Пример #1
0
        public void Add_NoThrow_ForCorrectPolygons(params Point[] points)
        {
            var builder = new SimplePolygonBuilder();

            foreach (var p in points)
            {
                builder.Add(p);
            }
        }
Пример #2
0
        public void Close_NoThrow_ForValidPolygons(params Point[] points)
        {
            var builder = new SimplePolygonBuilder();

            foreach (var p in points)
            {
                builder.Add(p);
            }

            builder.Close();
        }
Пример #3
0
        public void Close_ThrowInvalidOperationException_ForIntersectingPolygons(params Point[] points)
        {
            var builder = new SimplePolygonBuilder();

            foreach (var p in points)
            {
                builder.Add(p);
            }

            Assert.Throws <InvalidOperationException>(() => builder.Close());
        }
Пример #4
0
        public void Area_IsSameAsForTriangleWithGivenSides()
        {
            var triangle = new Triangle(3, 4, 5);
            var expected = triangle.Area();

            var polygon = new SimplePolygonBuilder()
                          .Add(new Point(0, 0))
                          .Add(new Point(4, 0))
                          .Add(new Point(0, 3))
                          .Close();
            var actual = polygon.Area();

            Assert.Equal(expected, actual);
        }
Пример #5
0
        public void Area_IsSameForRectangleWithGivenSides()
        {
            var expected = 4 * 3; // Rectangle with sides 4 and 3

            var polygon = new SimplePolygonBuilder()
                          .Add(new Point(0, 0))
                          .Add(new Point(4, 0))
                          .Add(new Point(4, 3))
                          .Add(new Point(0, 3))
                          .Close();
            var actual = polygon.Area();

            Assert.Equal(expected, actual);
        }
Пример #6
0
        public void Area_CorrectForNonTrivialShape()
        {
            // Consider rectangle with sliced out right triangle inside.
            // Rectangle with sides 7 and 6, triangle with catheti
            // 3 and 4. Meaning, area is equal 7 * 6 - 3 * 4 / 2
            var expected = 7 * 6 - new Triangle(3, 4, 5).Area();

            var polygon = new SimplePolygonBuilder()
                          .Add(x: 0, y: 0)
                          .Add(x: 3, y: 0)
                          .Add(x: 7, y: 3)
                          .Add(x: 7, y: 6)
                          .Add(x: 0, y: 6)
                          .Close();
            var actual = polygon.Area();

            Assert.Equal(expected, actual);
        }