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()); }
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)); }
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); }
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) })); }
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)); }
public void Container_ShapeAdded_ContainsShape() { Box container = new Box(10); Box box = new Box(5); container.AddShape(box); Assert.Contains <Shape>(box, container.Shapes); }
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); }
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)); }
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)); }
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); }
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)); }
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())); }
public void TestAddNullToBox() { Box box = new Box(); Assert.ThrowsException <ArgumentNullException>(() => box.AddShape(null)); }