diff --git a/src/weight_matrix.rs b/src/weight_matrix.rs index 76a1b72..8544655 100644 --- a/src/weight_matrix.rs +++ b/src/weight_matrix.rs @@ -9,6 +9,7 @@ pub struct WeightMatrix { impl Weights for WeightMatrix { type T = T; + #[inline(always)] fn n(&self) -> usize { self.c.n() @@ -76,3 +77,18 @@ impl WeightMatrix { self.c.as_slice() } } + +#[test] +fn test_weight_matrix() { + assert_eq!(0, WeightMatrix::from_row_vec(1, vec![0]).min_of_row(0)); + assert_eq!(1, WeightMatrix::from_row_vec(1, vec![1]).min_of_row(0)); + assert_eq!(1, WeightMatrix::from_row_vec(2, vec![5, 1, 0, 0]).min_of_row(0)); + + let mut mat = WeightMatrix::from_row_vec(2, vec![0, 1, 2, 3]); + mat.sub_row(1, 1); + assert_eq!(&[0, 1, 1, 2], mat.as_slice()); + + let mut mat = WeightMatrix::from_row_vec(2, vec![5, 3, 2, 3]); + mat.sub_min_of_each_row(); + assert_eq!(&[2, 0, 0, 1], mat.as_slice()); +}