public void Test_GetPerimeter(double actualResult, params double[] sides) { var skinRectangle = new SkinRectangle(sides); double result = skinRectangle.GetPerimeter(); Assert.AreEqual(result, actualResult, 0.0000001); }
public void Test_SkinRectangle(double radius, params double[] resultSides) { var skinCircle = new SkinCircle(radius); var result = new SkinRectangle(resultSides, skinCircle); var actualResult = new SkinRectangle(resultSides); Assert.AreEqual(result, actualResult); }
public void SkinRectangle_WhenOldAreaLessNewArea_GetArgumentException() { var sidesSkinRectangle = new List <double> { 12, 14 }; var radiusSkinCircle = 5; var skinCircle = new SkinCircle(radiusSkinCircle); var result = new SkinRectangle(sidesSkinRectangle, skinCircle); }
/// <summary> /// The method reads data from a file using StreamReader and returns a list of figures. /// </summary> /// <returns>Figure list</returns> public static List <IFigure> ReadFiguresStreamReader(string filePath) { using (var streamReader = new StreamReader(filePath)) { var figures = 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.PaperCircle: PaperCircle paperCircle = ParserFiguresUsingStream.ParseToPaperCircleFromXmlElement(streamReader); figures.Add(paperCircle); break; case TypeFigure.PaperRectangle: PaperRectangle paperRectangle = ParserFiguresUsingStream.ParseToPaperRectangleFromXmlElement(streamReader); figures.Add(paperRectangle); break; case TypeFigure.PaperTriangle: PaperTriangle paperTriangle = ParserFiguresUsingStream.ParseToPaperTriangleFromXmlElement(streamReader); figures.Add(paperTriangle); break; case TypeFigure.SkinCircle: SkinCircle skinCircle = ParserFiguresUsingStream.ParseToSkinCircleFromXmlElement(streamReader); figures.Add(skinCircle); break; case TypeFigure.SkinRectangle: SkinRectangle skinRectangle = ParserFiguresUsingStream.ParseToSkinRectangleFromXmlElement(streamReader); figures.Add(skinRectangle); break; case TypeFigure.SkinTriangle: SkinTriangle skinTriangle = ParserFiguresUsingStream.ParseToSkinTriangleFromXmlElement(streamReader); figures.Add(skinTriangle); break; } streamReader.ReadLine(); } return(figures); } }
public void Test_GetPerimeter() { var sidesSkinRectangle = new List <double> { 6, 8 }; var skinRectangle = new SkinRectangle(sidesSkinRectangle); double result = skinRectangle.GetPerimeter(); double actualResult = 14; Assert.AreEqual(result, actualResult, 0.0000001); }
/// <summary> /// The method reads data from a file using XmlReader and returns a list of figures. /// </summary> /// <param name="filePath">Path to the file</param> /// <returns>Figure list</returns> public static List <IFigure> ReadFiguresXmlReader(string filePath) { using (var xmlReader = new XmlTextReader(filePath)) { var figures = new List <IFigure>(); while (xmlReader.Read()) { if (!Enum.TryParse(typeof(TypeFigure), xmlReader.Name, out object typeFigure)) { continue; } switch (typeFigure) { case TypeFigure.PaperCircle: PaperCircle paperCircle = ParserFigureUsingXML.ParseToPaperCircleFromXmlElement(xmlReader); figures.Add(paperCircle); break; case TypeFigure.PaperRectangle: PaperRectangle paperRectangle = ParserFigureUsingXML.ParseToPaperRectangleFromXmlElement(xmlReader); figures.Add(paperRectangle); break; case TypeFigure.PaperTriangle: PaperTriangle paperTriangle = ParserFigureUsingXML.ParseToPaperTriangleFromXmlElement(xmlReader); figures.Add(paperTriangle); break; case TypeFigure.SkinCircle: SkinCircle skinCircle = ParserFigureUsingXML.ParseToSkinCircleFromXmlElement(xmlReader); figures.Add(skinCircle); break; case TypeFigure.SkinRectangle: SkinRectangle skinRectangle = ParserFigureUsingXML.ParseToSkinRectangleFromXmlElement(xmlReader); figures.Add(skinRectangle); break; case TypeFigure.SkinTriangle: SkinTriangle skinTriangle = ParserFigureUsingXML.ParseToSkinTriangleFromXmlElement(xmlReader); figures.Add(skinTriangle); break; } xmlReader.Read(); } return(figures); } }
public void SkinRectangle_WhenOldAreaMoreNewArea_CreatePaperCircle() { var sidesSkinRectangle = new List <double> { 2, 4 }; var radiusSkinCircle = 5; var skinCircle = new SkinCircle(radiusSkinCircle); var result = new SkinRectangle(sidesSkinRectangle, skinCircle); var actualResult = new SkinRectangle(sidesSkinRectangle); Assert.AreEqual(result, actualResult); }
public void Test_SkinCircle_ThrowsArgumentException(Type typeException, string exceptionMessage, double radius, params double[] sides) { var skinRectangle = new SkinRectangle(sides); Assert.That(() => new SkinCircle(radius, skinRectangle), Throws.ArgumentException.With.Message.EqualTo(exceptionMessage)); }
/// <summary> /// The method parses the skin rectangle into the xml element. /// </summary> /// <param name="xmlWriter"></param> /// <param name="skinRectangle">Skin rectangle</param> public static void ParseToXmlElementFromSkinRectangle(XmlTextWriter xmlWriter, SkinRectangle skinRectangle) { xmlWriter.WriteStartElement(nameof(SkinRectangle)); xmlWriter.WriteElementString(nameof(SkinRectangle.Sides), string.Join(' ', skinRectangle.Sides)); xmlWriter.WriteEndElement(); }
/// <summary> /// The method parses the skin rectangle into the xml element. /// </summary> /// <param name="streamWriter"></param> /// <param name="skinRectangle">Skin rectangle</param> public static void ParseToXmlElementFromSkinRectangle(StreamWriter streamWriter, SkinRectangle skinRectangle) { streamWriter.WriteLine($"\t<{nameof(SkinRectangle)}>"); streamWriter.WriteLine($"\t\t<{nameof(SkinRectangle.Sides)}>{string.Join(' ', skinRectangle.Sides)}</{nameof(SkinRectangle.Sides)}>"); streamWriter.WriteLine($"\t</{nameof(SkinRectangle)}>"); }