public void TestFillMatrix() { FillMatrix matrix = new FillMatrix(6); int[,] expected = new int[, ] { { 1, 16, 17, 18, 19, 20 }, { 15, 2, 27, 28, 29, 21 }, { 14, 0, 3, 26, 30, 22 }, { 13, 0, 0, 4, 25, 23 }, { 12, 0, 0, 0, 5, 24 }, { 11, 10, 9, 8, 7, 6 } }; int horizontal = 0; int vertical = 0; matrix.FillMatrixWithNumbers(vertical, horizontal, 6); bool isSame = true; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (matrix.Matrix[i, j] != expected[i, j]) { isSame = false; } } } Assert.AreEqual(true, isSame); }
public void TheMaxFilledNumberShoudBeSizeToTheSecondPower(string size) { int matrixCellsNumber = Int32.Parse(size) * Int32.Parse(size); StringReader reader = new StringReader(size); StringWriter writer = new StringWriter(); Console.SetIn(reader); Console.SetOut(writer); FillMatrix.Main(); string output = writer.ToString(); output = output.Replace("Enter a positive number ", string.Empty); output = output.Replace("\r", string.Empty); output = output.Replace("\n", string.Empty); string[] separators = { " " }; string[] outputNumbers = output.Split(separators, StringSplitOptions.RemoveEmptyEntries); int maxNumber = 0; for (int i = 0; i < matrixCellsNumber; i++) { int currentNumber = Int32.Parse(outputNumbers[i].Trim()); if (currentNumber > maxNumber) { maxNumber = currentNumber; } } Assert.AreEqual(matrixCellsNumber, maxNumber); reader.Dispose(); writer.Dispose(); }
public void ConstructorShouldCreateTheCorrectSizeMatrix_WhenValidValueIsPassed() { // Arrange and Act var matrixSize = 5; var sut = new FillMatrix(matrixSize); // Assert Assert.AreEqual(matrixSize, sut.Matrix.GetLength(0)); Assert.AreEqual(matrixSize, sut.Matrix.GetLength(1)); }
public static bool checkNMore(ref double[] s) { FillMatrix fillMatrix = new FillMatrix(); Console.WriteLine(" Введите точность вычислений.(Количесвто знаков после запятой)"); //Ввод точности вычислений Console.WriteLine(); Console.Write(" -> "); int sign = 0; try { sign = int.Parse(Console.ReadLine()); } catch (FormatException) { Console.WriteLine("Вводить нужно только числа!"); } Console.WriteLine(); if (sign > 0) { string wich = "";//Задание точности for (int i = 0; i < sign; i++) { wich += "0"; } Console.WriteLine(); s = fillMatrix.fillMatrix(s.Length, sign); //Получение ответа Console.WriteLine(" ___________________ответ_________________"); Console.WriteLine(); if (s != null) { Console.WriteLine("c["); //Вывод ответа for (int i = 0; i < s.Length; i++) { Console.WriteLine(String.Format("{0:0." + wich + "}", s[i])); } Console.Write("]"); } else { Console.WriteLine(" Детерминант равен 0! Система не имеет решений."); } return(false); } else { return(true); } }
public void CheckNineCellsMatrix() { StringReader reader = new StringReader("3"); StringWriter writer = new StringWriter(); Console.SetIn(reader); Console.SetOut(writer); FillMatrix.Main(); string expectedOutput = "Enter a positive number \r\n 1 7 8\r\n 6 2 9\r\n 5 4 3\r\n"; Assert.AreEqual(expectedOutput, writer.ToString()); reader.Dispose(); writer.Dispose(); }
public void TestPrintMatrix() { StreamWriter writer = new StreamWriter("testprint.txt"); Console.SetOut(writer); FillMatrix matrix = new FillMatrix(6); int horizontal = 0; int vertical = 0; matrix.FillMatrixWithNumbers(vertical, horizontal, 6); matrix.FindEmptyCell(out vertical, out horizontal); matrix.FillMatrixWithNumbers(vertical, horizontal, 6); using (writer) { matrix.PrintMatrix(); } StreamReader reader = new StreamReader("testprint.txt"); StringBuilder result = new StringBuilder(); using (reader) { for (int i = 0; i < 6; i++) { result.Append(reader.ReadLine()); result.AppendLine(); } } string resultStr = result.ToString(); string expected = @" 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 "; Assert.AreEqual(resultStr, expected); }
public void AskUntilValidMatrixSizeEntered(string input) { StringReader reader = new StringReader(input + "\n3"); StringWriter writer = new StringWriter(); Console.SetIn(reader); Console.SetOut(writer); FillMatrix.Main(); string expectedOutput = "Enter a positive number \r\n" + "You haven't entered a correct positive number\r\n" + " 1 7 8\r\n" + " 6 2 9\r\n" + " 5 4 3\r\n"; Assert.AreEqual(expectedOutput, writer.ToString()); reader.Dispose(); writer.Dispose(); }
public void ChangeOfDirectionsShouldSwitchDirectionsCorrect(int directionNumber) { int[] rowDirections = { 1, 1, 1, 0, -1, -1, -1, 0 }; int[] colDirections = { 1, 0, -1, -1, -1, 0, 1, 1 }; int inputDirectionRow = rowDirections[directionNumber - 1], inputDirectionCol = colDirections[directionNumber - 1]; FillMatrix.ChangeDirection(ref inputDirectionRow, ref inputDirectionCol); if (directionNumber < 8) { Assert.AreEqual(rowDirections[directionNumber], inputDirectionRow); Assert.AreEqual(colDirections[directionNumber], inputDirectionCol); } else { Assert.AreEqual(rowDirections[0], inputDirectionRow); Assert.AreEqual(colDirections[0], inputDirectionCol); } }
public void TheResultMatrixShouldHaveAccurateSize(string size) { StringReader reader = new StringReader(size); StringWriter writer = new StringWriter(); Console.SetIn(reader); Console.SetOut(writer); FillMatrix.Main(); string output = writer.ToString(); output = output.Replace("Enter a positive number ", string.Empty); output = output.Replace("\r", string.Empty); output = output.Replace("\n", string.Empty); string[] separators = { " " }; string[] outputNumbers = output.Split(separators, StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(Int32.Parse(size) * Int32.Parse(size), outputNumbers.Length); reader.Dispose(); writer.Dispose(); }
public void TestFindEmptyCell() { FillMatrix matrix = new FillMatrix(4); matrix.Matrix = new int[4, 4] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 1, 0, 3, 4 }, { 1, 2, 3, 4 } }; int horizontal = 0; int vertical = 0; matrix.FindEmptyCell(out vertical, out horizontal); Assert.AreEqual(2, vertical); Assert.AreEqual(1, horizontal); }
public void ConstructorShouldCorrectlyInitializeAllMatrixParameters_WhenValidValueIsPassed() { // Arrange var matrixSize = 5; var expectedRow = 0; var expectedCol = 0; var expectedRowIncrement = 1; var expectedColIncrement = 1; var expectedNumber = 1; // Act var sut = new FillMatrix(matrixSize); // Assert Assert.AreEqual(expectedRow, sut.Row); Assert.AreEqual(expectedCol, sut.Column); Assert.AreEqual(expectedRowIncrement, sut.RowIncrement); Assert.AreEqual(expectedColIncrement, sut.ColumnIncrement); Assert.AreEqual(expectedNumber, sut.Number); }
public void HaveEmptyNeighbourShouldReturnTrueByPresenceOfEmptyNeighbour() { int[,] firstMatrix = { { 1, 2, 3 }, { 4, 5, 0 }, { 7, 8, 9 } }; Assert.AreEqual(true, FillMatrix.HaveEmptyNeighbour(firstMatrix, 0, 2)); int[,] secondMatrix = { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 8, 9 } }; Assert.AreEqual(true, FillMatrix.HaveEmptyNeighbour(secondMatrix, 1, 1)); int[,] thirdMatrix = { { 1, 0, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; Assert.AreEqual(true, FillMatrix.HaveEmptyNeighbour(thirdMatrix, 1, 0)); }
public void HaveEmptyNeighbourShouldReturnFalseIfOnlyEmptyCellIsNotNeighbourOfCurrentCell() { int[,] firstMatrix = { { 1, 2, 3 }, { 4, 5, 0 }, { 7, 8, 9 } }; Assert.AreEqual(false, FillMatrix.HaveEmptyNeighbour(firstMatrix, 0, 0)); int[,] secondMatrix = { { 1, 2, 3 }, { 4, 5, 6 }, { 0, 8, 9 } }; Assert.AreEqual(false, FillMatrix.HaveEmptyNeighbour(secondMatrix, 1, 2)); int[,] thirdMatrix = { { 1, 0, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; Assert.AreEqual(false, FillMatrix.HaveEmptyNeighbour(thirdMatrix, 2, 1)); }
public void ChangeOfDirectionsShouldThrowByWrongInput(int currentRowDirection, int currentColDirection) { Assert.Throws(typeof(ArgumentOutOfRangeException), () => { FillMatrix.ChangeDirection(ref currentRowDirection, ref currentColDirection); }, "Boo!"); }