Skip to content

Commit 48275c4

Browse files
committed
Enhance documentation and test cases for Zip::all()
1 parent b36f56a commit 48275c4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/zip/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,16 @@ macro_rules! map_impl {
741741
/// Tests if every element of the iterator matches a predicate.
742742
///
743743
/// Returns `true` if `predicate` evaluates to `true` for all elements.
744+
/// Returns `true` if the input arrays are empty.
745+
///
746+
/// Example:
747+
///
748+
/// ```
749+
/// use ndarray::{array, Zip};
750+
/// let a = array![1, 2, 3];
751+
/// let b = array![1, 4, 9];
752+
/// assert!(Zip::from(&a).and(&b).all(|&a, &b| a * a == b));
753+
/// ```
744754
pub fn all<F>(mut self, mut predicate: F) -> bool
745755
where F: FnMut($($p::Item),*) -> bool
746756
{

tests/azip.rs

+3
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,11 @@ fn test_indices_split_1() {
276276
fn test_zip_all() {
277277
let a = Array::<f32, _>::zeros(62);
278278
let b = Array::<f32, _>::ones(62);
279+
let mut c = Array::<f32, _>::ones(62);
280+
c[5] = 0.0;
279281
assert_eq!(true, Zip::from(&a).and(&b).all(|&x, &y| x + y == 1.0));
280282
assert_eq!(false, Zip::from(&a).and(&b).all(|&x, &y| x == y));
283+
assert_eq!(false, Zip::from(&a).and(&c).all(|&x, &y| x + y == 1.0));
281284
}
282285

283286
#[test]

0 commit comments

Comments
 (0)