Skip to content

Commit b235aaf

Browse files
committed
Fix SpiralMatrixIITest: corrected class name and 2D array assertions
1 parent ef8a90e commit b235aaf

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed
Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
11
package com.thealgorithms.matrix;
2+
23
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
34
import org.junit.jupiter.api.Test;
45

56
class SpiralMatrixIITest {
67

7-
SpiralMatrix spiral = new SpiralMatrix();
8+
// Instantiate the class to test
9+
SpiralMatrixII spiral = new SpiralMatrixII();
810

911
@Test
1012
void testNEquals3() {
11-
int[][] expected = {{1, 2, 3}, {8, 9, 4}, {7, 6, 5}};
12-
assertArrayEquals(expected, spiral.generateMatrix(3));
13+
int[][] expected = {
14+
{1, 2, 3},
15+
{8, 9, 4},
16+
{7, 6, 5}
17+
};
18+
int[][] actual = spiral.generateMatrix(3);
19+
20+
// Compare each row
21+
for (int i = 0; i < expected.length; i++) {
22+
assertArrayEquals(expected[i], actual[i], "Row " + i + " is incorrect for n=3");
23+
}
1324
}
1425

1526
@Test
1627
void testNEquals4() {
17-
int[][] expected = {{1, 2, 3, 4}, {12, 13, 14, 5}, {11, 16, 15, 6}, {10, 9, 8, 7}};
18-
assertArrayEquals(expected, spiral.generateMatrix(4));
28+
int[][] expected = {
29+
{1, 2, 3, 4},
30+
{12, 13, 14, 5},
31+
{11, 16, 15, 6},
32+
{10, 9, 8, 7}
33+
};
34+
int[][] actual = spiral.generateMatrix(4);
35+
36+
for (int i = 0; i < expected.length; i++) {
37+
assertArrayEquals(expected[i], actual[i], "Row " + i + " is incorrect for n=4");
38+
}
1939
}
2040

2141
@Test
2242
void testNEquals2() {
23-
int[][] expected = {{1, 2}, {4, 3}};
24-
assertArrayEquals(expected, spiral.generateMatrix(2));
43+
int[][] expected = {
44+
{1, 2},
45+
{4, 3}
46+
};
47+
int[][] actual = spiral.generateMatrix(2);
48+
49+
for (int i = 0; i < expected.length; i++) {
50+
assertArrayEquals(expected[i], actual[i], "Row " + i + " is incorrect for n=2");
51+
}
2552
}
2653
}

0 commit comments

Comments
 (0)