- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathMatrixTransposeTest.java
33 lines (26 loc) · 1.77 KB
/
MatrixTransposeTest.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
28
29
30
31
32
33
packagecom.thealgorithms.matrix;
importstaticorg.junit.jupiter.api.Assertions.assertArrayEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importjava.util.stream.Stream;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
publicclassMatrixTransposeTest {
privatestaticStream<Arguments> provideValidMatrixTestCases() {
returnStream.of(Arguments.of(newint[][] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, newint[][] {{1, 4, 7}, {2, 5, 8}, {3, 6, 9}}, "Transpose of square matrix"), Arguments.of(newint[][] {{1, 2}, {3, 4}, {5, 6}}, newint[][] {{1, 3, 5}, {2, 4, 6}}, "Transpose of rectangular matrix"),
Arguments.of(newint[][] {{1, 2, 3}}, newint[][] {{1}, {2}, {3}}, "Transpose of single-row matrix"), Arguments.of(newint[][] {{1}, {2}, {3}}, newint[][] {{1, 2, 3}}, "Transpose of single-column matrix"));
}
privatestaticStream<Arguments> provideInvalidMatrixTestCases() {
returnStream.of(Arguments.of(newint[0][0], "Empty matrix should throw IllegalArgumentException"), Arguments.of(null, "Null matrix should throw IllegalArgumentException"));
}
@ParameterizedTest(name = "Test case {index}: {2}")
@MethodSource("provideValidMatrixTestCases")
voidtestValidMatrixTranspose(int[][] input, int[][] expected, Stringdescription) {
assertArrayEquals(expected, MatrixTranspose.transpose(input), description);
}
@ParameterizedTest(name = "Test case {index}: {1}")
@MethodSource("provideInvalidMatrixTestCases")
voidtestInvalidMatrixTranspose(int[][] input, Stringdescription) {
assertThrows(IllegalArgumentException.class, () -> MatrixTranspose.transpose(input), description);
}
}