Пример #1
0
        public void RemoveShapeNotInComposite()
        {
            var composite = new CompositeShape();
            var circle    = new Circle(20, 20, 5);

            Assert.That(() => composite.RemoveShape(circle), Throws.TypeOf <ShapeException>()
                        .With.Message.EqualTo($"{typeof(Circle).Name} is not part of the composite shape."));
        }
Пример #2
0
        public void TestRemoveShape()
        {
            ShapeFactory sf = new ShapeFactory();

            CompositeShape compositeShape = sf.MakeCompositeShape(1, 1);
            Circle         testCircle     = sf.MakeCircle(3, 2, 2);

            compositeShape.AddShape(testCircle);
            Assert.AreEqual(1, compositeShape.GetShapes().Count);
            compositeShape.RemoveShape(0);
            Assert.AreEqual(0, compositeShape.GetShapes().Count);
        }
Пример #3
0
        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());
        }