-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMatrixTest.java
More file actions
81 lines (63 loc) · 2.12 KB
/
MatrixTest.java
File metadata and controls
81 lines (63 loc) · 2.12 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package dataStructures.matrix;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class MatrixTest {
@Test
@DisplayName("rotate matrix")
public void testRotate() {
Matrix a = new Matrix();
int[][] arrayA = new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
a.set(arrayA);
a.rotate();
String expected = a.toString();
Matrix b = new Matrix();
int[][] arrayB = new int[][] { { 7, 4, 1 }, { 8, 5, 2 }, { 9, 6, 3 } };
b.set(arrayB);
String actual = b.toString();
assertEquals(expected, actual, "Rotation matrix should work");
System.out.println("Test - Matrix : rotate() - passed ok");
}
@Test
@DisplayName("transpose matrix")
public void testTranspose() {
Matrix a = new Matrix();
int[][] arrayA = new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
a.set(arrayA);
a.transpose();
String expected = a.toString();
Matrix b = new Matrix();
int[][] arrayB = new int[][] { { 1, 4, 7 }, { 2, 5, 8 }, { 3, 6, 9 } };
b.set(arrayB);
String actual = b.toString();
assertEquals(expected, actual, "Transpose matrix should work");
System.out.println("Test - Matrix : transpose() - passed ok");
}
@Test
@DisplayName("reflect matrix")
public void testReflect() {
Matrix a = new Matrix();
int[][] arrayA = new int[][] { { 1, 4, 7 }, { 2, 5, 8 }, { 3, 6, 9 } };
a.set(arrayA);
a.reflect();
String expected = a.toString();
Matrix b = new Matrix();
int[][] arrayB = new int[][] { { 7, 4, 1 }, { 8, 5, 2 }, { 9, 6, 3 } };
b.set(arrayB);
String actual = b.toString();
assertEquals(expected, actual, "Reflect matrix should work");
System.out.println("Test - Matrix : reflect() - passed ok");
}
@Test
public void testSet_IS_NULL() {
int[][] expectedArr = null;
Matrix a = new Matrix();
assertThrows(IllegalArgumentException.class, () -> {
a.set(expectedArr);
fail("Input null matrix");
});
System.out.println("Test - Matrix : added NULL array - passed ok");
}
}