|
| 1 | +import org.junit.Before; |
| 2 | +import org.junit.Ignore; |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import static org.junit.Assert.assertArrayEquals; |
| 6 | + |
| 7 | +/* |
| 8 | + * version: 1.0.0 |
| 9 | + */ |
| 10 | +public class SpiralMatrixBuilderTest { |
| 11 | + |
| 12 | + private SpiralMatrixBuilder spiralMatrixBuilder; |
| 13 | + |
| 14 | + @Before |
| 15 | + public void setUp() { |
| 16 | + spiralMatrixBuilder = new SpiralMatrixBuilder(); |
| 17 | + } |
| 18 | + |
| 19 | + @Test |
| 20 | + public void testEmptySpiral() { |
| 21 | + int[][] expected = {}; |
| 22 | + |
| 23 | + assertArrayEquals(expected, spiralMatrixBuilder.buildMatrixOfSize(0)); |
| 24 | + } |
| 25 | + |
| 26 | + @Ignore("Remove to run test") |
| 27 | + @Test |
| 28 | + public void testTrivialSpiral() { |
| 29 | + int[][] expected = { |
| 30 | + {1} |
| 31 | + }; |
| 32 | + |
| 33 | + assertArrayEquals(expected, spiralMatrixBuilder.buildMatrixOfSize(1)); |
| 34 | + } |
| 35 | + |
| 36 | + @Ignore("Remove to run test") |
| 37 | + @Test |
| 38 | + public void testSpiralOfSize2() { |
| 39 | + int[][] expected = { |
| 40 | + {1, 2}, |
| 41 | + {4, 3} |
| 42 | + }; |
| 43 | + |
| 44 | + assertArrayEquals(expected, spiralMatrixBuilder.buildMatrixOfSize(2)); |
| 45 | + } |
| 46 | + |
| 47 | + @Ignore("Remove to run test") |
| 48 | + @Test |
| 49 | + public void testSpiralOfSize3() { |
| 50 | + int[][] expected = { |
| 51 | + {1, 2, 3}, |
| 52 | + {8, 9, 4}, |
| 53 | + {7, 6, 5} |
| 54 | + }; |
| 55 | + |
| 56 | + assertArrayEquals(expected, spiralMatrixBuilder.buildMatrixOfSize(3)); |
| 57 | + } |
| 58 | + |
| 59 | + @Ignore("Remove to run test") |
| 60 | + @Test |
| 61 | + public void testSpiralOfSize4() { |
| 62 | + int[][] expected = { |
| 63 | + { 1, 2, 3, 4}, |
| 64 | + {12, 13, 14, 5}, |
| 65 | + {11, 16, 15, 6}, |
| 66 | + {10, 9, 8, 7} |
| 67 | + }; |
| 68 | + |
| 69 | + assertArrayEquals(expected, spiralMatrixBuilder.buildMatrixOfSize(4)); |
| 70 | + } |
| 71 | + |
| 72 | + @Ignore("Remove to run test") |
| 73 | + @Test |
| 74 | + public void testSpiralOfSize5() { |
| 75 | + int[][] expected = { |
| 76 | + { 1, 2, 3, 4, 5}, |
| 77 | + {16, 17, 18, 19, 6}, |
| 78 | + {15, 24, 25, 20, 7}, |
| 79 | + {14, 23, 22, 21, 8}, |
| 80 | + {13, 12, 11, 10, 9} |
| 81 | + }; |
| 82 | + |
| 83 | + assertArrayEquals(expected, spiralMatrixBuilder.buildMatrixOfSize(5)); |
| 84 | + } |
| 85 | + |
| 86 | +} |
0 commit comments