示例#1
0
        public void Question_1_7_EdgeCases()
        {
            var image    = MatrixHelpers.CreateTwoDimensionalMatrix(1, 1, 'a');
            var expected = MatrixHelpers.CreateTwoDimensionalMatrix(1, 1, 'a');

            Question_1_7.Rotate(image);
            TestHelpers.AssertMatricesEqual(expected, image, "1x1");
        }
        public void RotateMatrixTest_2x2()
        {
            int[,] testMatrix = new int[2, 2]
            {
                { 1, 2 },
                { 3, 4 }
            };
            int[,] expectedMatrix = new int[2, 2]
            {
                { 2, 4 },
                { 1, 3 }
            };

            int[,] resultMatrix = Question_1_7.RotateMatrix(testMatrix);
            TestHelper.AssertMatricesAreEqual(expectedMatrix, resultMatrix);
        }
        public void RotateMatrixInplaceTest_3x3()
        {
            int[,] testMatrix = new int[3, 3]
            {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            };
            int[,] expectedMatrix = new int[3, 3]
            {
                { 3, 6, 9 },
                { 2, 5, 8 },
                { 1, 4, 7 }
            };

            Question_1_7.RotateMatrixInplace(testMatrix);
            TestHelper.AssertMatricesAreEqual(expectedMatrix, testMatrix);
        }
        public void RotateMatrixTest_4x4()
        {
            int[,] testMatrix = new int[4, 4]
            {
                { 1, 2, 3, 4 },
                { 5, 6, 7, 8 },
                { 9, 10, 11, 12 },
                { 13, 14, 15, 16 }
            };
            int[,] expectedMatrix = new int[4, 4]
            {
                { 4, 8, 12, 16 },
                { 3, 7, 11, 15 },
                { 2, 6, 10, 14 },
                { 1, 5, 9, 13 }
            };

            int[,] resultMatrix = Question_1_7.RotateMatrix(testMatrix);
            TestHelper.AssertMatricesAreEqual(expectedMatrix, resultMatrix);
        }
示例#5
0
        public void Question_1_7_Basic()
        {
            // 2x2 matrix rotation
            //
            // 1 2  => 3 1
            // 3 4     4 2
            var image    = MatrixHelpers.CreateTwoDimensionalMatrix(2, 2, '1', '2', '3', '4');
            var expected = MatrixHelpers.CreateTwoDimensionalMatrix(2, 2, '3', '1', '4', '2');

            Question_1_7.Rotate(image);
            TestHelpers.AssertMatricesEqual(expected, image, "2x2");

            // 3x3 matrix rotation
            //
            // 1 2 3 => 7 4 1
            // 4 5 6    8 5 2
            // 7 8 9    9 6 3
            image    = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, '1', '2', '3', '4', '5', '6', '7', '8');
            expected = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, '7', '4', '1', '8', '5', '2', '9', '6', '3');

            Question_1_7.Rotate(image);
            TestHelpers.AssertMatricesEqual(expected, image, "3x3");

            image = new char[, ] {
                { 'a', 'e', 'i', 'm' }, { 'b', 'f', 'j', 'n' }, { 'c', 'g', 'k', 'o' }, { 'd', 'h', 'l', 'p' }
            };
            expected = new char[, ] {
                { 'm', 'n', 'o', 'p' }, { 'i', 'j', 'k', 'l' }, { 'e', 'f', 'g', 'h' }, { 'a', 'b', 'c', 'd' }
            };
            // 4x4 matrix rotation
            //
            // a b c d    m i e a
            // e f g h => n j f b
            // i j k l    o k g c
            // m n o p    p l h d
            image    = MatrixHelpers.CreateTwoDimensionalMatrix(4, 4, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p');
            expected = MatrixHelpers.CreateTwoDimensionalMatrix(4, 4, 'm', 'i', 'e', 'a', 'n', 'j', 'f', 'b', 'o', 'k', 'g', 'c', 'p', 'l', 'h', 'd');

            Question_1_7.Rotate(image);
            TestHelpers.AssertMatricesEqual(expected, image, "4x4");
        }
示例#6
0
 public void Question_1_7_InavlidCases()
 {
     TestHelpers.AssertExceptionThrown(() => Question_1_7.Rotate(null), typeof(ArgumentException));
 }