Skip to content

Commit 2200c0e

Browse files
committed
fix: use error tolerance and segregate testcases
1 parent 64d1afc commit 2200c0e

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

Maths/test/RowEchelon.test.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { rowEchelon } from '../RowEchelon'
22
describe('Determinant', () => {
3-
const testCases = [
3+
const tolerance = 0.000001
4+
test.each([
45
[
56
[
67
[8, 1, 3, 5],
@@ -45,14 +46,6 @@ describe('Determinant', () => {
4546
[0, 0, 0]
4647
]
4748
],
48-
[
49-
[
50-
[8, 1, 3, 5],
51-
[4, 6, 8, 2, 7],
52-
[3, 5, 6, 8]
53-
],
54-
'Input is not a valid 2D matrix.'
55-
],
5649
[
5750
[
5851
[0, 7, 8, 1, 3, 5],
@@ -73,12 +66,24 @@ describe('Determinant', () => {
7366
[0, 0, 0, 0, 0, 0]
7467
]
7568
]
76-
]
77-
78-
test.each(testCases)(
79-
'Should return the matrix in row echelon form.',
80-
(matrix, expected) => {
81-
expect(rowEchelon(matrix)).toEqual(expected)
69+
])('Should return the matrix in row echelon form.', (matrix, expected) => {
70+
for (let i = 0; i < matrix.length; i++) {
71+
for (let j = 0; j < matrix[i].length; j++) {
72+
expect(rowEchelon(matrix)[i][j]).toBeCloseTo(expected[i][j], tolerance)
73+
}
8274
}
83-
)
75+
})
76+
77+
test.each([
78+
[
79+
[
80+
[8, 1, 3, 5],
81+
[4, 6, 8, 2, 7],
82+
[3, 5, 6, 8]
83+
],
84+
'Input is not a valid 2D matrix.'
85+
]
86+
])('Should return the error message.', (matrix, expected) => {
87+
expect(() => rowEchelon(matrix)).toThrowError(expected)
88+
})
8489
})

0 commit comments

Comments
 (0)