Esempio n. 1
0
        public void ShouldCreateVerticalLine(int x1, int y1, int x2, int y2)
        {
            int size = 5;

            using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
                ICanvas canvas = container.Scope.Resolve <ICanvas>();
                canvas.Canvas = new char[size, size];

                canvas = container.Module.Execute(new string[] { x1.ToString(), y1.ToString(), x2.ToString(), y2.ToString() });

                char lineMark = canvas.Canvas[y1 - 1, x1 - 1];
                int  yPointer = Math.Min(y1, y2) - 1;
                int  yEnd     = Math.Max(y1, y2) - 1;
                int  xLine    = x1 - 1;
                for (int x = 0; x < size; ++x)
                {
                    for (int y = 0; y < size; ++y)
                    {
                        if (y == yPointer && yPointer <= yEnd && x == xLine)
                        {
                            Assert.True(lineMark == canvas.Canvas[y, x], $"Expected line mark {lineMark} on {x},{y}");
                            yPointer++;
                        }
                        else
                        {
                            Assert.True(lineMark != canvas.Canvas[y, x], $"Unexpected line mark {lineMark} on {x}, {y}");
                        }
                    }
                }
            }
        }
 public void ShouldThrowArgumentExceptionOnInvalidInput(string width, string height)
 {
     using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
         Assert.Throws <ArgumentException>(() =>
         {
             container.Module.Execute(new string[] { width, height });
         });
     }
 }
        public void ShouldCreateArrays(int width, int height)
        {
            using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
                ICanvas canvas = container.Module.Execute(new string[] { width.ToString(), height.ToString() });

                Assert.NotNull(canvas.Canvas);
                Assert.Equal(width, canvas.Canvas.GetLength(1));
                Assert.Equal(height, canvas.Canvas.GetLength(0));
            }
        }
        public void ShouldRecreateArraysWithNewDimension(int oldWidth, int oldHeight, int newWidth, int newHeight)
        {
            using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
                container.Module.Execute(new string[] { oldWidth.ToString(), oldHeight.ToString() });
                ICanvas canvas = container.Module.Execute(new string[] { newWidth.ToString(), newHeight.ToString() });

                Assert.NotNull(canvas.Canvas);
                Assert.Equal(newWidth, canvas.Canvas.GetLength(1));
                Assert.Equal(newHeight, canvas.Canvas.GetLength(0));
            }
        }
Esempio n. 5
0
        public void ShouldThrowArgumentExceptionOnDiagonalLine(int x1, int y1, int x2, int y2)
        {
            int size = 5;

            using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
                ICanvas canvas = container.Scope.Resolve <ICanvas>();
                canvas.Canvas = new char[size, size];

                Assert.Throws <ArgumentException>(() =>
                {
                    container.Module.Execute(new string[] { x1.ToString(), y1.ToString(), x2.ToString(), y2.ToString() });
                });
            }
        }
Esempio n. 6
0
        public void ShouldThrowArgumentExceptionOnInvalidInput(string x1, string y1, string x2, string y2)
        {
            int size = 5;

            using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
                ICanvas canvas = container.Scope.Resolve <ICanvas>();
                canvas.Canvas = new char[size, size];

                Assert.Throws <ArgumentException>(() =>
                {
                    container.Module.Execute(new string[] { x1, y1, x2, y2 });
                });
            }
        }
        public void ShouldFillAllNodesOnEmptyCanvas(int width, int height)
        {
            using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
                ICanvas canvas = container.Scope.Resolve <ICanvas>();
                canvas.Canvas = new char[height, width];

                canvas = container.Module.Execute(new string[] { "1", "1", "c" });

                for (int x = 0; x < width; ++x)
                {
                    for (int y = 0; y < height; ++y)
                    {
                        Assert.True(canvas.Canvas[y, x] != default(char), $"Expected fill mark on {x}, {y}");
                    }
                }
            }
        }
        public void ShouldCreateRectangle(int x1, int y1, int x2, int y2)
        {
            int size = 5;

            using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
                ICanvas canvas = container.Scope.Resolve <ICanvas>();
                canvas.Canvas = new char[size, size];

                canvas = container.Module.Execute(new string[] { x1.ToString(), y1.ToString(), x2.ToString(), y2.ToString() });

                HashSet <(int, int)> rectNodes = GetRectNodes(x1, y1, x2, y2);
                Assert.NotNull(canvas.Canvas);

                for (int x = 0; x < size; ++x)
                {
                    for (int y = 0; y < size; ++y)
                    {
                        if (rectNodes.Contains((x, y)))
                        {
                            Assert.True(canvas.Canvas[y, x] != default(char), $"Expected rectangle mark on {x}, {y}");
                        }
        public void ShouldOnlyFillNodesOnTheSameArea(int bucketX, int bucketY)
        {
            int  width  = 5;
            int  height = 8;
            char color  = 'c';

            using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
                ICanvas canvas = container.Scope.Resolve <ICanvas>();
                canvas.Canvas = new char[height, width];
                canvas        = DrawStraightLine(canvas, 2, 0, 2, 2);
                canvas        = DrawStraightLine(canvas, 0, 3, 1, 3);
                canvas        = DrawStraightLine(canvas, 0, 6, 4, 6);
                HashSet <(int, int)> fillNodes = GetFillNodes(canvas.Canvas, bucketX - 1, bucketY - 1);

                canvas = container.Module.Execute(new string[] { bucketX.ToString(), bucketY.ToString(), color.ToString() });

                for (int x = 0; x < width; ++x)
                {
                    for (int y = 0; y < height; ++y)
                    {
                        if (fillNodes.Contains((x, y)))
                        {
                            Assert.True(canvas.Canvas[y, x] == color, $"Expected fill mark on {x}, {y}");
                        }
Esempio n. 10
0
 public void ParametersIsNotNull()
 {
     using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
         Assert.NotNull(container.Module.Parameters);
     }
 }
Esempio n. 11
0
 public void CommandIsNotNull()
 {
     using (CommandTestContainer container = new CommandTestContainer(ClassToTest)) {
         Assert.NotNull(container.Module.Command);
     }
 }