Beispiel #1
0
        public void ComputeAreaTest()
        {
            var point1 = new Point(0, 0);
            var point2 = new Point(3, 0);
            var point3 = new Point(0, 3);
            var area   = 9 * .5;

            var triangle = new Triangle(point1, point2, point3);

            Assert.LessOrEqual(Math.Abs(triangle.ComputeArea() - area), 3.0E-15d);
        }
        public void CompositeShape()
        {
            var points    = new List <Point>();
            var composite = new CompositeShape();
            var rpoint1   = new Point(20, 20);
            var rpoint2   = new Point(30, 20);
            var rpoint3   = new Point(30, 30);
            var rpoint4   = new Point(20, 30);

            var rect = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(3, 0);
            var tpoint3  = new Point(0, 3);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            points.Add(rpoint1);
            points.Add(rpoint2);
            points.Add(rpoint3);
            points.Add(rpoint4);
            points.Add(tpoint1);
            points.Add(tpoint2);
            points.Add(tpoint3);

            var area = rect.ComputeArea() + triangle.ComputeArea();

            composite.Add(rect);
            composite.Add(triangle);

            Assert.AreEqual(area, composite.ComputeArea());
            Assert.AreEqual(Color.Empty, composite.Fill);
            Assert.AreEqual(Color.Black, composite.Stroke);
            composite.Fill = Color.Aqua;
            Assert.AreEqual(Color.Aqua, composite.Fill);



            foreach (var point in composite.Points)
            {
                Assert.Contains(point, points);
            }
        }
        public void RemoveShapeTest()
        {
            var points    = new List <Point>();
            var composite = new CompositeShape();
            var rpoint1   = new Point(20, 20);
            var rpoint2   = new Point(30, 20);
            var rpoint3   = new Point(30, 30);
            var rpoint4   = new Point(20, 30);

            var rect = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(3, 0);
            var tpoint3  = new Point(0, 3);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            points.Add(rpoint1);
            points.Add(rpoint2);
            points.Add(rpoint3);
            points.Add(rpoint4);


            var area = rect.ComputeArea() + triangle.ComputeArea();

            composite.Add(rect);
            composite.Add(triangle);

            Assert.AreEqual(area, composite.ComputeArea());

            composite.RemoveShape(triangle);

            foreach (var point in composite.Points)
            {
                Assert.Contains(point, points);
            }
            Assert.AreEqual(rect.ComputeArea(), composite.ComputeArea());
        }