csvbinmatrix/matrix/
cmp.rs1use super::CSVBinaryMatrix;
4
5impl PartialEq for CSVBinaryMatrix {
6 fn eq(self: &CSVBinaryMatrix, other: &CSVBinaryMatrix) -> bool {
7 if self.number_of_rows != other.number_of_rows {
8 return false;
9 }
10 if self.number_of_columns != other.number_of_columns {
11 return false;
12 }
13 if self.distances.len() != other.distances.len() {
14 return false;
15 }
16 if self.is_reversed == other.is_reversed {
17 return self.distances == other.distances;
18 }
19 let mut distance_index = 0;
20 let mut rev_distance_index = other.distances.len();
21 while distance_index < self.distances.len() {
22 if self.distances[distance_index] != other.distances[rev_distance_index - 1] {
23 return false;
24 }
25 distance_index += 1;
26 rev_distance_index -= 1;
27 }
28 true
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use pretty_assertions::assert_eq;
35 use rstest::rstest;
36
37 use super::super::ops::tests::matrix_a_rev;
38 use super::super::tests::{matrix_a, matrix_a_bis};
39 use super::super::CSVBinaryMatrix;
40
41 #[rstest]
42 fn no_equal_number_of_rows(matrix_a: CSVBinaryMatrix) {
43 let matrix_b = CSVBinaryMatrix::try_from(&[[1, 1, 1]]).unwrap();
44 assert!(matrix_a != matrix_b);
45 }
46
47 #[rstest]
48 fn no_equal_number_of_columns(matrix_a: CSVBinaryMatrix) {
49 let matrix_b = CSVBinaryMatrix::try_from(&[[1, 1], [1, 0], [0, 1]]).unwrap();
50 assert!(matrix_a != matrix_b);
51 }
52
53 #[rstest]
54 fn no_equal_distances(matrix_a: CSVBinaryMatrix) {
55 let matrix_b = CSVBinaryMatrix::try_from(&[[1, 1, 1], [1, 0, 1], [0, 1, 0]]).unwrap();
56 assert!(matrix_a != matrix_b);
57 }
58
59 #[rstest]
60 fn equal_when_rev_bools_equal(matrix_a: CSVBinaryMatrix) {
61 let matrix_b = matrix_a.clone();
62 assert_eq!(matrix_a, matrix_b);
63 }
64
65 #[rstest]
66 fn equal_when_rev_bools_differ(matrix_a: CSVBinaryMatrix, matrix_a_bis: CSVBinaryMatrix) {
67 assert_eq!(matrix_a, matrix_a_bis);
68 }
69
70 #[rstest]
71 fn no_equal_when_rev_bools_differ(matrix_a: CSVBinaryMatrix, matrix_a_rev: CSVBinaryMatrix) {
72 assert!(matrix_a != matrix_a_rev);
73 }
74}