From 2c3c2ca80d85992f75a05d2d3fb102f5694f495e Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Fri, 26 May 2023 17:33:51 -0500 Subject: [PATCH] fix: Some grammar and newlines --- src/lib.rs | 14 +++++++------- src/tests.rs | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d3a52bd..8c43d3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,17 +54,17 @@ impl Matrix { } } - /// Return the height of a matrix. + /// Returns the height of a matrix. pub fn height(&self) -> usize { self.entries.len() } - /// Return the width of a matrix. + /// Returns the width of a matrix. pub fn width(&self) -> usize { self.entries[0].len() } - /// Return the transpose of a matrix. + /// Returns the transpose of a matrix. pub fn transpose(&self) -> Self where T: Copy, @@ -80,7 +80,7 @@ impl Matrix { Matrix { entries: out } } - /// Return a reference to the rows of a matrix as `&Vec>`. + /// Returns a reference to the rows of a matrix as `&Vec>`. pub fn rows(&self) -> &Vec> { &self.entries } @@ -98,7 +98,7 @@ impl Matrix { self.height() == self.width() } - /// Return a matrix after removing the provided row and column from it. + /// Returns a matrix after removing the provided row and column from it. /// Note: Row and column numbers are 0-indexed. /// # Example /// ``` @@ -127,7 +127,7 @@ impl Matrix { Matrix { entries: out } } - /// Return the determinant of a square matrix. This method additionally requires [`Zero`], + /// Returns the determinant of a square matrix. This method additionally requires [`Zero`], /// [`One`] and [`Copy`] traits. Also, we need that the [`Mul`] and [`Add`] operations /// return the same type `T`. This uses basic recursive algorithm using cofactor-minor. /// See [`det_in_field`](Self::det_in_field()) for faster determinant calculation in fields. @@ -169,7 +169,7 @@ impl Matrix { } } - /// Return the determinant of a square matrix over a field i.e. needs [`One`] and [`Div`] traits. + /// Returns the determinant of a square matrix over a field i.e. needs [`One`] and [`Div`] traits. /// See [`det`](Self::det()) for determinants in rings. /// This method uses row reduction as is much faster. /// It'll throw an error if the provided matrix isn't square. diff --git a/src/tests.rs b/src/tests.rs index 608c3ec..14eb605 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -5,6 +5,7 @@ fn mul_test() { let a = Matrix::from(vec![vec![1, 2, 4], vec![3, 4, 9]]).unwrap(); let b = Matrix::from(vec![vec![1, 2], vec![2, 3], vec![5, 1]]).unwrap(); let c = Matrix::from(vec![vec![25, 12], vec![56, 27]]).unwrap(); + assert_eq!(a * b, c); } @@ -15,6 +16,7 @@ fn add_sub_test() { let c = Matrix::from(vec![vec![1, 2, 4], vec![2, 2, 5]]).unwrap(); let d = Matrix::from(vec![vec![1, 2, 2], vec![-2, 0, -1]]).unwrap(); let e = Matrix::from(vec![vec![-1, -2, -4], vec![-2, -2, -5]]).unwrap(); + assert_eq!(a.clone() + b.clone(), c); assert_eq!(a - b, d); assert_eq!(-c, e); @@ -30,6 +32,7 @@ fn det_test() { vec![1.0, 2.0, 0.0], ]) .unwrap(); + assert_eq!(a.det(), Ok(30)); assert_eq!(c.det_in_field(), Ok(-30.0)); assert!(b.det().is_err()); @@ -39,6 +42,7 @@ fn det_test() { fn zero_one_test() { let a = Matrix::from(vec![vec![0, 0, 0], vec![0, 0, 0]]).unwrap(); let b = Matrix::from(vec![vec![1, 0], vec![0, 1]]).unwrap(); + assert_eq!(Matrix::::zero(2, 3), a); assert_eq!(Matrix::::identity(2), b); } @@ -49,6 +53,7 @@ fn echelon_test() { let a = Matrix::from(vec![vec![1.0, 2.0, 3.0], vec![0.0, -2.0, -2.0]]).unwrap(); let b = Matrix::from(vec![vec![1.0, 0.0, 0.0], vec![1.0, -2.0, 0.0]]).unwrap(); let c = Matrix::from(vec![vec![1.0, 2.0, 3.0], vec![0.0, 1.0, 1.0]]).unwrap(); + assert_eq!(m.row_echelon(), a); assert_eq!(m.column_echelon(), b); assert_eq!(m.reduced_row_echelon(), c);