csvbinmatrix/matrix/
mod.rs1#![doc = include_str!("../../docs/matrix/mod.md")]
2
3pub mod cmp;
4pub mod create;
5pub mod io;
6pub mod items;
7pub mod iter;
8pub mod ops;
9pub mod update;
10pub mod views;
11
12#[derive(Debug, Clone)]
38#[allow(clippy::module_name_repetitions)]
39pub struct CSVBinaryMatrix {
40 number_of_rows: usize,
41 number_of_columns: usize,
42 distances: Vec<usize>,
43 is_reversed: bool,
44}
45
46impl CSVBinaryMatrix {
47 #[must_use]
49 pub fn number_of_rows(&self) -> usize {
50 self.number_of_rows
51 }
52
53 #[must_use]
55 pub fn number_of_columns(&self) -> usize {
56 self.number_of_columns
57 }
58}
59
60#[cfg(test)]
61mod tests {
62
63 use pretty_assertions::assert_eq;
64 use rstest::{fixture, rstest};
65
66 use super::CSVBinaryMatrix;
67
68 #[fixture]
76 pub fn zeros_matrix() -> CSVBinaryMatrix {
77 CSVBinaryMatrix {
78 number_of_rows: 3,
79 number_of_columns: 3,
80 distances: vec![8],
81 is_reversed: false,
82 }
83 }
84
85 #[fixture]
87 pub fn zeros_matrix_bis() -> CSVBinaryMatrix {
88 CSVBinaryMatrix {
89 number_of_rows: 3,
90 number_of_columns: 3,
91 distances: vec![8],
92 is_reversed: true,
93 }
94 }
95
96 #[fixture]
104 pub fn ones_matrix() -> CSVBinaryMatrix {
105 CSVBinaryMatrix {
106 number_of_rows: 3,
107 number_of_columns: 3,
108 distances: vec![0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
109 is_reversed: false,
110 }
111 }
112
113 #[fixture]
121 pub fn matrix_a() -> CSVBinaryMatrix {
122 CSVBinaryMatrix {
123 number_of_rows: 3,
124 number_of_columns: 3,
125 distances: vec![0, 1, 1, 1, 4, 1],
126 is_reversed: false,
127 }
128 }
129
130 #[fixture]
138 pub fn matrix_a_bis() -> CSVBinaryMatrix {
139 CSVBinaryMatrix {
140 number_of_rows: 3,
141 number_of_columns: 3,
142 distances: vec![1, 4, 1, 1, 1, 0],
143 is_reversed: true,
144 }
145 }
146
147 #[rstest]
148 fn debug(zeros_matrix: CSVBinaryMatrix, matrix_a: CSVBinaryMatrix) {
149 assert_eq!(
150 format!("{zeros_matrix:?}"),
151 "CSVBinaryMatrix { number_of_rows: 3, number_of_columns: 3, distances: [8], is_reversed: false }"
152 );
153 assert_eq!(
154 format!("{matrix_a:?}"),
155 "CSVBinaryMatrix { number_of_rows: 3, number_of_columns: 3, distances: [0, 1, 1, 1, 4, 1], is_reversed: false }"
156 );
157 }
158
159 #[rstest]
160 fn number_of_rows(matrix_a: CSVBinaryMatrix) {
161 assert_eq!(matrix_a.number_of_rows(), 3);
162 }
163
164 #[rstest]
165 fn number_of_columns(matrix_a: CSVBinaryMatrix) {
166 assert_eq!(matrix_a.number_of_columns(), 3);
167 }
168}