1
1
import { expect } from 'vitest'
2
2
import { determinant } from '../Determinant'
3
3
describe ( 'Determinant' , ( ) => {
4
- const validTestCases = [
4
+ test . each ( [
5
5
[
6
6
[
7
7
[ 8 , 1 , 6 ] ,
@@ -37,9 +37,14 @@ describe('Determinant', () => {
37
37
2476
38
38
] ,
39
39
[ [ [ 23 ] ] , 23 ]
40
- ]
40
+ ] ) (
41
+ 'Should return the determinant of the square matrix.' ,
42
+ ( matrix , expected ) => {
43
+ expect ( determinant ( matrix ) ) . toEqual ( expected )
44
+ }
45
+ )
41
46
42
- const errorTestCases = [
47
+ test . each ( [
43
48
[
44
49
[
45
50
[ 1 , 6 ] ,
@@ -49,27 +54,10 @@ describe('Determinant', () => {
49
54
'Square matrix is required.'
50
55
] ,
51
56
[ [ 1 , 3 , 2 , [ 5 , 8 , 6 ] , 3 ] , 'Input is not a valid 2D matrix.' ]
52
- ]
53
-
54
- test . each ( validTestCases ) (
55
- 'Should return the determinant of the square matrix.' ,
56
- ( matrix , expected ) => {
57
- try {
58
- expect ( determinant ( matrix ) ) . toEqual ( expected )
59
- } catch ( err ) {
60
- expect ( err . message ) . toEqual ( expected )
61
- }
62
- }
63
- )
64
-
65
- test . each ( errorTestCases ) (
57
+ ] ) (
66
58
'Should return the error message.' ,
67
59
( matrix , expected ) => {
68
- try {
69
- expect ( determinant ( matrix ) ) . toEqual ( expected )
70
- } catch ( err ) {
71
- expect ( err . message ) . toEqual ( expected )
72
- }
60
+ expect ( ( ) => determinant ( matrix ) ) . toThrowError ( expected )
73
61
}
74
62
)
75
63
} )