Skip to content

Commit

Permalink
Enhance documentation and test cases for Zip::all()
Browse files Browse the repository at this point in the history
  • Loading branch information
mneumann committed Apr 13, 2019
1 parent b36f56a commit 48275c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/zip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,16 @@ macro_rules! map_impl {
/// Tests if every element of the iterator matches a predicate.
///
/// Returns `true` if `predicate` evaluates to `true` for all elements.
/// Returns `true` if the input arrays are empty.
///
/// Example:
///
/// ```
/// use ndarray::{array, Zip};
/// let a = array![1, 2, 3];
/// let b = array![1, 4, 9];
/// assert!(Zip::from(&a).and(&b).all(|&a, &b| a * a == b));
/// ```
pub fn all<F>(mut self, mut predicate: F) -> bool
where F: FnMut($($p::Item),*) -> bool
{
Expand Down
3 changes: 3 additions & 0 deletions tests/azip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,11 @@ fn test_indices_split_1() {
fn test_zip_all() {
let a = Array::<f32, _>::zeros(62);
let b = Array::<f32, _>::ones(62);
let mut c = Array::<f32, _>::ones(62);
c[5] = 0.0;
assert_eq!(true, Zip::from(&a).and(&b).all(|&x, &y| x + y == 1.0));
assert_eq!(false, Zip::from(&a).and(&b).all(|&x, &y| x == y));
assert_eq!(false, Zip::from(&a).and(&c).all(|&x, &y| x + y == 1.0));
}

#[test]
Expand Down

0 comments on commit 48275c4

Please sign in to comment.