public void TestFindNullinBox(double radius) { Box box = new Box(); Circle firstCircle = new MembraneCircle(radius); Assert.ThrowsException <ArgumentNullException>(() => box.Find(null)); }
public void TestFindElementDontPresentinBox(double radius, double newRadius) { Box box = new Box(); Circle firstCircle = new MembraneCircle(radius); Assert.IsNull(box.Find(new PaperCircle(newRadius))); }
public void TestFindAtInBox(double radius, int index) { Box box = new Box(); Circle firstCircle = new MembraneCircle(radius); Assert.ThrowsException <ArgumentOutOfRangeException>(() => box.FindAt(index)); }
/// <summary> /// Reads the file. /// </summary> /// <param name="file">The file.</param> /// <returns>List of shapes.</returns> public List <IShape> ReadFile(string file) { List <IShape> shapes = new List <IShape>(); using (XmlReader reader = XmlReader.Create(file)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name.Equals("circle")) { Circle circle; if (reader.GetAttribute("material").Equals("paper")) { circle = new PaperCircle( double.Parse(reader.GetAttribute("radius")), (Color)Enum.Parse(typeof(Color), reader.GetAttribute("color"))); } else { circle = new MembraneCircle(double.Parse(reader.GetAttribute("radius"))); } shapes.Add(circle); } if (reader.Name.Equals("square")) { Square square; if (reader.GetAttribute("material").Equals("paper")) { square = new PaperSquare(double.Parse(reader.GetAttribute("side")), (Color)Enum.Parse(typeof(Color), reader.GetAttribute("color"))); } else { square = new MembraneSquare(double.Parse(reader.GetAttribute("side"))); } shapes.Add(square); } if (reader.Name.Equals("rectangle")) { Rectangle rectangle; if (reader.GetAttribute("material").Equals("paper")) { rectangle = new PaperRectangle(double.Parse(reader.GetAttribute("firstSide")), double.Parse(reader.GetAttribute("secondSide")), (Color)Enum.Parse(typeof(Color), reader.GetAttribute("color"))); } else { rectangle = new MembraneRectangle( double.Parse(reader.GetAttribute("firstSide")), double.Parse(reader.GetAttribute("secondSide"))); } shapes.Add(rectangle); } } } } return(shapes); }
public void CreatingCircleMustReturnObject(double radius) { Circle paperCircle = new PaperCircle(radius); Circle membraneCircle = new MembraneCircle(radius); Assert.IsNotNull(paperCircle); Assert.IsNotNull(membraneCircle); }
public void TestGetPerimeterOfCircle(double radius, double expectedArea) { Circle paperCircle = new PaperCircle(radius); Circle membraneCircle = new MembraneCircle(radius); Assert.AreEqual(expectedArea, paperCircle.GetPerimeter()); Assert.AreEqual(expectedArea, membraneCircle.GetPerimeter()); }
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 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 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 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 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 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 TestCutShapeFromAnotherShape(double smallerRadius, double biggerRadius, double smallerSide, double biggerSide, double smallerFirstSide, double smallerSecondSide, double biggerFirstSide, double biggerSecondSide) { //Cutting shape from another shape is available only in case when area of source shape bigger then area target shape //Cutting shape from another shape also is available only for equals materials Circle bigCircle = new MembraneCircle(biggerRadius); Circle smallCircle = new MembraneCircle(smallerRadius, bigCircle); Square bigSquare = new MembraneSquare(biggerSide); Square smallSquare = new MembraneSquare(smallerSide, bigSquare); Rectangle bigRectangle = new MembraneRectangle(biggerFirstSide, biggerSecondSide); Rectangle smallRectangle = new MembraneRectangle(smallerFirstSide, smallerSecondSide, bigRectangle); Circle circleFromRectangle = new MembraneCircle(smallerRadius, bigRectangle); Square squareFromRectangle = new MembraneSquare(smallerSide, bigRectangle); Assert.IsNotNull(smallCircle); Assert.IsNotNull(smallSquare); Assert.IsNotNull(smallRectangle); Assert.IsNotNull(circleFromRectangle); Assert.IsNotNull(squareFromRectangle); }
/// <summary> /// Reads the file. /// </summary> /// <param name="file">The file.</param> /// <returns>List of shapes.</returns> public List <IShape> ReadFile(string file) { List <IShape> shapes = new List <IShape>(); using (StreamReader streamReader = new StreamReader(file)) { XmlDocument document = new XmlDocument(); document.Load(streamReader); XmlNode root = document.SelectSingleNode("/shapes"); XmlNodeList nodeList = root.SelectNodes("*"); foreach (XmlNode node in nodeList) { if (node.Name.Equals("circle")) { Circle circle; if (node.Attributes.GetNamedItem("material").Value.Equals("paper")) { circle = new PaperCircle( double.Parse(node.Attributes.GetNamedItem("radius").Value), (Color)Enum.Parse(typeof(Color), node.Attributes.GetNamedItem("color").Value)); } else { circle = new MembraneCircle(double.Parse(node.Attributes.GetNamedItem("radius").Value)); } shapes.Add(circle); } if (node.Name.Equals("square")) { Square square; if (node.Attributes.GetNamedItem("material").Value.Equals("paper")) { square = new PaperSquare( double.Parse(node.Attributes.GetNamedItem("side").Value), (Color)Enum.Parse(typeof(Color), node.Attributes.GetNamedItem("color").Value)); } else { square = new MembraneSquare(double.Parse(node.Attributes.GetNamedItem("side").Value)); } shapes.Add(square); } if (node.Name.Equals("rectangle")) { Rectangle rectangle; if (node.Attributes.GetNamedItem("material").Value.Equals("paper")) { rectangle = new PaperRectangle( double.Parse(node.Attributes.GetNamedItem("firstSide").Value), double.Parse(node.Attributes.GetNamedItem("secondSide").Value), (Color)Enum.Parse(typeof(Color), node.Attributes.GetNamedItem("color").Value)); } else { rectangle = new MembraneRectangle( double.Parse(node.Attributes.GetNamedItem("firstSide").Value), double.Parse(node.Attributes.GetNamedItem("secondSide").Value)); } shapes.Add(rectangle); } } } return(shapes); }