-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateMatrixTest.java
More file actions
84 lines (71 loc) · 2.04 KB
/
Copy pathRotateMatrixTest.java
File metadata and controls
84 lines (71 loc) · 2.04 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
82
83
84
package algorithm.cracking.arrays;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
class RotateMatrixTest {
@Test
void testRotateMatrix() {
byte[][] matrix = {
{1, 0, 2, 0, 1, 1},
{0, 1, 1, 0, 2, 1},
{0, 0, 1, 0, 1, 3},
{0, 0, 1, 0, 1, 1},
{0, 4, 8, 0, 3, 1},
{6, 0, 1, 5, 1, 7}
};
byte[][] expectedMatrix = {
{1, 1, 3, 1, 1, 7},
{1, 2, 1, 1, 3, 1},
{0, 0, 0, 0, 0, 5},
{2, 1, 1, 1, 8, 1},
{0, 1, 0, 0, 4, 0},
{1, 0, 0, 0, 0, 6}
};
// (i,j)
for (byte[] row : matrix) {
System.out.println(Arrays.toString(row));
}
System.out.println();
RotateMatrix.rotate(matrix);
for (byte[] row : matrix) {
System.out.println(Arrays.toString(row));
}
assertArrayEquals(expectedMatrix, matrix);
}
@Test
void testRotateSmallMatrix() {
byte[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
byte[][] expectedMatrix = {
{3, 6, 9},
{2, 5, 8},
{1, 4, 7}
};
// (i,j)
for (byte[] row : matrix) {
System.out.println(Arrays.toString(row));
}
System.out.println();
RotateMatrix.rotate(matrix);
for (byte[] row : matrix) {
System.out.println(Arrays.toString(row));
}
assertArrayEquals(expectedMatrix, matrix);
}
@Test
void testEmptyMatrix() {
byte[][] matrix = {};
byte[][] expectedMatrix = {};
RotateMatrix.rotate(matrix);
assertArrayEquals(expectedMatrix, matrix);
}
@Test
void testNullMatrix() {
byte[][] matrix = null;
RotateMatrix.rotate(matrix);
assertArrayEquals(null, matrix);
}
}