Skip to content

Commit c03c213

Browse files
committed
deviation:Implement count_neq
1 parent f98349b commit c03c213

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/deviation.rs

+24
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ where
1010
fn count_eq(&self, other: &ArrayBase<S, D>) -> usize
1111
where
1212
A: PartialEq;
13+
14+
fn count_neq(&self, other: &ArrayBase<S, D>) -> usize
15+
where
16+
A: PartialEq;
1317
}
1418

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

3236
c
3337
}
38+
39+
fn count_neq(&self, other: &ArrayBase<S, D>) -> usize
40+
where
41+
A: PartialEq,
42+
{
43+
self.len() - self.count_eq(other)
44+
}
3445
}
3546

3647
#[cfg(test)]
@@ -50,4 +61,17 @@ mod tests {
5061
assert_eq!(b.count_eq(&c), 0);
5162
assert_eq!(d.count_eq(&e), 4);
5263
}
64+
65+
#[test]
66+
fn test_count_neq() {
67+
let a = array![1, 2, 3, 4, 5, 6, 7];
68+
let b = array![1, 3, 3, 4, 6, 7, 8];
69+
let c = array![2, 4, 4, 5, 7, 8, 9];
70+
let d = array![[1, 2], [3, 4], [5, 6]];
71+
let e = array![[1, 2], [4, 3], [5, 6]];
72+
73+
assert_eq!(a.count_neq(&b), 4);
74+
assert_eq!(b.count_neq(&c), 7);
75+
assert_eq!(d.count_neq(&e), 2);
76+
}
5377
}

0 commit comments

Comments
 (0)