public void AddFigureWhenFigureIsInBoxAddNewFigure() { var figures = new List <IFigure> { new RectanglePaper(new List <double> { 2, 4 }, Color.Black), new TrianglePaper(new List <double> { 2, 4, 5 }, Color.Blue) }; var box = new Box(figures); var figure = new CirclePellicle(7); box.AddFigure(figure); IFigure[] result = box.Figures; var actualResult = new IFigure[20]; for (var i = 0; i < actualResult.Length; i++) { if (i == figures.Count) { actualResult[i] = figure; break; } actualResult[i] = figures[i]; } CollectionAssert.AreEqual(result, actualResult); }
public void SkinCircleWhenOldAreaLessNewAreaGetArgumentException() { var paperRectangle = new RectanglePellicle(new List <double> { 6, 8 }); var result = new CirclePellicle(7, paperRectangle); }
public void PaperCircleWhenOldAreaLessNewAreaGetArgumentException() { var paperCircle = new CirclePellicle(5); var result = new TrianglePellicle(new List <double> { 13, 14, 15 }, paperCircle); }
public void SkinRectangleWhenOldAreaLessNewAreaGetArgumentException() { var skinCircle = new CirclePellicle(7); var result = new RectanglePellicle(new List <double> { 14, 17 }, skinCircle); }
public void TestGetPerimeter() { var circle = new CirclePellicle(7); double result = circle.GetPerimeter(); double actualResult = 43.98229; Assert.AreEqual(result, actualResult, 0.001); }
public void TestGetArea() { var circle = new CirclePellicle(7); double result = circle.GetArea(); double actualResult = 153.93804; Assert.AreEqual(result, actualResult, 0.0000001); }
/// <summary> /// parses the skin circle into the xml element. /// </summary> /// <param name="xmlWriter"></param> /// <param name="skinCircle">Pellicle circle</param> public static void ParseXmlPellicleCircle(XmlTextWriter xmlWriter, CirclePellicle skinCircle) { xmlWriter.WriteStartElement(nameof(CirclePellicle)); xmlWriter.WriteElementString(nameof(CirclePellicle.Radius), skinCircle.Radius.ToString()); xmlWriter.WriteEndElement(); }
public void SkinCircleWhenOldAreaMoreNewAreaCreatePaperCircle() { var paperRectangle = new RectanglePellicle(new List <double> { 19, 14 }); var result = new CirclePellicle(4, paperRectangle); var actualResult = new CirclePellicle(4); Assert.AreEqual(result, actualResult); }
/// <summary> /// The method reads data from a file using StreamReader and returns a list of generalFigure. /// </summary> /// <returns>Figure list</returns> public static List <IFigure> ReadFiguresStreamReader(string way) { using (var streamReader = new StreamReader(way)) { var generalFigure = new List <IFigure>(); string line; while ((line = streamReader.ReadLine()) != null) { string elementContent = line.Trim('<', '>', '/', '\t', ' '); if (!Enum.TryParse(typeof(TypeFigure), elementContent, out object typeFigure)) { continue; } switch (typeFigure) { case TypeFigure.CirclePaper: CirclePaper paperCircle = ParserFiguresUsingStream.ParsePaperCircleXmlElement(streamReader); generalFigure.Add(paperCircle); break; case TypeFigure.RectanglePaper: RectanglePaper paperRectangle = ParserFiguresUsingStream.ParsePaperRectXmlElement(streamReader); generalFigure.Add(paperRectangle); break; case TypeFigure.TrianglePaper: TrianglePaper paperTriangle = ParserFiguresUsingStream.ParsePaperTriXmlElement(streamReader); generalFigure.Add(paperTriangle); break; case TypeFigure.CirclePellicle: CirclePellicle skinCircle = ParserFiguresUsingStream.ParsePellicleCircleXmlElement(streamReader); generalFigure.Add(skinCircle); break; case TypeFigure.RectanglePellicle: RectanglePellicle skinRectangle = ParserFiguresUsingStream.ParsePellicleRectangleFXmlElement(streamReader); generalFigure.Add(skinRectangle); break; case TypeFigure.TrianglePellicle: TrianglePellicle skinTriangle = ParserFiguresUsingStream.ParsePellicleTriXmlElement(streamReader); generalFigure.Add(skinTriangle); break; } streamReader.ReadLine(); } return(generalFigure); } }
public void SkinTriangleWhenOldAreaMoreNewAreaCreatePaperCircle() { var skinCircle = new CirclePellicle(5); var result = new TrianglePellicle(new List <double> { 3, 4, 5 }, skinCircle); var actualResult = new TrianglePellicle(new List <double> { 3, 4, 5 }); Assert.AreEqual(result, actualResult); }
public static List <IFigure> ReadFiguresXmlReader(string way) { using (var xmlReader = new XmlTextReader(way)) { var generalFigure = new List <IFigure>(); while (xmlReader.Read()) { if (!Enum.TryParse(typeof(TypeFigure), xmlReader.Name, out object typeFigure)) { continue; } switch (typeFigure) { case TypeFigure.CirclePaper: CirclePaper paperCircle = ParserFigureUsingXML.ParsePaperCircleXmlElement(xmlReader); generalFigure.Add(paperCircle); break; case TypeFigure.RectanglePaper: RectanglePaper paperRectangle = ParserFigureUsingXML.ParsePaperRectangleXmlElement(xmlReader); generalFigure.Add(paperRectangle); break; case TypeFigure.TrianglePaper: TrianglePaper paperTriangle = ParserFigureUsingXML.ParsePaperTriangleXmlElement(xmlReader); generalFigure.Add(paperTriangle); break; case TypeFigure.CirclePellicle: CirclePellicle skinCircle = ParserFigureUsingXML.ParsePellicleCircleXmlElement(xmlReader); generalFigure.Add(skinCircle); break; case TypeFigure.RectanglePellicle: RectanglePellicle skinRectangle = ParserFigureUsingXML.ParsePellicleRectangleXmlElement(xmlReader); generalFigure.Add(skinRectangle); break; case TypeFigure.TrianglePellicle: TrianglePellicle skinTriangle = ParserFigureUsingXML.ParsePellicleTriangleXmlElement(xmlReader); generalFigure.Add(skinTriangle); break; } xmlReader.Read(); } return(generalFigure); } }
public void SetFigureWhenIndexIsOutsideArrayGetArgumentOutOfRangeException() { var figures = new List <IFigure> { new RectanglePaper(new List <double> { 2, 4 }, Color.Black), new TrianglePaper(new List <double> { 2, 4, 7 }, Color.Blue), }; var box = new Box(figures); var figure = new CirclePellicle(7); box.SetFigure(-10, figure); }
public void SearchFigureWhenFigureIsNotInBoxGetNull() { var figures = new List <IFigure> { new RectanglePaper(new List <double> { 2, 4 }, Color.Black), new TrianglePaper(new List <double> { 2, 4, 7 }, Color.Blue) }; var box = new Box(figures); var figure = new CirclePellicle(7); IFigure result = box.SearchFigure(figure); IFigure actualResult = null; Assert.AreEqual(result, actualResult); }
public void SetFigureWhenIndexIsNotOutsideArrayChangeChosenFigure() { var figures = new List <IFigure> { new RectanglePaper(new List <double> { 2, 4 }, Color.Black), new TrianglePaper(new List <double> { 2, 4, 7 }, Color.Blue) }; var box = new Box(figures); var figure = new CirclePellicle(7); box.SetFigure(0, figure); IFigure result = box.ShowFigure(0); var actualResult = new CirclePellicle(7); Assert.AreEqual(result, actualResult); }
/// <summary> /// parses the skin circle into the xml element. /// </summary> /// <param name="streamWriter"></param> /// <param name="skinCircle">Pellicle circle</param> public static void ParseXmlPellicleCircle(StreamWriter streamWriter, CirclePellicle skinCircle) { streamWriter.WriteLine($"\t<{nameof(CirclePellicle)}>"); streamWriter.WriteLine($"\t\t<{nameof(CirclePellicle.Radius)}>{skinCircle.Radius}</{nameof(CirclePellicle.Radius)}>"); streamWriter.WriteLine($"\t</{nameof(CirclePellicle)}>"); }