From 75a5f20802af64b2b483f0cae1316f46c07ae5ad Mon Sep 17 00:00:00 2001 From: Michael Neumann Date: Sat, 27 Feb 2016 19:30:33 +0100 Subject: [PATCH] Add test case for WeightMatrix --- src/weight_matrix.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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()); +}