diff --git a/matrix/src/lib.rs b/matrix/src/lib.rs index 31e1bb2..967c69e 100644 --- a/matrix/src/lib.rs +++ b/matrix/src/lib.rs @@ -1,7 +1,45 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); +use std::ops::Index; + +pub struct Matrix { + matrix: Vec>, +} + +impl Matrix { + pub fn new(matrix: Vec>) -> Matrix { + Matrix { + matrix: matrix, + } } } + +impl Index for Matrix { + type Output = Vec; + fn index(&self, index: usize) -> &Self::Output { + &self.matrix[index] + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let m = vec![ + vec![1.0, 2.0, 3.0, 4.0], + vec![5.5, 6.5, 7.5, 8.5], + vec![9.0, 10.0, 11.0, 12.0], + vec![13.5, 14.5, 15.5, 16.5], + ]; + + let matrix = Matrix::new(m); + assert_eq!(1.0, matrix[0][0]); + assert_eq!(4.0, matrix[0][3]); + assert_eq!(5.5, matrix[1][0]); + assert_eq!(7.5, matrix[1][2]); + assert_eq!(11.0, matrix[2][2]); + assert_eq!(13.5, matrix[3][0]); + assert_eq!(15.5, matrix[3][2]); + } + +}