public void PrintMatrixToConsoleSizeFiveTest() { string outputFile = "ConsoleOutput.txt"; StreamWriter writer = new StreamWriter(outputFile); using (writer) { Console.SetOut(writer); WalkInMatrix matrix = new WalkInMatrix(5); matrix.PrintMatrixToConsole(); } StreamReader reader = new StreamReader(outputFile); string consoleResult = string.Empty; using (reader) { consoleResult = reader.ReadToEnd(); } string expectedResult = @" 1 13 14 15 16 12 2 21 22 17 11 22 3 20 18 10 24 23 4 19 9 8 7 6 5 "; Assert.AreEqual(expectedResult, consoleResult, "result is incorect"); }
public void PrintMatrixToConsoleSizeFiveTest() { string outputFile = "ConsoleOutput.txt"; StreamWriter writer = new StreamWriter(outputFile); using(writer) { Console.SetOut(writer); WalkInMatrix matrix = new WalkInMatrix(5); matrix.PrintMatrixToConsole(); } StreamReader reader = new StreamReader(outputFile); string consoleResult = string.Empty; using (reader) { consoleResult = reader.ReadToEnd(); } string expectedResult = @" 1 13 14 15 16 12 2 21 22 17 11 22 3 20 18 10 24 23 4 19 9 8 7 6 5 "; Assert.AreEqual(expectedResult, consoleResult, "result is incorect"); }
public void GetMatrix() { WalkInMatrix walk = new WalkInMatrix(3); walk.FillMatrix(); int[,] expected = new int[, ] { { 1, 7, 8 }, { 6, 2, 9 }, { 5, 4, 3 }, }; int[,] actual = walk.GetMatrix; bool areEqual = true; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (expected[i, j] != actual[i, j]) { areEqual = false; } } } Assert.AreEqual(true, areEqual); }
public void PrintMatrixToConsoleSizeTenTest() { string outputFile = "ConsoleOutput.txt"; StreamWriter writer = new StreamWriter(outputFile); using (writer) { Console.SetOut(writer); WalkInMatrix matrix = new WalkInMatrix(10); matrix.PrintMatrixToConsole(); } StreamReader reader = new StreamReader(outputFile); string consoleResult = string.Empty; using (reader) { consoleResult = reader.ReadToEnd(); } string expectedResult = @" 1 28 29 30 31 32 33 34 35 36 27 2 51 52 53 54 55 56 57 37 26 72 3 50 66 67 68 69 58 38 25 89 73 4 49 65 72 70 59 39 24 88 90 74 5 48 64 71 60 40 23 87 98 91 75 6 47 63 61 41 22 86 97 99 92 76 7 46 62 42 21 85 96 95 94 93 77 8 45 43 20 84 83 82 81 80 79 78 9 44 19 18 17 16 15 14 13 12 11 10 "; Assert.AreEqual(expectedResult, consoleResult, "result is incorect"); }
public void WalkInMatrixTest15() { int n = 15; int[,] matrix = WalkInMatrix.BuildMatrix(n); int[,] expectedOutput = { { 1, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56 }, { 42, 2, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 57 }, { 41, 148, 3, 80, 111, 112, 113, 114, 115, 116, 117, 118, 119, 93, 58 }, { 40, 180, 149, 4, 79, 110, 132, 133, 134, 135, 136, 137, 120, 94, 59 }, { 39, 179, 181, 150, 5, 78, 109, 131, 144, 145, 146, 138, 121, 95, 60 }, { 38, 178, 204, 182, 151, 6, 77, 108, 130, 143, 147, 139, 122, 96, 61 }, { 37, 177, 203, 205, 183, 152, 7, 76, 107, 129, 142, 140, 123, 97, 62 }, { 36, 176, 202, 219, 206, 184, 153, 8, 75, 106, 128, 141, 124, 98, 63 }, { 35, 175, 201, 218, 220, 207, 185, 154, 9, 74, 105, 127, 125, 99, 64 }, { 34, 174, 200, 217, 225, 221, 208, 186, 155, 10, 73, 104, 126, 100, 65 }, { 33, 173, 199, 216, 224, 223, 222, 209, 187, 156, 11, 72, 103, 101, 66 }, { 32, 172, 198, 215, 214, 213, 212, 211, 210, 188, 157, 12, 71, 102, 67 }, { 31, 171, 197, 196, 195, 194, 193, 192, 191, 190, 189, 158, 13, 70, 68 }, { 30, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 14, 69 }, { 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15 } }; CollectionAssert.AreEqual(matrix, expectedOutput, "Collections are not equal"); }
public void TestWalkInMatrixOfSizeTwo() { WalkInMatrix matrix = new WalkInMatrix(2); matrix.Walk(); string expected = "1 4 " + Environment.NewLine + "3 2"; Assert.AreEqual(expected, matrix.ToString()); }
public void TestWalkInMatrixOfSizeOne() { WalkInMatrix matrix = new WalkInMatrix(1); matrix.Walk(); string expected = "1"; Assert.AreEqual(expected, matrix.ToString()); }
public void SizeSixTest() { WalkInMatrix matrix = new WalkInMatrix(6); Assert.IsTrue(matrix.ToString() == string.Format("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}\r\n", " 1 16 17 18 19 20", " 15 2 27 28 29 21", " 14 31 3 26 30 22", " 13 36 32 4 25 23", " 12 35 34 33 5 24", " 11 10 9 8 7 6")); }
public void TestIfWithThreeResultIsWillBeCorrect() { var walkInMatrix = new WalkInMatrix(3); var expectedResult = new string[] { " 1 7 8", " 6 2 9", " 5 4 3\r\n" }; Assert.AreEqual(string.Join("\r\n", expectedResult), walkInMatrix.ToString(), "Result is incorrect"); }
public void ToStringSize3() { WalkInMatrix walk = new WalkInMatrix(3); walk.FillMatrix(); string expected = " 1 7 8\r\n" + " 6 2 9\r\n" + " 5 4 3\r\n"; string actual = walk.ToString(); Assert.AreEqual(expected, walk.ToString()); }
public void WalkInMatrixTest2() { int n = 2; int[,] matrix = WalkInMatrix.BuildMatrix(n); int[,] expectedOutput = { { 1, 4 }, { 3, 2 }, }; CollectionAssert.AreEqual(matrix, expectedOutput, "Collections are not equal"); }
public void TestGenerateMatrixWithSize1() { int[,] matrix = WalkInMatrix.GenerateMatrix(1); int[,] expectedResult = { { 1 } }; for (int row = 0; row < matrix.GetLength(0); row++) { for (int col = 0; col < matrix.GetLength(1); col++) { Assert.AreEqual(expectedResult[row, col], matrix[row, col]); } } }
public void WalkInMatrixTest3() { int n = 3; int[,] matrix = WalkInMatrix.BuildMatrix(n); int[,] expectedOutput = { { 1, 7, 8 }, { 6, 2, 9 }, { 5, 4, 3 }, }; CollectionAssert.AreEqual(matrix, expectedOutput, "Collections are not equal"); }
public void TestWalkInMatrixOfSizeSix() { WalkInMatrix matrix = new WalkInMatrix(6); matrix.Walk(); string expected = "1 16 17 18 19 20 " + Environment.NewLine + "15 2 27 28 29 21 " + Environment.NewLine + "14 31 3 26 30 22 " + Environment.NewLine + "13 36 32 4 25 23 " + Environment.NewLine + "12 35 34 33 5 24 " + Environment.NewLine + "11 10 9 8 7 6"; Assert.AreEqual(expected, matrix.ToString()); }
public void ToStringSize6() { WalkInMatrix walk = new WalkInMatrix(6); walk.FillMatrix(); string expected = " 1 16 17 18 19 20\r\n" + " 15 2 27 28 29 21\r\n" + " 14 31 3 26 30 22\r\n" + " 13 36 32 4 25 23\r\n" + " 12 35 34 33 5 24\r\n" + " 11 10 9 8 7 6\r\n"; string actual = walk.ToString(); Assert.AreEqual(expected, walk.ToString()); }
public void TestIfWithSixResultIsWillBeCorrect() { var walkInMatrix = new WalkInMatrix(6); var expectedResult = new string[] { " 1 16 17 18 19 20", " 15 2 27 28 29 21", " 14 31 3 26 30 22", " 13 36 32 4 25 23", " 12 35 34 33 5 24", " 11 10 9 8 7 6\r\n" }; Assert.AreEqual(string.Join("\r\n", expectedResult), walkInMatrix.ToString(), "Result Is incorrect"); }
public void Output_Input1_ReturnExpectedResuslt() { int[,] expectedOutput = { { 1 } }; var walkInMatrix = new WalkInMatrix(1); var actualOutput = walkInMatrix.Run(); var expected = OutputAsString(expectedOutput); var actual = OutputAsString(actualOutput); Assert.AreEqual(expected, actual); }
public void WalkInMatrixTest6() { int n = 6; int[,] matrix = WalkInMatrix.BuildMatrix(n); int[,] expectedOutput = { { 1, 16, 17, 18, 19, 20 }, { 15, 2, 27, 28, 29, 21 }, { 14, 31, 3, 26, 30, 22 }, { 13, 36, 32, 4, 25, 23 }, { 12, 35, 34, 33, 5, 24 }, { 11, 10, 9, 8, 7, 6 } }; CollectionAssert.AreEqual(matrix, expectedOutput, "Collections are not equal"); }
public void StartFromTheTopLeftCorner(int matrixSize) { // Walk in the matrix starts from the top left corner of the matrix. // Arrange var reader = new Mock <IReadable>(); reader.Setup(x => x.ReadSize()).Returns(matrixSize); var writer = new Mock <IWritable>(); // Act var walk = new WalkInMatrix(reader.Object, writer.Object); walk.Execute(); // Assert Assert.AreEqual(1, walk.Matrix[0, 0]); }
public void PrintTheMatrix_WhenNoEmptyCellIsLeft(int matrixSize) { // When no empty cell is left in the matrix, the walk is finished. // Arrange var reader = new Mock <IReadable>(); reader.Setup(x => x.ReadSize()).Returns(matrixSize); var writer = new Mock <IWritable>(); var walk = new WalkInMatrix(reader.Object, writer.Object); // Act walk.Execute(); // Assert writer.Verify(x => x.Write(It.IsAny <string>())); }
public void GoInDownRightDirectionToTheBottomRightCorner(int matrixSize) { // Goes in down-right direction. // Arrange // matrixSize is always the value at the bottom-right corner(matrix is square) var reader = new Mock <IReadable>(); reader.Setup(x => x.ReadSize()).Returns(matrixSize); var writer = new Mock <IWritable>(); var walk = new WalkInMatrix(reader.Object, writer.Object); // Act walk.Execute(); // Assert Assert.AreEqual(matrixSize, walk.Matrix[matrixSize - 1, matrixSize - 1]); }
public void TestCreateMatrix_InputSize6_ShouldCreateMatrixCorrectly() { int[,] actualMatrix = WalkInMatrix.Create2DMatrix(6); int[,] expectedMatrix = { { 1, 16, 17, 18, 19, 20 }, { 15, 2, 27, 28, 29, 21 }, { 14, 31, 3, 26, 30, 22 }, { 13, 36, 32, 4, 25, 23 }, { 12, 35, 34, 33, 5, 24 }, { 11, 10, 9, 8, 7, 6 } }; for (int row = 0; row < actualMatrix.GetLength(0); row++) { for (int column = 0; column < actualMatrix.GetLength(1); column++) { Assert.AreEqual(expectedMatrix[row, column], actualMatrix[row, column], "Matrix with size 6 was not created as expected."); } } }
public void TestGenerateMatrixWithSize6() { int[,] matrix = WalkInMatrix.GenerateMatrix(6); int[,] expectedResult = { { 1, 16, 17, 18, 19, 20 }, { 15, 2, 27, 28, 29, 21 }, { 14, 31, 3, 26, 30, 22 }, { 13, 36, 32, 4, 25, 23 }, { 12, 35, 34, 33, 5, 24 }, { 11, 10, 9, 8, 7, 6 } }; for (int row = 0; row < matrix.GetLength(0); row++) { for (int col = 0; col < matrix.GetLength(1); col++) { Assert.AreEqual(expectedResult[row, col], matrix[row, col]); } } }
public void RestartTheWalk_WhenNoEmptyCellIsAvailableAtAllDirections_ButThereAreStillEmptyCellsInMatrix() { // this test requires matrixSize >= 4, since there will be no empty cells after the first walk otherwise // When no empty cell is available at all directions, the walk is restarted from an empty cell at the // smallest possible row and as close as possible to the start of this row. // Arrange int matrixSize = 6; var reader = new Mock <IReadable>(); reader.Setup(x => x.ReadSize()).Returns(matrixSize); var writer = new Mock <IWritable>(); var walk = new WalkInMatrix(reader.Object, writer.Object); // Act walk.Execute(); // Assert Assert.AreEqual(31, walk.Matrix[2, 1]); }
public void ChangeDirectionClockwise_WhenNoContinuationIsAvailableAtCurrentDirection(int matrixSize) { // When no continuation is available at the current direction (either the matrix wall or non-empty cell is // reached), the direction is changed to the next possible clockwise. // Arrange // matrixSize is always the value at the bottom-right corner(matrix is square) var reader = new Mock <IReadable>(); reader.Setup(x => x.ReadSize()).Returns(matrixSize); var writer = new Mock <IWritable>(); var walk = new WalkInMatrix(reader.Object, writer.Object); // Act walk.Execute(); // Assert // (matrixSize + 1) --> is always the value at the first possible cell clockwise // walk.Matrix[matrixSize - 1, matrixSize - 2] --> is always the coordinates of the first possible cell clockwise Assert.AreEqual(matrixSize + 1, walk.Matrix[matrixSize - 1, matrixSize - 2]); }
public void SizeTwoTest() { WalkInMatrix matrix = new WalkInMatrix(2); Assert.IsTrue(matrix.ToString() == string.Format(" 1 4\r\n 3 2\r\n")); }
public void SizeThreeTest() { WalkInMatrix matrix = new WalkInMatrix(3); Assert.IsTrue(matrix.ToString() == string.Format(" 1 7 8\r\n 6 2 9\r\n 5 4 3\r\n")); }
public void OutOfRangeTest() { WalkInMatrix matrix = new WalkInMatrix(102); }
public void SizeOneTest() { WalkInMatrix matrix = new WalkInMatrix(1); Assert.IsTrue(matrix.ToString() == string.Format(" 1\r\n")); }
public void NegativeSizeTest() { WalkInMatrix matrix = new WalkInMatrix(-7); }
public void ZeroSizedTest() { WalkInMatrix matrix = new WalkInMatrix(0); }