Ejemplo n.º 1
0
        public void Question_8_10_BasicCases()
        {
            // Fill with same color
            var image         = new int[10, 10];
            var expectedImage = (int[, ])image.Clone();
            var point         = new Point(5, 5);
            var color         = image[point.Row, point.Column];

            Question_8_10.ColorFill(point, image, color);
            TestHelpers.AssertMatricesEqual(expectedImage, image);

            image         = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1);
            expectedImage = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2);
            point         = new Point(1, 1);
            Question_8_10.ColorFill(point, image, 2);
            TestHelpers.AssertMatricesEqual(expectedImage, image);

            image         = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1);
            expectedImage = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2);
            point         = new Point(0, 0);
            Question_8_10.ColorFill(point, image, 2);
            TestHelpers.AssertMatricesEqual(expectedImage, image);

            image         = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 1, 1, 2, 2, 2, 3, 4, 5);
            expectedImage = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 1, 1, 6, 6, 6, 3, 4, 5);
            point         = new Point(1, 1);
            Question_8_10.ColorFill(point, image, 6);
            TestHelpers.AssertMatricesEqual(expectedImage, image);

            image         = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 1, 1, 2, 2, 2, 3, 4, 5);
            expectedImage = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 1, 1, 2, 2, 2, 3, 6, 5);
            point         = new Point(2, 1);
            Question_8_10.ColorFill(point, image, 6);
            TestHelpers.AssertMatricesEqual(expectedImage, image);
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
0
        private void ValidateResult(int[,] expected, int[,] input)
        {
            var inputCopy = MatrixHelpers.CreateTwoDimensionalMatrix(input.GetLength(0), input.GetLength(1), input.Cast <int>().ToArray());

            Question_1_8.PropogateZeros(input);
            TestHelpers.AssertMatricesEqual(expected, input);
            Question_1_8.PropogateZerosInPlace(inputCopy);
            TestHelpers.AssertMatricesEqual(expected, inputCopy);
        }
Ejemplo n.º 4
0
        public void Question_1_8_EdgeCases()
        {
            // Zero in the middle
            // 0
            var matrix   = MatrixHelpers.CreateTwoDimensionalMatrix(1, 1, 0);
            var expected = MatrixHelpers.CreateTwoDimensionalMatrix(1, 1, 0);

            this.ValidateResult(expected, matrix);
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 6
0
        public void Question_1_8_Basic()
        {
            // Zero in the middle.
            // 1 1 1
            // 1 0 1
            // 1 1 1
            var matrix   = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 1, 1, 1, 0, 1, 1, 1, 1);
            var expected = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 0, 1, 0, 0, 0, 1, 0, 1);

            this.ValidateResult(expected, matrix);

            // No zeros.
            // 1 1 1
            // 1 1 1
            // 1 1 1
            var matrix2   = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1);
            var expected2 = MatrixHelpers.CreateTwoDimensionalMatrix(3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1);

            this.ValidateResult(expected2, matrix2);

            // Zero on edge.
            // 0 1 1 1
            // 1 1 1 1
            // 1 1 1 1
            var matrix3   = MatrixHelpers.CreateTwoDimensionalMatrix(3, 4, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
            var expected3 = MatrixHelpers.CreateTwoDimensionalMatrix(3, 4, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1);

            this.ValidateResult(expected3, matrix3);

            // Zero everything
            // 0 1
            // 0 1
            var matrix4   = MatrixHelpers.CreateTwoDimensionalMatrix(2, 2, 0, 1, 0, 1);
            var expected4 = MatrixHelpers.CreateTwoDimensionalMatrix(2, 2, 0, 0, 0, 0);

            this.ValidateResult(expected4, matrix4);
        }