-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathMirrorOfMatrixTest.java
53 lines (44 loc) · 2 KB
/
MirrorOfMatrixTest.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.thealgorithms.matrix;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
class MirrorOfMatrixTest {
@Test
void testMirrorMatrixRegularMatrix() {
double[][] originalMatrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
double[][] expectedMirrorMatrix = {{3, 2, 1}, {6, 5, 4}, {9, 8, 7}};
double[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
}
@Test
void testMirrorMatrixEmptyMatrix() {
double[][] originalMatrix = {};
Exception e = assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(originalMatrix));
assertEquals("The input matrix cannot be empty", e.getMessage());
}
@Test
void testMirrorMatrixSingleElementMatrix() {
double[][] originalMatrix = {{42}};
double[][] expectedMirrorMatrix = {{42}};
double[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
}
@Test
void testMirrorMatrixMultipleRowsOneColumnMatrix() {
double[][] originalMatrix = {{1}, {2}, {3}, {4}};
double[][] expectedMirrorMatrix = {{1}, {2}, {3}, {4}};
double[][] mirroredMatrix = MirrorOfMatrix.mirrorMatrix(originalMatrix);
assertArrayEquals(expectedMirrorMatrix, mirroredMatrix);
}
@Test
void testMirrorMatrixNullInput() {
double[][] originalMatrix = null;
Exception e = assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(originalMatrix));
assertEquals("The input matrix cannot be null", e.getMessage());
}
@Test
void testMirrorMatrixThrows() {
assertThrows(IllegalArgumentException.class, () -> MirrorOfMatrix.mirrorMatrix(new double[][] {{1}, {2, 3}}));
}
}