Ejemplo n.º 1
0
        public void TestMethod1()
        {
            Shape   myRectangle  = new Rectangle("Rectangle1", "FusionBlue", 0, 0, 0, 1, 1, 1, 1, 0);
            Shape   myRectangle2 = new Rectangle("Rectangle2", "FusionGreen", 0, 0, 0, 1, 1, 1, 1, 0);
            Shape   p1           = new Point("Point1", "Red", 1, 2);
            Shape   p2           = new Point("Point2", "Blue", 3, 4);
            Shape2d rect2d       = myRectangle;
            Shape2d rect2d2      = myRectangle2;
            Shape2d p12d         = p1;
            Shape2d p22d         = p2;
            Shape2d Jumble       = new CompositeShape("Jumble", "grey");

            Jumble.Add(rect2d);
            Jumble.Add(p12d);
            Jumble.Add(p22d);
            Jumble.Add(rect2d2);
            List <Shape2d> _myShapes = Jumble.GetMyShapes();

            Assert.AreEqual(_myShapes[0].GetData(), rect2d.GetData());
            Assert.AreEqual(_myShapes[1].GetData(), p12d.GetData());
            Assert.AreEqual(_myShapes[2].GetData(), p22d.GetData());
            Assert.AreEqual(_myShapes[3].GetData(), rect2d2.GetData());
            Assert.AreEqual(_myShapes.Count, 4);
            Assert.AreEqual(Jumble.ComputeArea(), 2 * myRectangle.ComputeArea());

            Jumble.Add(rect2d);
            Assert.AreEqual(Jumble.ComputeArea(), 2 * myRectangle.ComputeArea());

            Jumble.Remove(rect2d);
            Assert.AreEqual(_myShapes.Count, 3);
            Jumble.Remove(rect2d);
            Assert.AreEqual(_myShapes.Count, 3);
            Jumble.Remove(p12d);
            Assert.AreEqual(_myShapes.Count, 2);
            Jumble.Remove(p22d);
            Assert.AreEqual(_myShapes.Count, 1);
            Jumble.Remove(rect2d2);
            Assert.AreEqual(_myShapes.Count, 0);

            Jumble.Add(rect2d);
            //Jumble.Add(rect2d);
            //Jumble.Add(rect2d);
            //Jumble.Add(rect2d);
            //Jumble.Add(rect2d);
            //Jumble.Add(rect2d);
            Jumble.Add(p12d);
            Assert.AreEqual(_myShapes.Count, 2);
            Jumble.Move(1, 1);
            Jumble.RemoveAll();
            Assert.AreEqual(_myShapes.Count, 0);
            Jumble.Add(Jumble);
            Jumble.Add(rect2d);
            Jumble.Add(p12d);
            Assert.AreEqual(Jumble.GetData(), "Rectangle1 FusionBlue 1 1 1 2 2 2 2 1 Point1 Red 2 3 ");
        }
Ejemplo n.º 2
0
        public void AddShapeTwicetest()
        {
            var c       = 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);

            c.Add(rect);
            Assert.That(() => c.Add(rect), Throws.TypeOf <ShapeException>()
                        .With.Message.EqualTo("This shape has already been added to a composite"));
        }
Ejemplo n.º 3
0
        public void AddCompositeToSelf()
        {
            var c = new CompositeShape();

            Assert.That(() => c.Add(c), Throws.TypeOf <ShapeException>()
                        .With.Message.EqualTo("You cant add a shape to itself"));
        }
 public static void TestShape()
 {
     var circle = new Circle();
     var square = new Square();
     var compositeShape = new CompositeShape();
     compositeShape.Add(circle,square);
     Draw(compositeShape);
 }
Ejemplo n.º 5
0
        public static void TestShape()
        {
            var circle         = new Circle();
            var square         = new Square();
            var compositeShape = new CompositeShape();

            compositeShape.Add(circle, square);
            Draw(compositeShape);
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
 public GroupShapeCommand(Canvas InputCanvas, List <Shape> ListShape)
 {
     ActiveCanvas = InputCanvas;
     AllShape     = new List <Shape>();
     GroupShape   = new CompositeShape();
     foreach (Shape SelectedShape in ListShape)
     {
         AllShape.Add(SelectedShape);
         GroupShape.Add(SelectedShape);
     }
 }
Ejemplo n.º 8
0
        public void ScaleTest()
        {
            var c       = new CompositeShape();
            var rpoint1 = new Point(1, 1);
            var rpoint2 = new Point(2, 1);
            var rpoint3 = new Point(2, 2);
            var rpoint4 = new Point(1, 2);
            var rect    = new Rectangle(rpoint1, rpoint2, rpoint3, rpoint4);

            c.Add(rect);
            var tpoint1  = new Point(0, 0);
            var tpoint2  = new Point(1, 0);
            var tpoint3  = new Point(0, 1);
            var triangle = new Triangle(tpoint1, tpoint2, tpoint3);

            c.Add(triangle);
            var area = c.ComputeArea() * 2;

            c.Scale(2);
            Assert.Less(Math.Abs(c.ComputeArea() - area), .000000000000001);
        }
Ejemplo n.º 9
0
        public void RemoveAllShapes()
        {
            var c       = 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);

            c.Add(rect);
            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);

            c.Add(triangle);

            c.RemoveAllShapes();
            Assert.AreEqual(0, c.Points.Count);
            Assert.AreEqual(0, c.thisShapesList.Count);
        }
Ejemplo n.º 10
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());
        }