Exemplo n.º 1
0
        public void Draw()
        {
            // Arrange
            var canvasMock = new CanvasMock.Canvas();

            var center      = new Point(0, 0);
            var vertexCount = 3;
            var radius      = 2;


            var regularPolygon = new RegularPolygon(vertexCount, radius, center, ColorType.Blue);

            var expectedDrawedLines = new HashSet <Line>
            {
                new Line {
                    From = new Point(2, 0), To = new Point(-1, 1.732)
                },
                new Line {
                    From = new Point(-1, 1.732), To = new Point(-1, -1.732)
                },
                new Line {
                    From = new Point(-1, -1.732), To = new Point(2, 0)
                }
            };
            var expectedColor = ColorType.Blue;

            // Act
            regularPolygon.Draw(canvasMock);

            // Assert
            Assert.Equal(expectedColor, canvasMock.Color);
            Assert.Equal(expectedDrawedLines, canvasMock.LastDrawedLines);
        }
Exemplo n.º 2
0
        public void Draw_WithRegularPolygon_ShouldWriteDrawingInfo()
        {
            var    center         = new Point(100, 100);
            double radius         = 30;
            int    vertexCount    = 3;
            var    color          = Color.Green;
            var    regularPolygon = new RegularPolygon(center, radius, vertexCount, color);
            var    sw             = new StringWriter();
            var    canvas         = new TestCanvas(sw);

            regularPolygon.Draw(canvas);

            var expectedString = "Green line from (130, 100), to (85, 125,98076211353316)\r\n" +
                                 "Green line from (85, 125,98076211353316), to (84,99999999999999, 74,01923788646684)\r\n" +
                                 "Green line from (84,99999999999999, 74,01923788646684), to (130, 99,99999999999999)\r\n";

            Assert.AreEqual(expectedString, sw.ToString());
        }
Exemplo n.º 3
0
        public void CreateRegularPolygonTest()
        {
            StringWriter   stringWriter   = new StringWriter();
            Canvas         canvas         = new Canvas(stringWriter);
            Point          center         = new Point(1.0, 1.0);
            RegularPolygon regularPolygon = new RegularPolygon(center, 2, 1);

            regularPolygon.Draw(canvas);
            string result =
                "Line\r\n"
                + "From x: 2 y: 1\r\n"
                + "To x: 0 y: 1\r\n"
                + "Line\r\n"
                + "From x: 0 y: 1\r\n"
                + "To x: 2 y: 1\r\n";

            Assert.AreEqual(result, stringWriter.ToString());
            Assert.AreEqual(center, regularPolygon.GetCenter());
            Assert.AreEqual(2, regularPolygon.GetVertexCount());
            Assert.AreEqual(1, regularPolygon.GetRadius());
        }
Exemplo n.º 4
0
        public void CanDrawRegularPolygon()
        {
            var vertexCount = 3;
            var center      = new Point(4, 4);
            var radius      = 3;
            var color       = Color.Red;

            var regularPolygon = new RegularPolygon(vertexCount, center, radius, color);

            TestCanvas canvas = new TestCanvas();

            var angle   = 360f / vertexCount;
            var vertex1 = GetVertexByAngle(angle * 0);

            for (var i = 1; i < vertexCount; ++i)
            {
                var vertex2 = GetVertexByAngle(angle * i);
                canvas.ExpectedData.Add($"{vertex1} {vertex2}");
                vertex1 = vertex2;
            }

            regularPolygon.Draw(canvas);
        }