Skip to content
Prev Previous commit
Next Next commit
fix: use error tolerance and segregate testcases
  • Loading branch information
piyushk77 committed Oct 10, 2023
commit 2200c0e74e1a02bec53c5e8605f6e27a3d64d15e
37 changes: 21 additions & 16 deletions Maths/test/RowEchelon.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { rowEchelon } from '../RowEchelon'
describe('Determinant', () => {
const testCases = [
const tolerance = 0.000001
test.each([
[
[
[8, 1, 3, 5],
Expand Down Expand Up @@ -45,14 +46,6 @@ describe('Determinant', () => {
[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],
Expand All @@ -73,12 +66,24 @@ describe('Determinant', () => {
[0, 0, 0, 0, 0, 0]
]
]
]

test.each(testCases)(
'Should return the matrix in row echelon form.',
(matrix, expected) => {
expect(rowEchelon(matrix)).toEqual(expected)
])('Should return the matrix in row echelon form.', (matrix, expected) => {
for (let i = 0; i < matrix.length; i++) {
for (let j = 0; j < matrix[i].length; j++) {
expect(rowEchelon(matrix)[i][j]).toBeCloseTo(expected[i][j], tolerance)
}
}
)
})

test.each([
[
[
[8, 1, 3, 5],
[4, 6, 8, 2, 7],
[3, 5, 6, 8]
],
'Input is not a valid 2D matrix.'
]
])('Should return the error message.', (matrix, expected) => {
expect(() => rowEchelon(matrix)).toThrowError(expected)
})
})