mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
@ -0,0 +1,28 @@
|
||||
package com.thealgorithms.misc;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
class InverseOfMatrixTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCases")
|
||||
void testInvert(double[][] matrix, double[][] expectedInverse) {
|
||||
double[][] result = InverseOfMatrix.invert(matrix);
|
||||
assertMatrixEquals(expectedInverse, result);
|
||||
}
|
||||
|
||||
private static Stream<Arguments> provideTestCases() {
|
||||
return Stream.of(Arguments.of(new double[][] {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, new double[][] {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}), Arguments.of(new double[][] {{4, 7}, {2, 6}}, new double[][] {{0.6, -0.7}, {-0.2, 0.4}}));
|
||||
}
|
||||
|
||||
private void assertMatrixEquals(double[][] expected, double[][] actual) {
|
||||
for (int i = 0; i < expected.length; i++) {
|
||||
assertArrayEquals(expected[i], actual[i], 1.0E-10, "Row " + i + " is not equal");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user