示例#1
0
        public void TestFillCompleteCanvasWhenEmptyAndColorChanged(string Command)
        {
            bucketFillCommandHandler.ProcessCommand(Command);
            var filledCanvasString = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', 'M', 'M', 'M', '|' }, { '|', 'M', 'M', 'M', '|' }, { '|', 'M', 'M', 'M', '|' }, { '|', 'M', 'M', 'M', '|' }, { '-', '-', '-', '-', '-' },
            });

            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString + filledCanvasString);
        }
        public void TestLineAndCrossingRectangleCommand(string lineCommand, string rectangleCommand)
        {
            lineCommandHandler.ProcessCommand(lineCommand);
            var lineOnCanvasString = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', ' ', ' ', 'x', '|' }, { '|', ' ', ' ', 'x', '|' }, { '|', ' ', ' ', 'x', '|' }, { '|', ' ', ' ', 'x', '|' }, { '-', '-', '-', '-', '-' },
            });

            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString + lineOnCanvasString);
            Assert.Throws <Exception>(() => rectangleCommandHandler.ProcessCommand(rectangleCommand));
        }
示例#3
0
        public void TestWhenPointIsOnExistingRectangle(string rectangleCommand, string fillCommand)
        {
            var rectCommandHandler = new DrawRectangleCommandHandler();

            rectCommandHandler.ProcessCommand(rectangleCommand);
            var canvasStringWithRectangle = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', 'x', 'x', 'x', '|' }, { '|', 'x', ' ', 'x', '|' }, { '|', 'x', 'x', 'x', '|' }, { '|', ' ', ' ', ' ', '|' }, { '-', '-', '-', '-', '-' },
            });

            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString + canvasStringWithRectangle);
            Assert.Throws <Exception>(() => bucketFillCommandHandler.ProcessCommand(fillCommand));
        }
 public void TestNByMDimentionsInput()
 {
     using (StringWriter sw = new StringWriter())
     {
         Console.SetOut(sw);
         createCanvasCommandHandler.ProcessCommand("C 3 2");
         var outputMatrixString = MatrixToStringConverter.Convert(new char[4, 5] {
             { '-', '-', '-', '-', '-' }, { '|', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', '|' }, { '-', '-', '-', '-', '-' },
         });
         NUnit.Framework.Assert.AreEqual(outputMatrixString, sw.ToString());
     }
 }
        public void DrawRectangleCommandHandlerTestSetUp()
        {
            originalOut  = Console.Out;
            stringWriter = new StringWriter();
            Console.SetOut(stringWriter);
            var createCanvas = new CreateCanvasCommandHandler();

            createCanvas.ProcessCommand("C 3 4");
            rectangleCommandHandler = new DrawRectangleCommandHandler();
            emptyCanvasString       = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', '|' }, { '-', '-', '-', '-', '-' },
            });
        }
示例#6
0
        public void FillConnectedAreaCommandHandlerTestSetUp()
        {
            originalOut  = Console.Out;
            stringWriter = new StringWriter();
            Console.SetOut(stringWriter);
            var createCanvas = new CreateCanvasCommandHandler();

            createCanvas.ProcessCommand("C 3 4");
            bucketFillCommandHandler = new FillConnectedAreaCommandHandler();
            emptyCanvasString        = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', '|' }, { '-', '-', '-', '-', '-' }
            });
        }
示例#7
0
        public void TestDrawHorizontalLinesCommand(string command)
        {
            Assert.NotNull(stringWriter.ToString());
            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString);
            lineHandler.ProcessCommand(command);
            Assert.AreEqual(stringWriter.ToString().Count(c => c.Equals('x')), 3);

            var lineContainingCanvas = MatrixToStringConverter.Convert(new char[4, 5] {
                { '-', '-', '-', '-', '-' }, { '|', ' ', ' ', ' ', '|' }, { '|', 'x', 'x', 'x', '|' }, { '-', '-', '-', '-', '-' },
            });

            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString + lineContainingCanvas);
        }
        public void TestDrawValidRectangleCommand(string command)
        {
            Assert.NotNull(stringWriter.ToString());
            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString);

            rectangleCommandHandler.ProcessCommand(command);
            Assert.AreEqual(stringWriter.ToString().Count(c => c.Equals('x')), 8);

            var canvasStringWithRectangle = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', 'x', 'x', 'x', '|' }, { '|', 'x', ' ', 'x', '|' }, { '|', 'x', 'x', 'x', '|' }, { '|', ' ', ' ', ' ', '|' }, { '-', '-', '-', '-', '-' },
            });

            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString + canvasStringWithRectangle);
        }
        public void TestValidLineAndRectangleCommand(string lineCommand, string rectangleCommand)
        {
            lineCommandHandler.ProcessCommand(lineCommand);
            var lineOnCanvasString = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', ' ', ' ', 'x', '|' }, { '|', ' ', ' ', 'x', '|' }, { '|', ' ', ' ', 'x', '|' }, { '|', ' ', ' ', 'x', '|' }, { '-', '-', '-', '-', '-' },
            });

            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString + lineOnCanvasString);

            rectangleCommandHandler.ProcessCommand(rectangleCommand);
            var lineAndRectangleOnCanvasString = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', 'x', 'x', 'x', '|' }, { '|', 'x', 'x', 'x', '|' }, { '|', ' ', ' ', 'x', '|' }, { '|', ' ', ' ', 'x', '|' }, { '-', '-', '-', '-', '-' },
            });

            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString + lineOnCanvasString + lineAndRectangleOnCanvasString);
        }
 public void TestOneByOneDimentionsInput(string input)
 {
     using (StringWriter sw = new StringWriter())
     {
         //   var originalOutput = Console.Out;
         Console.SetOut(sw);
         createCanvasCommandHandler.ProcessCommand(input);
         var outputMatrixString = MatrixToStringConverter.Convert(new char[3, 3] {
             { '-', '-', '-' }, { '|', ' ', '|' }, { '-', '-', '-' }
         });
         NUnit.Framework.Assert.AreEqual(outputMatrixString, sw.ToString());
         //    Console.SetOut(originalOutput);
         //    Console.WriteLine("Expected Output Matrix"+"/r/n" + outputMatrixString.ToString());
         //   Console.WriteLine("Original output was" + "/r/n"+ sw.ToString());
     }
 }
        public void TestDrawRectangleAndBucketFillCommand(string rectangleCommand, string fillCommand)
        {
            Assert.NotNull(stringWriter.ToString());
            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString);

            rectangleCommandHandler.ProcessCommand(rectangleCommand);
            Assert.AreEqual(stringWriter.ToString().Count(c => c.Equals('x')), 10);
            var canvasStringWithRectangle = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', 'x', 'x', 'x', '|' }, { '|', 'x', ' ', 'x', '|' }, { '|', 'x', ' ', 'x', '|' }, { '|', 'x', 'x', 'x', '|' }, { '-', '-', '-', '-', '-' },
            });

            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString + canvasStringWithRectangle);

            bucketFillCommandHandler.ProcessCommand(fillCommand);
            var canvasStringWithRectangleAndBucketFilled = MatrixToStringConverter.Convert(new char[6, 5] {
                { '-', '-', '-', '-', '-' }, { '|', 'x', 'x', 'x', '|' }, { '|', 'x', 'p', 'x', '|' }, { '|', 'x', 'p', 'x', '|' }, { '|', 'x', 'x', 'x', '|' }, { '-', '-', '-', '-', '-' },
            });

            Assert.AreEqual(stringWriter.ToString(), emptyCanvasString + canvasStringWithRectangle + canvasStringWithRectangleAndBucketFilled);
        }