public void CheckRectangle(float width, float height, float expectArea, float expectPerim) { Rectangle rectangle = new RectangleFilm(width, height); Assert.AreEqual(expectArea, rectangle.GetArea(), 0.0001f); Assert.AreEqual(expectPerim, rectangle.GetPerimeter(), 0.0001f); }
public void CheckCuttingFilmFigures(int index) { Figure figure = figuresBox.ShowFigure(index); Figure miniRect = new RectangleFilm(figure, 1, 1); Assert.IsNotNull(miniRect); }
/// <summary> /// Сreating a specific figure /// </summary> /// <param name="material"> Material type</param> /// <param name="values"> Figure's data</param> /// <returns></returns> public IFigure CreateFigure(Material material, params double[] values) { IFigure figure = null; switch (material) { case Material.Paper: switch (values.Length) { case 1: figure = new CirclePaper(values[0]); break; case 2: figure = new RectanglePaper(values[0], values[1]); break; case 3: figure = new TrianglePaper(values[0], values[1], values[2]); break; default: throw new InvalidParametersException(); } break; case Material.Film: switch (values.Length) { case 1: figure = new CircleFilm(values[0]); break; case 2: figure = new RectangleFilm(values[0], values[1]); break; case 3: figure = new TriangleFilm(values[0], values[1], values[2]); break; default: throw new InvalidParametersException(); } break; default: throw new InvalidParametersException(); } return(figure); }
/// <summary> /// Method for create cuttting figures /// </summary> /// <param name="figure"></param> /// <param name="values"></param> /// <returns></returns> public IFigure CreateFigure(IFigure figure, params double[] values) { IFigure newFigure = null; if (figure is Paper) { switch (values.Length) { case 1: figure = new CirclePaper(figure, values[0]); break; case 2: figure = new RectanglePaper(figure, values[0], values[1]); break; case 3: figure = new TrianglePaper(figure, values[0], values[1], values[2]); break; default: throw new InvalidParametersException(); } } else if (figure is Film) { switch (values.Length) { case 1: figure = new CircleFilm(figure, values[0]); break; case 2: figure = new RectangleFilm(figure, values[0], values[1]); break; case 3: figure = new TriangleFilm(figure, values[0], values[1], values[2]); break; default: throw new InvalidParametersException(); } } return(newFigure); }
public void CheckFiguresFactory() { Figure circle = null; Figure rectangle = null; Figure triangle = null; // Create factory FiguresFactory factory = new FiguresFactory(); // Film Circle circle = factory.GetFigure(Material.Film, 3); Figure expCircleF = new CircleFilm(3); Assert.AreEqual(expCircleF, circle); // Paper Circle circle = factory.GetFigure(Material.Paper, 3); Figure expCircleP = new CirclePaper(3); Assert.AreEqual(expCircleP, circle); // Film Rectangle rectangle = factory.GetFigure(Material.Film, 2, 2); Figure expRectangleF = new RectangleFilm(2, 2); Assert.AreEqual(expRectangleF, rectangle); // Paper Rectangle rectangle = factory.GetFigure(Material.Paper, 2, 2); Figure expRectangleP = new RectanglePaper(2, 2); Assert.AreEqual(expRectangleP, rectangle); // Film Triangle triangle = factory.GetFigure(Material.Film, 2, 2, 2); Figure expTriangleF = new TriangleFilm(2, 2, 2); Assert.AreEqual(expTriangleF, triangle); // Paper Triangle triangle = factory.GetFigure(Material.Paper, 3, 4, 5); Figure expTriangleP = new TrianglePaper(3, 4, 5); Assert.AreEqual(expTriangleP, triangle); }
/// <summary> /// Create new figure /// </summary> /// <param name="material">Material of new figure</param> /// <param name="form">Form of new figure</param> /// <param name="ps">Array of other params</param> /// <returns>Figure</returns> public IFigure CreateFigure(Material material, Form form, params float [] ps) { IFigure figure; switch (material) { case Material.Film: { switch (form) { case Form.Circle: { if (ps.Length == 1) { figure = new CircleFilm(ps[0]); break; } else { throw new Exception("Wrong input parameters"); } } case Form.Rectangle: { if (ps.Length == 2) { figure = new RectangleFilm(ps[0], ps[1]); break; } else { throw new Exception("Wrong input parameters"); } } case Form.Square: { if (ps.Length == 1) { figure = new SquareFilm(ps[0]); break; } else { throw new Exception("Wrong input parameters"); } } case Form.Triangle: { if (ps.Length == 3) { figure = new TriangleFilm(ps[0], ps[1], ps[2]); break; } else { throw new Exception("Wrong input parameters"); } } default: throw new Exception("Wrong input Form"); } break; } case Material.Paper: { switch (form) { case Form.Circle: { if (ps.Length == 1) { figure = new CirclePaper(ps[0]); break; } else { throw new Exception("Wrong input parameters"); } } case Form.Rectangle: { if (ps.Length == 2) { figure = new RectanglePaper(ps[0], ps[1]); break; } else { throw new Exception("Wrong input parameters"); } } case Form.Square: { if (ps.Length == 1) { figure = new SquarePaper(ps[0]); break; } else { throw new Exception("Wrong input parameters"); } } case Form.Triangle: { if (ps.Length == 3) { figure = new TrianglePaper(ps[0], ps[1], ps[2]); break; } else { throw new Exception("Wrong input parameters"); } } default: throw new Exception("Wrong input Form"); } break; } default: throw new Exception("Wrong input Material"); } return(figure); }
/// <summary> /// Method Write /// </summary> /// <param name="intoBox">Input List</param> public void Write(string output, List <IFigure> intoBox) { XmlWriter xmlWriter = XmlWriter.Create(output); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("Boxs"); foreach (var i in intoBox) { switch (i.GetType().Name) { case "CircleFilm": { CircleFilm c1 = (CircleFilm)i; xmlWriter.WriteStartElement("figure"); xmlWriter.WriteAttributeString("type", "Circle"); xmlWriter.WriteStartElement("material"); xmlWriter.WriteString("Film"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("color"); xmlWriter.WriteString("None"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("diameter"); xmlWriter.WriteString("" + c1.Diameter); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); break; } case "RectangleFilm": { RectangleFilm r1 = (RectangleFilm)i; xmlWriter.WriteStartElement("figure"); xmlWriter.WriteAttributeString("type", "Rectangle"); xmlWriter.WriteStartElement("material"); xmlWriter.WriteString("Film"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("color"); xmlWriter.WriteString("None"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("height"); xmlWriter.WriteString("" + r1.Height); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("width"); xmlWriter.WriteString("" + r1.Width); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); break; } case "SquareFilm": { SquareFilm s1 = (SquareFilm)i; xmlWriter.WriteStartElement("figure"); xmlWriter.WriteAttributeString("type", "Square"); xmlWriter.WriteStartElement("material"); xmlWriter.WriteString("Film"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("color"); xmlWriter.WriteString("None"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("height"); xmlWriter.WriteString("" + s1.A); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); break; } case "TriangleFilm": { TriangleFilm t1 = (TriangleFilm)i; xmlWriter.WriteStartElement("figure"); xmlWriter.WriteAttributeString("type", "Triangle"); xmlWriter.WriteStartElement("material"); xmlWriter.WriteString("Film"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("color"); xmlWriter.WriteString("None"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("side_a"); xmlWriter.WriteString("" + t1.A); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("side_b"); xmlWriter.WriteString("" + t1.B); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("side_c"); xmlWriter.WriteString("" + t1.C); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); break; } case "CirclePaper": { CirclePaper c1 = (CirclePaper)i; xmlWriter.WriteStartElement("figure"); xmlWriter.WriteAttributeString("type", "Circle"); xmlWriter.WriteStartElement("material"); xmlWriter.WriteString("Paper"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("color"); xmlWriter.WriteString("" + c1.Color); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("diameter"); xmlWriter.WriteString("" + c1.Diameter); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); break; } case "RectanglePaper": { RectanglePaper r1 = (RectanglePaper)i; xmlWriter.WriteStartElement("figure"); xmlWriter.WriteAttributeString("type", "Rectangle"); xmlWriter.WriteStartElement("material"); xmlWriter.WriteString("Paper"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("color"); xmlWriter.WriteString("" + r1.Color); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("height"); xmlWriter.WriteString("" + r1.Height); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("width"); xmlWriter.WriteString("" + r1.Width); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); break; } case "SquarePaper": { SquarePaper s1 = (SquarePaper)i; xmlWriter.WriteStartElement("figure"); xmlWriter.WriteAttributeString("type", "Square"); xmlWriter.WriteStartElement("material"); xmlWriter.WriteString("Paper"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("color"); xmlWriter.WriteString("" + s1.Color); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("height"); xmlWriter.WriteString("" + s1.A); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); break; } case "TrianglePaper": { TrianglePaper t1 = (TrianglePaper)i; xmlWriter.WriteStartElement("figure"); xmlWriter.WriteAttributeString("type", "Triangle"); xmlWriter.WriteStartElement("material"); xmlWriter.WriteString("Paper"); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("color"); xmlWriter.WriteString("" + t1.Color); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("side_a"); xmlWriter.WriteString("" + t1.A); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("side_b"); xmlWriter.WriteString("" + t1.B); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("side_c"); xmlWriter.WriteString("" + t1.C); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); break; } } } xmlWriter.WriteEndDocument(); xmlWriter.Close(); }