From e227dd693e233cc2819277ffe0f0b252bdb84bf8 Mon Sep 17 00:00:00 2001 From: lukas Date: Mon, 10 Oct 2022 19:05:47 -0700 Subject: [PATCH] Refactor unit tests --- nalgebra-sparse/tests/unit_tests/coo.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/nalgebra-sparse/tests/unit_tests/coo.rs b/nalgebra-sparse/tests/unit_tests/coo.rs index fae0144a..8e46651f 100644 --- a/nalgebra-sparse/tests/unit_tests/coo.rs +++ b/nalgebra-sparse/tests/unit_tests/coo.rs @@ -95,16 +95,30 @@ fn coo_triplets_iter_mut() { let v = vec![2, 3, 4, 7, 1, 3, 1, 5]; let mut coo = CooMatrix::::try_from_triplets(3, 5, i.clone(), j.clone(), v.clone()).unwrap(); - coo.triplet_iter_mut().for_each(|(_i, _j, v)| *v = *v * *v); + + let actual_triplets: Vec<_> = coo.triplet_iter_mut().map(|(i, j, v)| (i, j, *v)).collect(); let expected_triplets: Vec<_> = i .iter() .zip(&j) .zip(&v) - .map(|((i, j), v)| (*i, *j, v * v)) + .map(|((i, j), v)| (*i, *j, *v)) .collect(); - let actual_triplets: Vec<_> = coo.triplet_iter().map(|(i, j, v)| (i, j, *v)).collect(); - assert_eq!(expected_triplets, actual_triplets) + assert_eq!(expected_triplets, actual_triplets); + + for (_i, _j, v) in coo.triplet_iter_mut() { + *v += *v; + } + + let actual_triplets: Vec<_> = coo.triplet_iter_mut().map(|(i, j, v)| (i, j, *v)).collect(); + let v = vec![4, 6, 8, 14, 2, 6, 2, 10]; + let expected_triplets: Vec<_> = i + .iter() + .zip(&j) + .zip(&v) + .map(|((i, j), v)| (*i, *j, *v)) + .collect(); + assert_eq!(expected_triplets, actual_triplets); } #[test]