Skip to content

Commit

Permalink
deviation:Implement count_neq
Browse files Browse the repository at this point in the history
  • Loading branch information
munckymagik committed Apr 17, 2019
1 parent f98349b commit c03c213
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/deviation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ where
fn count_eq(&self, other: &ArrayBase<S, D>) -> usize
where
A: PartialEq;

fn count_neq(&self, other: &ArrayBase<S, D>) -> usize
where
A: PartialEq;
}

impl<A, S, D> DeviationExt<A, S, D> for ArrayBase<S, D>
Expand All @@ -31,6 +35,13 @@ where

c
}

fn count_neq(&self, other: &ArrayBase<S, D>) -> usize
where
A: PartialEq,
{
self.len() - self.count_eq(other)
}
}

#[cfg(test)]
Expand All @@ -50,4 +61,17 @@ mod tests {
assert_eq!(b.count_eq(&c), 0);
assert_eq!(d.count_eq(&e), 4);
}

#[test]
fn test_count_neq() {
let a = array![1, 2, 3, 4, 5, 6, 7];
let b = array![1, 3, 3, 4, 6, 7, 8];
let c = array![2, 4, 4, 5, 7, 8, 9];
let d = array![[1, 2], [3, 4], [5, 6]];
let e = array![[1, 2], [4, 3], [5, 6]];

assert_eq!(a.count_neq(&b), 4);
assert_eq!(b.count_neq(&c), 7);
assert_eq!(d.count_neq(&e), 2);
}
}

0 comments on commit c03c213

Please sign in to comment.