Ejemplo n.º 1
0
 public void ShouldThrowExceptionWhenParameterIsNotAPositiveInteger()
 {
     Assert.That(() => {
         var command = new CanvasDrawingCommand();
         command.Draw("-2", "-9");
     }, Throws.InstanceOf <ArgumentException>());
 }
Ejemplo n.º 2
0
 public void ShouldThrowExceptionWhenParameterIsNotANumber()
 {
     Assert.That(() => {
         var command = new CanvasDrawingCommand();
         command.Draw("xxx", "yyy");
     }, Throws.InstanceOf <ArgumentException>());
 }
        public void ShouldDrawRectangle()
        {
            var canvasDrawingCommand = new CanvasDrawingCommand();

            canvasDrawingCommand.Draw("20", "4");
            var canvas = canvasDrawingCommand.Canvas;

            var rectangleDrawingCommand = new RectangleDrawingCommand(canvas);

            rectangleDrawingCommand.Draw("14", "1", "18", "3");

            var elements = canvas.Elements;

            for (var i = 14; i <= 18; i++)
            {
                Assert.AreEqual("x", elements[i, 1].Value);
                Assert.AreEqual("x", elements[i, 3].Value);
            }

            for (var i = 1; i <= 3; i++)
            {
                Assert.AreEqual("x", elements[14, i].Value);
                Assert.AreEqual("x", elements[18, i].Value);
            }
        }
Ejemplo n.º 4
0
        public void ShouldCreateCanvas()
        {
            var command = new CanvasDrawingCommand();

            command.Draw("20", "4");

            Assert.NotNull(command.Canvas);
        }
Ejemplo n.º 5
0
        public void ShouldCreateCanvasWithWidthAndHeight()
        {
            var command = new CanvasDrawingCommand();

            command.Draw("20", "4");
            var canvas = command.Canvas;

            Assert.IsNotNull(canvas.Elements);
            Assert.AreEqual(21, canvas.Elements.GetUpperBound(0));
            Assert.AreEqual(5, canvas.Elements.GetUpperBound(1));
        }
        public void CanNotDrawLineOutOfCanvas()
        {
            var canvasDrawingCommand = new CanvasDrawingCommand();

            canvasDrawingCommand.Draw("20", "4");
            var canvas = canvasDrawingCommand.Canvas;

            Assert.That(() => {
                var lineDrawingCommand = new LineDrawingCommand(canvas);
                lineDrawingCommand.Draw("1", "5", "6", "5");
            }, Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
        public void ShouldDrawLineInCanvas()
        {
            var canvasDrawingCommand = new CanvasDrawingCommand();

            canvasDrawingCommand.Draw("20", "4");
            var canvas = canvasDrawingCommand.Canvas;

            var lineDrawingCommand = new LineDrawingCommand(canvas);

            lineDrawingCommand.Draw("1", "2", "6", "2");

            var elements = canvas.Elements;

            for (int i = 1; i <= 6; i++)
            {
                Assert.AreEqual("x", elements[i, 2].Value);
            }
        }
Ejemplo n.º 8
0
        public void ShouldFillArea()
        {
            var canvasDrawingCommand = new CanvasDrawingCommand();

            canvasDrawingCommand.Draw("20", "4");
            var canvas = canvasDrawingCommand.Canvas;

            var lineDrawingCommand = new LineDrawingCommand(canvas);

            lineDrawingCommand.Draw("1", "2", "6", "2");
            lineDrawingCommand.Draw("6", "3", "6", "4");

            var rectangleDrawingCommand = new RectangleDrawingCommand(canvas);

            rectangleDrawingCommand.Draw("14", "1", "18", "3");

            var bucketFillDrawingCommand = new BucketFillDrawingCommand(canvas);

            bucketFillDrawingCommand.Draw("10", "3", "o");

            var elements    = canvas.Elements;
            var filledCount = 0;
            var emptyCount  = 0;

            for (var x = 0; x < elements.GetUpperBound(0); x++)
            {
                for (var y = 0; y < elements.GetUpperBound(1); y++)
                {
                    if (elements[x, y] == null)
                    {
                        emptyCount++;
                    }
                    else if (elements[x, y].Value.Equals("o"))
                    {
                        filledCount++;
                    }
                }
            }

            Assert.AreEqual(13, emptyCount);
            Assert.AreEqual(47, filledCount);
        }
Ejemplo n.º 9
0
        public void ShouldCreateCanvasWithBoundaryElementsCreated()
        {
            var command = new CanvasDrawingCommand();

            command.Draw("20", "4");
            var canvas = command.Canvas;
            var points = canvas.Elements;

            for (int x = 0; x < 22; x++)
            {
                Assert.AreEqual("-", points[x, 0].Value);
                Assert.AreEqual("-", points[x, 5].Value);
            }

            for (int y = 1; y < 5; y++)
            {
                Assert.AreEqual("|", points[0, y].Value);
                Assert.AreEqual("|", points[21, y].Value);
            }
        }