Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7c5e6fb

Browse files
test: add self-tests for determinant algorithm
1 parent 13a5d57 commit 7c5e6fb

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

‎Maths/test/Determinant.test.js‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { determinant } from '../Determinant'
2+
describe('Determinant', () => {
3+
const testCases = [
4+
[
5+
[
6+
[8, 1, 6],
7+
[1, 2, 3],
8+
[4, 7, 5]
9+
],
10+
-87
11+
],
12+
[
13+
[
14+
[2, 1, 0, 2],
15+
[1, 2, 4, 3],
16+
[0, 4, 7, 5],
17+
[4, 7, 9, 8]
18+
],
19+
25
20+
],
21+
[
22+
[
23+
[5, 9],
24+
[3, 7]
25+
],
26+
8
27+
],
28+
[
29+
[
30+
[7, 5, 1, 4, 3],
31+
[6, 8, 7, 9, 6],
32+
[9, 8, 0, 4, 7],
33+
[0, 3, 4, 7, 9],
34+
[3, 6, 2, 8, 8]
35+
],
36+
2476
37+
],
38+
[[[23]], 23],
39+
[
40+
[
41+
[1, 6],
42+
[1, 2, 3],
43+
[4, 7, 5]
44+
],
45+
'Square matrix is required.'
46+
],
47+
[[1, 3, 2, [5, 8, 6], 3], 'Input is not a valid 2D matrix.']
48+
]
49+
50+
test.each(testCases)(
51+
'Should return the determinant of the square matrix.',
52+
(matrix, expected) => {
53+
expect(determinant(matrix)).toEqual(expected)
54+
}
55+
)
56+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /