use csr_matrix::CsrMatrixBuilder; use itertools::Itertools; #[test] fn test_row_iter() { let m = 3; let n = 3; let matrix = { let mut builder = CsrMatrixBuilder::::new(m, n); builder.add_entry(0, 0, 0); builder.add_entry(1, 1, 1); builder.add_entry(2, 2, 2); builder.build() }; for i in 0..m { let mut row_iter = matrix.row_iter(i); assert_eq!(Some(&(i, i)), row_iter.next()); assert!(row_iter.next().is_none()); } } #[test] fn test_entries_iter() { let m = 9; let n = 9; for permutation in (0..m).permutations(m) { test_entries_iter_helper(m, n, permutation); } } fn test_entries_iter_helper(m: usize, n: usize, permutation: Vec) { let matrix = { let mut builder = CsrMatrixBuilder::::new(m, n); for i in permutation.into_iter() { builder.add_entry(i, i, i); } builder.build() }; let mut entries_iter = matrix.entries_iter(); for i in 0..m { assert_eq!(Some((i, &(i, i))), entries_iter.next()); } assert_eq!(None, entries_iter.next()); }