Exemplo n.º 1
0
        public void TestFindTotalPerimeterInBox(double radius, double newRadius, int index)
        {
            Box    box          = new Box();
            Circle firstCircle  = new MembraneCircle(radius);
            Circle secondCircle = new PaperCircle(newRadius);

            Assert.AreEqual(0, box.GetTotalPerimeter());
            box.AddShape(firstCircle);
            box.AddShape(secondCircle);
            Assert.AreEqual(firstCircle.GetPerimeter() + secondCircle.GetPerimeter(), box.GetTotalPerimeter());
        }
Exemplo n.º 2
0
        public void TestAddTwoSameShapesToBox(double radius, int expectedCount)
        {
            Box    box          = new Box();
            Circle firstCircle  = new MembraneCircle(radius);
            Circle secondCircle = new MembraneCircle(radius);

            //Box contains only unique shapes
            box.AddShape(firstCircle);
            box.AddShape(secondCircle);


            Assert.AreEqual(box.Count(), expectedCount);
            Assert.AreEqual(firstCircle, box.FindAt(0));
            Assert.AreEqual(firstCircle, box.Find(firstCircle));
        }
Exemplo n.º 3
0
        public static void PutIntoContainer(Box container, Shape shape)
        {
            string statusMsg;


            if (container.AddAvailable(shape))
            {
                container.emptyVolume -= shape.Volume;
                container.AddShape(shape);

                statusMsg = $"SUCCESSFULLY ADDED: [{shape.Name}] with volume [{shape.Volume}] into the Container.";
            }
            else
            {
                statusMsg = $"NOT ENOUGH SPACE: [{shape.Name}] with volume [{shape.Volume}].";
            }

            string freeContainerSpaceMsg = $"Free Container space: [{container.emptyVolume.ToString()}].";
            string usedContainerSpaceMsg = $"Used Container space: [{(container.Volume - container.emptyVolume).ToString()}]";
            string shapesInsideMsg       = $"Shapes inside: {{{string.Join(',', container.Shapes.Select(s => s.Name).ToList())}}}";

            Console.WriteLine(statusMsg);
            Console.WriteLine(freeContainerSpaceMsg);
            Console.WriteLine(usedContainerSpaceMsg);
            Console.WriteLine(shapesInsideMsg);
        }
Exemplo n.º 4
0
        public void TestStreamIoInBox(double radius, double side, Color color, string fileName)
        {
            List <IShape> shapes = new List <IShape> {
                new PaperCircle(radius), new MembraneSquare(side)
            };

            (shapes[0] as IPaper).Paint(color);
            Box box = new Box();

            shapes.ForEach(e => box.AddShape(e));

            box.SaveAllShapesStreamWriter(fileName);

            Assert.IsTrue(File.Exists(fileName));

            box.ReadShapesStreamReader(fileName);

            File.Delete(fileName);

            Assert.AreEqual(shapes.Count, box.Count());

            Assert.IsTrue(shapes.SequenceEqual(new List <IShape>()
            {
                box.FindAt(0), box.FindAt(1)
            }));
        }
Exemplo n.º 5
0
        public void TestPopAtInvalidDatainBox(double radius, int index)
        {
            Box    box         = new Box();
            Circle firstCircle = new MembraneCircle(radius);

            box.AddShape(firstCircle);

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => box.PopAt(index));
        }
Exemplo n.º 6
0
        public void Container_ShapeAdded_ContainsShape()
        {
            Box container = new Box(10);
            Box box       = new Box(5);

            container.AddShape(box);

            Assert.Contains <Shape>(box, container.Shapes);
        }
Exemplo n.º 7
0
        public void TestGetAllMembraneFromBox(double radius, double newRadius, double side, int numberOfMembrane)
        {
            Box            box          = new Box();
            MembraneCircle firstCircle  = new MembraneCircle(radius);
            PaperCircle    secondCircle = new PaperCircle(newRadius);
            MembraneSquare square       = new MembraneSquare(side);

            Assert.AreEqual(0, box.GetAllMembrane().Count);

            box.AddShape(firstCircle);
            box.AddShape(secondCircle);
            box.AddShape(square);

            Assert.IsTrue(new List <IMembrane>()
            {
                firstCircle, square
            }.SequenceEqual(box.GetAllMembrane()));
            Assert.AreEqual(numberOfMembrane, box.GetAllCircles().Count);
        }
Exemplo n.º 8
0
        public void TestAddShapeToBox(double radius)
        {
            Box    box    = new Box();
            Circle circle = new MembraneCircle(radius);

            box.AddShape(circle);

            Assert.AreEqual(circle, box.FindAt(0));
            Assert.AreEqual(circle, box.Find(circle));
        }
Exemplo n.º 9
0
        public void TestReaplaceAtInvalidDatatinBox(double radius, double newRadius, int index)
        {
            Box    box         = new Box();
            Circle firstCircle = new MembraneCircle(radius);

            box.AddShape(firstCircle);
            Circle secondCircle = new PaperCircle(newRadius);

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => box.ReplaceAt(index, secondCircle));
        }
Exemplo n.º 10
0
        public void TestPopAtinBox(double radius, int index)
        {
            Box    box         = new Box();
            Circle firstCircle = new MembraneCircle(radius);

            box.AddShape(firstCircle);

            Assert.AreEqual(firstCircle, box.FindAt(index));

            IShape popedShape = box.PopAt(index);

            Assert.AreEqual(0, box.Count());
            Assert.AreEqual(popedShape, firstCircle);
        }
Exemplo n.º 11
0
        public void TestReaplaceAtinBox(double radius, double newRadius, int index)
        {
            Box    box         = new Box();
            Circle firstCircle = new MembraneCircle(radius);

            box.AddShape(firstCircle);
            Circle secondCircle = new PaperCircle(newRadius);

            box.ReplaceAt(index, secondCircle);

            Assert.AreEqual(secondCircle, box.FindAt(index));

            Assert.ThrowsException <ArgumentNullException>(() => box.ReplaceAt(index, null));
        }
Exemplo n.º 12
0
        public void TestStreamWritetOnlyMembraneInBox(double radius, double side, Color color, string fileName)
        {
            List <IShape> shapes = new List <IShape> {
                new PaperCircle(radius), new MembraneSquare(side)
            };

            (shapes[0] as IPaper).Paint(color);
            Box box = new Box();

            shapes.ForEach(e => box.AddShape(e));

            box.SaveMembraneShapesStreamWriter(fileName);

            Assert.IsTrue(File.Exists(fileName));

            box.ReadShapesXmlReader(fileName);

            File.Delete(fileName);

            Assert.AreEqual(shapes.Where(e => e is IMembrane).Count(), box.Count());

            Assert.IsTrue(shapes.Where(e => e is IMembrane).SequenceEqual(box.GetAllShapes()));
        }
Exemplo n.º 13
0
        public void TestAddNullToBox()
        {
            Box box = new Box();

            Assert.ThrowsException <ArgumentNullException>(() => box.AddShape(null));
        }