- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathInverseOfMatrixTest.java
27 lines (22 loc) · 1.08 KB
/
InverseOfMatrixTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
packagecom.thealgorithms.matrix;
importstaticorg.junit.jupiter.api.Assertions.assertArrayEquals;
importjava.util.stream.Stream;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
classInverseOfMatrixTest {
@ParameterizedTest
@MethodSource("provideTestCases")
voidtestInvert(double[][] matrix, double[][] expectedInverse) {
double[][] result = InverseOfMatrix.invert(matrix);
assertMatrixEquals(expectedInverse, result);
}
privatestaticStream<Arguments> provideTestCases() {
returnStream.of(Arguments.of(newdouble[][] {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, newdouble[][] {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}), Arguments.of(newdouble[][] {{4, 7}, {2, 6}}, newdouble[][] {{0.6, -0.7}, {-0.2, 0.4}}));
}
privatevoidassertMatrixEquals(double[][] expected, double[][] actual) {
for (inti = 0; i < expected.length; i++) {
assertArrayEquals(expected[i], actual[i], 1.0E-10, "Row " + i + " is not equal");
}
}
}