Exemple #1
0
        public void MatrixConsoleOutputShouldBeAsExpectedWhenAValidMatrixIsCreated()
        {
            using (StringWriter testStringWriter = new StringWriter())
            {
                Console.SetOut(testStringWriter);
                RotatingWalkInMatrix.Main();
                Matrix testMatrix  = new Matrix(6);
                var    matrixUtils = new MatrixUtils(testMatrix, PossibleDirections.AllDirections, startingCell);
                matrixUtils.FillMatrix();
                StringBuilder expected = new StringBuilder();
                for (int i = 0; i < testMatrix.Field.GetLength(0); i++)
                {
                    for (int j = 0; j < testMatrix.Field.GetLength(0); j++)
                    {
                        expected.AppendFormat("{0,3}", testMatrix.Field[i, j]);
                    }

                    expected.Append(Environment.NewLine);
                }
                expected.Append(Environment.NewLine);
                string expectedString = expected.ToString();

                Assert.AreEqual(expectedString, testStringWriter.ToString());
            }
        }
Exemple #2
0
 public void TestSmallestPossibleMatrix()
 {
     int[,] matrix = new int[1, 1];
     RotatingWalkInMatrix.RotateWalkInMatrix(matrix);
     int[,] expected = new int[, ] {
         { 1 }
     };
     AssertMatrixEquality(matrix, expected);
 }
Exemple #3
0
        public void FillMatrixOfSizeOne_ShouldFillMatrixCorrectly()
        {
            int[,] matrix = RotatingWalkInMatrix.FillMatrix(1);

            int[,] expected =
            {
                { 1 }
            };

            CollectionAssert.AreEqual(expected, matrix);
        }
        public void GetPositionOutOfMatrixBoundaries_ShouldReturnTrue()
        {
            int[,] matrix = new int[3, 3];

            Cell position = new Cell(2, 2);

            Cell direction = new Cell(1, 1);

            bool isOutOfBoundaries = RotatingWalkInMatrix.IsOutOfBoundaries(matrix, position, direction);

            Assert.IsTrue(isOutOfBoundaries);
        }
Exemple #5
0
        public void FillMatrixOfSizeThree_ShouldFillMatrixCorrectly()
        {
            int[,] matrix = RotatingWalkInMatrix.FillMatrix(3);

            int[,] expected =
            {
                { 1, 7, 8 },
                { 6, 2, 9 },
                { 5, 4, 3 }
            };

            CollectionAssert.AreEqual(expected, matrix);
        }
Exemple #6
0
        public void PossibleMovement_WithEmptyCells_ShouldReturnTrue()
        {
            int[,] matrix =
            {
                { 1, 0, 0 },
                { 0, 2, 0 },
                { 0, 0, 3 }
            };

            Cell current = new Cell(2, 2);

            bool possibleMovement = RotatingWalkInMatrix.PossibleMovement(matrix, current);

            Assert.IsTrue(possibleMovement);
        }
Exemple #7
0
        public void PossibleMovement_WithNoEmptyCells_ShouldReturnFalse()
        {
            int[,] matrix =
            {
                { 1, 7, 8 },
                { 6, 2, 9 },
                { 5, 4, 3 }
            };

            Cell current = new Cell(1, 2);

            bool possibleMovement = RotatingWalkInMatrix.PossibleMovement(matrix, current);

            Assert.IsFalse(possibleMovement);
        }
Exemple #8
0
 public void TestSampleMatrix()
 {
     int[,] matrix = new int[6, 6];
     RotatingWalkInMatrix.RotateWalkInMatrix(matrix);
     int[,] expected = new int[, ]
     {
         { 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 },
     };
     AssertMatrixEquality(matrix, expected);
 }
Exemple #9
0
        public void FillMatrixOfSizeSix_ShouldFillMatrixCorrectly()
        {
            int[,] matrix = RotatingWalkInMatrix.FillMatrix(6);

            int[,] 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 }
            };

            CollectionAssert.AreEqual(expected, matrix);
        }
Exemple #10
0
        public void GenerateRotationMatrixTestWhitTwo()
        {
            const int n = 2;

            int[,] expected =
            {
                { 1, 4 },
                { 3, 2 }
            };
            int[,] result = RotatingWalkInMatrix.GenerateRotationgMatrix(n);

            string expectedString = MatrixToString(expected);
            string resultString   = MatrixToString(result);

            bool areEqual = (expectedString.Equals(resultString, StringComparison.InvariantCultureIgnoreCase));

            Assert.AreEqual(true, areEqual);
        }
Exemple #11
0
        public void FillMatrix_TwoDimensionalMatrix_ShouldFillCorrectMatrix()
        {
            // Arrange
            using (var sr = new StringReader("6"))
            {
                Console.SetIn(sr);

                // Act
                int[,] actual   = RotatingWalkInMatrix.FillMatrix(2);
                int[,] expected = new int[, ] {
                    { 1, 4 },
                    { 3, 2 }
                };

                // Assert
                CollectionAssert.AreEqual(expected, actual);
            }
        }
Exemple #12
0
        public void FillMatrix_ThreeDimensionalMatrix_ShouldFillCorrectMatrix()
        {
            // Arrange
            using (var sr = new StringReader("3"))
            {
                Console.SetIn(sr);

                // Act
                int[,] actual   = RotatingWalkInMatrix.FillMatrix(3);
                int[,] expected = new int[, ] {
                    { 1, 7, 8 },
                    { 6, 2, 9 },
                    { 5, 4, 3 }
                };

                // Assert
                CollectionAssert.AreEqual(expected, actual);
            }
        }
Exemple #13
0
        public void GetSmallestFreeCell_WhenNoMoreEmptyCellsInAllDirections_ShouldGetCellCorrectly()
        {
            int[,] matrix =
            {
                {  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 }
            };

            Cell smallestFreeCell = RotatingWalkInMatrix.GetSmallestFreeCell(matrix);

            Cell expected = new Cell(2, 1);

            //Assert.AreEqual(expected, smallestFreeCell);
            Assert.AreEqual(expected.Row, smallestFreeCell.Row);
            Assert.AreEqual(expected.Col, smallestFreeCell.Col);
        }
Exemple #14
0
        public void GenerateRotationMatrixTestWhitFife()
        {
            const int n = 5;

            int[,] expected =
            {
                {  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 }
            };
            int[,] result = RotatingWalkInMatrix.GenerateRotationgMatrix(n);

            string expectedString = MatrixToString(expected);
            string resultString   = MatrixToString(result);

            bool areEqual = (expectedString.Equals(resultString, StringComparison.InvariantCultureIgnoreCase));

            Assert.AreEqual(true, areEqual);
        }
Exemple #15
0
        public void FillMatrix_SixDimensionalMatrix_ShouldFillCorrectMatrix()
        {
            // Arrange
            using (var sr = new StringReader("6"))
            {
                Console.SetIn(sr);

                // Act
                int[,] actual   = RotatingWalkInMatrix.FillMatrix(6);
                int[,] expected = new int[, ] {
                    { 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
                CollectionAssert.AreEqual(expected, actual);
            }
        }
Exemple #16
0
        public void GenerateRotationMatrixTestWhitSeven()
        {
            const int n = 7;

            int[,] expected =
            {
                {  1, 19, 20, 21, 22, 23, 24 },
                { 18,  2, 33, 34, 35, 36, 25 },
                { 17, 40,  3, 32, 39, 37, 26 },
                { 16, 48, 41,  4, 31, 38, 27 },
                { 15, 47, 49, 42,  5, 30, 28 },
                { 14, 46, 45, 44, 43,  6, 29 },
                { 13, 12, 11, 10,  9,  8,  7 }
            };
            int[,] result = RotatingWalkInMatrix.GenerateRotationgMatrix(n);

            string expectedString = MatrixToString(expected);
            string resultString   = MatrixToString(result);

            bool areEqual = (expectedString.Equals(resultString, StringComparison.InvariantCultureIgnoreCase));

            Assert.AreEqual(true, areEqual);
        }
Exemple #17
0
 static void Main()
 {
     RotatingWalkInMatrix.GenerateRotationgMatrix(7);
 }