add test case

This commit is contained in:
lukas 2022-10-02 11:57:37 -07:00
parent b37eeee636
commit 9a38c554af
1 changed files with 20 additions and 0 deletions

View File

@ -87,6 +87,26 @@ fn coo_construction_for_valid_data() {
}
}
#[test]
fn coo_triplets_iter_mut() {
// Arbitrary matrix, with duplicates
let i = vec![0, 1, 0, 0, 0, 0, 2, 1];
let j = vec![0, 2, 0, 1, 0, 3, 3, 2];
let v = vec![2, 3, 4, 7, 1, 3, 1, 5];
let mut coo =
CooMatrix::<i32>::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 expected_triplets: Vec<_> = i
.iter()
.zip(&j)
.zip(&v)
.map(|((i, j), v)| (*i, *j, v * v))
.collect();
let actual_triplets: Vec<_> = coo.triplet_iter().map(|(i, j, v)| (i, j, *v)).collect();
assert_eq!(expected_triplets, actual_triplets)
}
#[test]
fn coo_try_from_triplets_reports_out_of_bounds_indices() {
{