File tree Expand file tree Collapse file tree 1 file changed +21
-16
lines changed Expand file tree Collapse file tree 1 file changed +21
-16
lines changed Original file line number Diff line number Diff line change 1
1
import { rowEchelon } from '../RowEchelon'
2
2
describe ( 'Determinant' , ( ) => {
3
- const testCases = [
3
+ const tolerance = 0.000001
4
+ test . each ( [
4
5
[
5
6
[
6
7
[ 8 , 1 , 3 , 5 ] ,
@@ -45,14 +46,6 @@ describe('Determinant', () => {
45
46
[ 0 , 0 , 0 ]
46
47
]
47
48
] ,
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
- ] ,
56
49
[
57
50
[
58
51
[ 0 , 7 , 8 , 1 , 3 , 5 ] ,
@@ -73,12 +66,24 @@ describe('Determinant', () => {
73
66
[ 0 , 0 , 0 , 0 , 0 , 0 ]
74
67
]
75
68
]
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
+ }
82
74
}
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
+ } )
84
89
} )
You can’t perform that action at this time.
0 commit comments