mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Refactor files to be in correctly nested packages (#6120)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.thealgorithms.matrix;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
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;
|
||||
|
||||
public class MatrixTransposeTest {
|
||||
|
||||
private static Stream<Arguments> provideValidMatrixTestCases() {
|
||||
return Stream.of(Arguments.of(new int[][] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, new int[][] {{1, 4, 7}, {2, 5, 8}, {3, 6, 9}}, "Transpose of square matrix"), Arguments.of(new int[][] {{1, 2}, {3, 4}, {5, 6}}, new int[][] {{1, 3, 5}, {2, 4, 6}}, "Transpose of rectangular matrix"),
|
||||
Arguments.of(new int[][] {{1, 2, 3}}, new int[][] {{1}, {2}, {3}}, "Transpose of single-row matrix"), Arguments.of(new int[][] {{1}, {2}, {3}}, new int[][] {{1, 2, 3}}, "Transpose of single-column matrix"));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> provideInvalidMatrixTestCases() {
|
||||
return Stream.of(Arguments.of(new int[0][0], "Empty matrix should throw IllegalArgumentException"), Arguments.of(null, "Null matrix should throw IllegalArgumentException"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Test case {index}: {2}")
|
||||
@MethodSource("provideValidMatrixTestCases")
|
||||
void testValidMatrixTranspose(int[][] input, int[][] expected, String description) {
|
||||
assertArrayEquals(expected, MatrixTranspose.transpose(input), description);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Test case {index}: {1}")
|
||||
@MethodSource("provideInvalidMatrixTestCases")
|
||||
void testInvalidMatrixTranspose(int[][] input, String description) {
|
||||
assertThrows(IllegalArgumentException.class, () -> MatrixTranspose.transpose(input), description);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user