@Test public void rotateNXNMatrix_1_6() { int[][] matrix = new int[][] { { 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} }; int[][] matrixExpect = new int[][] { {31, 25, 19, 13, 7, 1}, {32, 26, 20, 14, 8, 2}, {33, 27, 21, 15, 9, 3}, {34, 28, 22, 16, 10, 4}, {35, 29, 23, 17, 11, 5}, {36, 30, 24, 18, 12, 6} }; int[][] matrixGot = Chapter1.rotateNXNMatrix_1_6(matrix, 6); for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { assertEquals(matrixExpect[i][j], matrixGot[i][j]); } } }
@Test public void zeroOutMatrix_Q_1_7() { int[][] matrix = new int[][] { {1, 2, 3}, { 7, 0, 9, }, {13, 14, 0} }; int[][] matrixExpect = new int[][] { {1, 0, 0}, { 0, 0, 0, }, {0, 0, 0} }; Chapter1.zeroOutMatrix_Q_1_7(matrix, 3); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { assertEquals(matrixExpect[i][j], matrix[i][j]); } } }
@Test public void isPermuationWithHash1_Q_1_1() { assertTrue(Chapter1.isPermuationWithHash1_Q_1_1("test", "test")); }
@Test public void Testcompressionworks() { assertEquals("a3b1c1d2e3f3", Chapter1.compression_Q_1_5("aaabcddeeefff")); }
@Test public void compressionSameString_Q_1_5() { assertEquals("a2b1c5a3", Chapter1.compression_Q_1_5("aabcccccaaa")); }
@Test public void replaceSpacesWithPercentTwenty_Q_1_4() { char[] testArr = "Mr John Smith ".toCharArray(); Chapter1.replaceSpacesWithPercentTwenty_Q_1_4(testArr, 13); assertEquals("Mr%20John%20Smith", String.valueOf(testArr)); }
@Test public void isPermuationWithHashDiffString1_Q_1_1() { assertFalse(Chapter1.isPermuationWithHash1_Q_1_1("test", "test1")); }
@Test public void isPermuationNoDataStructure_Q_1_1() { assertTrue(Chapter1.isPermuationNoDataStructure_Q_1_1("test", "test")); }