Пример #1
0
        public void HasEmptyCell_ReturnsTrue_CellFound()
        {
            this.matrix[2, 3] = 0;
            bool hasEmpty = MatrixWalk.HasEmptyCell(this.matrix);

            Assert.IsTrue(hasEmpty);
        }
Пример #2
0
    public void PrintMatrix_OneEmptyElement()
    {
        Console.SetIn(new StringReader("1"));
        int input = int.Parse(Console.ReadLine());

        MatrixWalk matrixWalk = new MatrixWalk(input);
        string result = matrixWalk.Print();

        Assert.AreEqual(result, string.Format("{0,4}{1}", 0, Environment.NewLine));
    }
Пример #3
0
        public void MatrixWalkTest()
        {
            var mat = new MatrixWalk(5);

            int expectedDimension1Size = 5;
            int expectedDimension2Size = 5;

            Assert.AreEqual(expectedDimension1Size, mat.Matrix.GetLength(0));
            Assert.AreEqual(expectedDimension2Size, mat.Matrix.GetLength(1));
        }
Пример #4
0
        public void MatrixWalkTest()
        {
            var mat = new MatrixWalk(5);

            int expectedDimension1Size = 5;
            int expectedDimension2Size = 5;

            Assert.AreEqual(expectedDimension1Size, mat.Matrix.GetLength(0));
            Assert.AreEqual(expectedDimension2Size, mat.Matrix.GetLength(1));
        }
        public void StartMatrixWalk_ValidParams_ShouldPrintCorrect()
        {
            int    cellSize     = 6;
            string expectedText = "  1 28 29 31 35 36 27  2 24 30 32 34 26 25  3 23 22 33 13 15 17  4 19 21 12 14 16 18  5 20 11 10  9  8  7  6";
            var    loggerMock   = new LoggerMock();

            MatrixWalk.StartMatrixWalk(cellSize, loggerMock);

            Assert.AreEqual(expectedText, loggerMock.Text.ToString());
        }
Пример #6
0
        public void HasEmptySurroundingCells_ReturnsTrue_RightEmpty()
        {
            int emptyX = 2;
            int emptyY = 4;

            this.matrix[emptyX, emptyY] = 0;

            bool isRightEmpty = MatrixWalk.HasEmptySurroundingCells(this.matrix, this.cell);

            Assert.IsTrue(isRightEmpty);
        }
Пример #7
0
        public void HasEmptySurroundingCells_ReturnsTrue_BottomEmpty()
        {
            int emptyX = 3;
            int emptyY = 3;

            this.matrix[emptyX, emptyY] = 0;

            bool isBottomRmpty = MatrixWalk.HasEmptySurroundingCells(this.matrix, this.cell);

            Assert.IsTrue(isBottomRmpty);
        }
Пример #8
0
 public void FiveDimensionsTest()
 {
     var matrix = new MatrixWalk(5);
     Assert.AreEqual(string.Format(
             "{0}{5}{1}{5}{2}{5}{3}{5}{4}{5}",
             "  1 13 14 15 16",
             " 12  2 21 22 17",
             " 11 23  3 20 18",
             " 10 25 24  4 19",
             "  9  8  7  6  5",
             "\r\n"), 
             matrix.ToString());
 }
Пример #9
0
        public void FindEmptyCell_ReturnsCorrectResult()
        {
            int targetRow = 1;
            int targetCol = 3;

            this.matrix[targetRow, targetCol] = 0;

            Cell cell = new Cell();

            MatrixWalk.FindEmptyCell(this.matrix, cell);

            Assert.AreEqual(targetRow, cell.Row);
            Assert.AreEqual(targetCol, cell.Col);
        }
Пример #10
0
 static void Main(string[] args)
 {
     Console.WriteLine("Enter a positive number ");
     string input = Console.ReadLine();
     int n = 0;
     while (!int.TryParse(input, out n) || n < 0 || n > 100)
     {
         Console.WriteLine("You haven't entered a correct positive number");
         input = Console.ReadLine();
     }
     MatrixWalk mat = new MatrixWalk(n);
     mat.Calculate();
     mat.Print();
 }
Пример #11
0
    public void FiveDimensionsTest()
    {
        var matrix = new MatrixWalk(5);

        Assert.AreEqual(string.Format(
                            "{0}{5}{1}{5}{2}{5}{3}{5}{4}{5}",
                            "  1 13 14 15 16",
                            " 12  2 21 22 17",
                            " 11 23  3 20 18",
                            " 10 25 24  4 19",
                            "  9  8  7  6  5",
                            "\r\n"),
                        matrix.ToString());
    }
Пример #12
0
    static void Main()
    {
        Console.Write("Enter a positive number: ");
        string input = Console.ReadLine();
        int number;
        while (!int.TryParse(input, out number) || number < 0 || number > 100)
        {
            Console.Write("You haven't entered a correct positive number. Enter again: ");
            input = Console.ReadLine();
        }

        MatrixWalk matrixWalk = new MatrixWalk(number);
        matrixWalk.Fill();
        Console.Write(matrixWalk.Print());
    }
Пример #13
0
        public void ChangeDirection_ChangesDirectionCorrectly()
        {
            int[] directionsX = { 1, 1, 1, 0, -1, -1, -1, 0 };
            int[] directionsY = { 1, 0, -1, -1, -1, 0, 1, 1 };

            Path path = new Path {
                Dx = 1, Dy = 1
            };

            for (int i = 1; i < directionsX.Length; i++)
            {
                MatrixWalk.ChangeDirection(path);

                Assert.AreEqual(directionsX[i], path.Dx);
                Assert.AreEqual(directionsY[i], path.Dy);
            }
        }
Пример #14
0
        public void CalculateTest()
        {
            var mat = new MatrixWalk(6);
            mat.Calculate();
            mat.Print();

            var expected = new int[6,6]{{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(expected, mat.Matrix);
        }
Пример #15
0
        public void CalculateTest()
        {
            var mat = new MatrixWalk(6);

            mat.Calculate();
            mat.Print();

            var expected = new int[6, 6] {
                { 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(expected, mat.Matrix);
        }
Пример #16
0
    public void PrintMatrix_InputSix()
    {
        Console.SetIn(new StringReader("6"));
        int input = int.Parse(Console.ReadLine());

        MatrixWalk matrixWalk = new MatrixWalk(input);
        matrixWalk.Fill();
        string result = matrixWalk.Print();
        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" + Environment.NewLine;

        Assert.AreEqual(result, expected);
    }
Пример #17
0
 public static void Main()
 {
     try
     {
         Console.WriteLine("Enter an integer between 1 and 100");
         int number = int.Parse(Console.ReadLine());
         var matrix = new MatrixWalk(number);
         Console.WriteLine(matrix);
     }
     catch (ArgumentException ex)
     {
         Console.WriteLine(ex.Message);
     }
     catch (FormatException ex)
     {
         Console.WriteLine(ex.Message);
         Console.WriteLine("You must enter an integer between 1 and 100.");
     }
 }
Пример #18
0
 public void MatrixWalkMaxSizeTest()
 {
     var mat = new MatrixWalk(101);
 }
Пример #19
0
 public void TooManyDimentionsTest()
 {
     var matrix = new MatrixWalk(101);
 }
Пример #20
0
    public void OneDimensionTest()
    {
        var matrix = new MatrixWalk(1);

        Assert.AreEqual("  1\r\n", matrix.ToString());
    }
Пример #21
0
        static void Main(string[] args)
        {
            int n = 6;

            MatrixWalk.StartMatrixWalk(n, new ConsoleLogger());
        }
Пример #22
0
        public void StartMatrixWalk_InvalidCellSize_ShouldThrow(int invalidCellSize)
        {
            var mockedLogger = new Mock <ILogger>();

            Assert.Throws <OverflowException>(() => MatrixWalk.StartMatrixWalk(invalidCellSize, mockedLogger.Object));
        }
Пример #23
0
 public void TwoDimensionsTest()
 {
     var matrix = new MatrixWalk(2);
     Assert.AreEqual("  1  4\r\n  3  2\r\n", matrix.ToString());
 }
Пример #24
0
 public void Constructor_ZeroElements()
 {
     Console.SetIn(new StringReader("0"));
     int input = int.Parse(Console.ReadLine());
     MatrixWalk matrixWalk = new MatrixWalk(input);
 }
Пример #25
0
 MatrixWalkSizeTest()
 {
     var mat = new MatrixWalk(0);
 }
Пример #26
0
 MatrixWalkMaxSizeTest()
 {
     var mat = new MatrixWalk(101);
 }
Пример #27
0
        public void HasEmptySurroundingCells_ReturnsFalse_NoCellFound()
        {
            bool isEmpty = MatrixWalk.HasEmptySurroundingCells(this.matrix, this.cell);

            Assert.IsFalse(isEmpty);
        }
Пример #28
0
 public void OneDimensionTest()
 {
     var matrix = new MatrixWalk(1);
     Assert.AreEqual("  1\r\n", matrix.ToString());
 }
Пример #29
0
    public void ThreeDimensionsTest()
    {
        var matrix = new MatrixWalk(3);

        Assert.AreEqual("  1  7  8\r\n  6  2  9\r\n  5  4  3\r\n", matrix.ToString());
    }
Пример #30
0
 public void MatrixWalkSizeTest()
 {
     var mat = new MatrixWalk(0);
 }
Пример #31
0
        public void HasEmptyCell_ReturnsFalse_CellNotFound()
        {
            bool hasEmpty = MatrixWalk.HasEmptyCell(this.matrix);

            Assert.IsFalse(hasEmpty);
        }
Пример #32
0
 public void NegativeDimensionsTest()
 {
     var matrix = new MatrixWalk(-1);
 }
Пример #33
0
        public void StartMatrixWalk_InvalidLogger_ShouldThrow()
        {
            int cellSize = 50;

            Assert.Throws <ArgumentNullException>(() => MatrixWalk.StartMatrixWalk(cellSize, null));
        }
Пример #34
0
 public void NegativeDimensionsTest()
 {
     var matrix = new MatrixWalk(-1);
 }
Пример #35
0
 public void ThreeDimensionsTest()
 {
     var matrix = new MatrixWalk(3);
     Assert.AreEqual("  1  7  8\r\n  6  2  9\r\n  5  4  3\r\n", matrix.ToString());
 }
Пример #36
0
 public void TooManyDimentionsTest()
 {
     var matrix = new MatrixWalk(101);
 }
Пример #37
0
    public void TwoDimensionsTest()
    {
        var matrix = new MatrixWalk(2);

        Assert.AreEqual("  1  4\r\n  3  2\r\n", matrix.ToString());
    }