|
1 | 1 | package com.thealgorithms.matrix; |
| 2 | + |
2 | 3 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
3 | 4 | import org.junit.jupiter.api.Test; |
4 | 5 |
|
5 | 6 | class SpiralMatrixIITest { |
6 | 7 |
|
7 | | - SpiralMatrix spiral = new SpiralMatrix(); |
| 8 | + // Instantiate the class to test |
| 9 | + SpiralMatrixII spiral = new SpiralMatrixII(); |
8 | 10 |
|
9 | 11 | @Test |
10 | 12 | 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 | + } |
13 | 24 | } |
14 | 25 |
|
15 | 26 | @Test |
16 | 27 | 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 | + } |
19 | 39 | } |
20 | 40 |
|
21 | 41 | @Test |
22 | 42 | 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 | + } |
25 | 52 | } |
26 | 53 | } |
0 commit comments