Skip to content
Prev Previous commit
Next Next commit
test: add self-tests for row echelon algorithm
  • Loading branch information
piyushk77 committed Oct 6, 2023
commit d9e7ffa07ae1a0d0f66f71f52e04d899f98d7a04
84 changes: 84 additions & 0 deletions Maths/test/RowEchelon.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { rowEchelon } from '../RowEchelon'
describe('Determinant', () => {
const testCases = [
[
[
[8, 1, 3, 5],
[4, 6, 8, 2],
[3, 5, 6, 8]
],
[
[1, 0.125, 0.375, 0.625],
[0, 1, 1.18182, -0.09091],
[0, 0, 1, -11.0769]
]
],
[
[
[6, 8, 1, 3, 5],
[1, 4, 6, 8, 2],
[0, 3, 5, 6, 8],
[2, 5, 9, 7, 8],
[5, 5, 7, 0, 1]
],
[
[1, 1.33333, 0.16667, 0.5, 0.83333],
[0, 1, 2.1875, 2.8125, 0.4375],
[0, 0, 1, 1.56, -4.28003],
[0, 0, 0, 1, -3.3595],
[0, 0, 0, 0, 1]
]
],
[
[
[1, 3, 5],
[6, 8, 2],
[5, 6, 8],
[7, 9, 9],
[5, 0, 6]
],
[
[1, 3, 5],
[0, 1, 2.8],
[0, 0, 1],
[0, 0, 0],
[0, 0, 0]
]
],
[
[
[8, 1, 3, 5],
[4, 6, 8, 2, 7],
[3, 5, 6, 8]
],
'Input is not a valid 2D matrix.'
],
[
[
[0, 7, 8, 1, 3, 5],
[0, 6, 4, 6, 8, 2],
[0, 7, 3, 5, 6, 8],
[6, 8, 1, 0, 0, 4],
[3, 3, 5, 7, 3, 1],
[1, 2, 1, 0, 9, 7],
[8, 8, 0, 2, 3, 1]
],
[
[1, 1.33333, 0.16667, 0, 0, 0.66667],
[0, 1, 0.66667, 1, 1.33333, 0.33333],
[0, 0, 1, 1.2, 1.99999, -3.4],
[0, 0, 0, 1, 1.3, -1.4],
[0, 0, 0, 0, 1, -2.32854],
[0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0]
]
]
]

test.each(testCases)(
'Should return the matrix in row echelon form.',
(matrix, expected) => {
expect(rowEchelon(matrix)).toEqual(expected)
}
)
})