public void Test1() { int[] row1 = { 13, 9, 5, 1 }; int[] row2 = { 14, 10, 6, 2 }; int[] row3 = { 15, 11, 7, 3 }; int[] row4 = { 16, 12, 8, 4 }; int[][] testGrid = { row1, row2, row3, row4 }; Assert.AreEqual(testGrid, rotateMatrix.Rotate(matrix)); }
public void RotateMatrixTest(int rowsCount, params int[][] rows) { var m = new List <int[]>(); for (var i = 0; i < rowsCount; i++) { m.Add(rows[i]); } var actual = m.ToArray(); RotateMatrix.Rotate(actual); var expected = new List <int[]>(); for (var i = rowsCount; i < (rows?.Length ?? 0); i++) { expected.Add(rows[i]); } for (var i = 0; i < actual.Length; i++) { for (var j = 0; j < actual.Length; j++) { Assert.Equal(expected[i][j], actual[i][j]); } } }
public void TestRotateMatrix() { 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 } }; int[,] expected = new int[, ] { { 21, 16, 11, 6, 1 }, { 22, 17, 12, 7, 2 }, { 23, 18, 13, 8, 3 }, { 24, 19, 14, 9, 4 }, { 25, 20, 15, 10, 5 } }; RotateMatrix rm = new RotateMatrix(matrix); rm.Rotate(); Assert.Equal(expected, matrix); matrix = new int[, ] { { 1, 2 }, { 3, 4, } }; expected = new int[, ] { { 3, 1 }, { 4, 2 } }; rm = new RotateMatrix(matrix); rm.Rotate(); Assert.Equal(expected, matrix); matrix = new int[, ] { { 120 } }; expected = new int[, ] { { 120 } }; rm = new RotateMatrix(matrix); rm.Rotate(); Assert.Equal(expected, matrix); }
public void Rotate_Success() { int[,] data = new int[4, 4] { { 3, 6, 9, 10 }, { 4, 5, 6, 8 }, { 1, 2, 3, 6 }, { 4, 7, 8, 9 } }; var result = RotateMatrix.Rotate(data, 4); Assert.AreEqual(result[0, 0], 10, "(0,0) is not equal to 10."); Assert.AreEqual(result[1, 0], 9, "(1,0) number is not equal to 9."); Assert.AreEqual(result[2, 0], 6, "(2,0) number is not equal to 6."); Assert.AreEqual(result[3, 0], 3, "(3,0) number is not equal to 3."); }
public void TestRotateMatrix(string sourceString, string targetString) { Assert.Equal(StringToMatrix(targetString), RotateMatrix.Rotate(StringToMatrix(sourceString))); }