forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpiralMatrixIITest.java
More file actions
53 lines (44 loc) · 1.34 KB
/
SpiralMatrixIITest.java
File metadata and controls
53 lines (44 loc) · 1.34 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
package com.thealgorithms.matrix;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.jupiter.api.Test;
class SpiralMatrixIITest {
// Instantiate the class to test
SpiralMatrixII spiral = new SpiralMatrixII();
@Test
void testNEquals3() {
int[][] expected = {
{1, 2, 3},
{8, 9, 4},
{7, 6, 5}
};
int[][] actual = spiral.generateMatrix(3);
// Compare each row
for (int i = 0; i < expected.length; i++) {
assertArrayEquals(expected[i], actual[i], "Row " + i + " is incorrect for n=3");
}
}
@Test
void testNEquals4() {
int[][] expected = {
{1, 2, 3, 4},
{12, 13, 14, 5},
{11, 16, 15, 6},
{10, 9, 8, 7}
};
int[][] actual = spiral.generateMatrix(4);
for (int i = 0; i < expected.length; i++) {
assertArrayEquals(expected[i], actual[i], "Row " + i + " is incorrect for n=4");
}
}
@Test
void testNEquals2() {
int[][] expected = {
{1, 2},
{4, 3}
};
int[][] actual = spiral.generateMatrix(2);
for (int i = 0; i < expected.length; i++) {
assertArrayEquals(expected[i], actual[i], "Row " + i + " is incorrect for n=2");
}
}
}