public void Test_GetPerimeter(double actualResult, params double[] sides) { var skinTriangle = new SkinTriangle(sides); double result = skinTriangle.GetPerimeter(); Assert.AreEqual(result, actualResult, 0.000001); }
public void Test_SkinTriangle(double radius, params double[] resultSides) { var skinCircle = new SkinCircle(radius); var result = new SkinTriangle(resultSides, skinCircle); var actualResult = new SkinTriangle(resultSides); Assert.AreEqual(result, actualResult); }
/// <summary> /// Returns the skin triangle that the given skin triangle shares this skin edge with. /// </summary> /// <param name="skinTriangle">The skin triangle for which we want the adjacent skin triangle on this skin edge.</param> /// <returns>The skin triangle that the given skin triangle shares this skin edge with.</returns> public SkinTriangle GetAdjacentSkinTriangle(SkinTriangle skinTriangle) { if (triangles.Count <= 1) { return(null); } return(triangles[0] == skinTriangle ? triangles[1] : triangles[0]); }
public void PaperCircle_WhenOldAreaLessNewArea_GetArgumentException() { var sidesSkinTriangle = new List <double> { 13, 14, 15 }; var radiusSkinCircle = 5; var paperCircle = new SkinCircle(radiusSkinCircle); var result = new SkinTriangle(sidesSkinTriangle, paperCircle); }
/// <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 sidesSkinTriangle = new List <double> { 6, 8, 6 }; var skinTriangle = new SkinTriangle(sidesSkinTriangle); double result = skinTriangle.GetPerimeter(); double actualResult = 20; Assert.AreEqual(result, actualResult, 0.000001); }
public void Test_GetArea() { var sidesSkinTriangle = new List <double> { 6, 8, 6 }; var skinTriangle = new SkinTriangle(sidesSkinTriangle); double result = skinTriangle.GetArea(); var actualResult = 17.888543; Assert.AreEqual(result, actualResult, 0.000001); }
/// <summary> /// Returns whether the given skin triangle is considered equal to this object. /// </summary> /// <param name="other">The other skin triangle.</param> /// <returns>Whether the given skin triangle is considered equal to this object.</returns> public bool Equals(SkinTriangle other) { if ((object)other == null) { return(false); } return (((vertex0Index == other.vertex0Index) && (vertex1Index == other.vertex1Index) && (vertex2Index == other.vertex2Index)) || ((vertex0Index == other.vertex1Index) && (vertex1Index == other.vertex2Index) && (vertex2Index == other.vertex0Index)) || ((vertex0Index == other.vertex2Index) && (vertex1Index == other.vertex0Index) && (vertex2Index == other.vertex1Index))); }
/// <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 SkinTriangle_WhenOldAreaMoreNewArea_CreatePaperCircle() { var sidesSkinTriangle = new List <double> { 3, 4, 5 }; var radiusSkinCircle = 5; var skinCircle = new SkinCircle(radiusSkinCircle); var result = new SkinTriangle(sidesSkinTriangle, skinCircle); var actualResult = new SkinTriangle(sidesSkinTriangle); Assert.AreEqual(result, actualResult); }
/// <summary> /// The method parses the skin triangle into the xml element. /// </summary> /// <param name="xmlWriter"></param> /// <param name="skinTriangle">Skin triangle</param> public static void ParseToXmlElementFromSkinTriangle(XmlTextWriter xmlWriter, SkinTriangle skinTriangle) { xmlWriter.WriteStartElement(nameof(SkinTriangle)); xmlWriter.WriteElementString(nameof(SkinTriangle.Sides), string.Join(' ', skinTriangle.Sides)); xmlWriter.WriteEndElement(); }
/// <summary> /// The method parses the skin triangle into the xml element. /// </summary> /// <param name="streamWriter"></param> /// <param name="skinTriangle">Skin triangle</param> public static void ParseToXmlElementFromSkinTriangle(StreamWriter streamWriter, SkinTriangle skinTriangle) { streamWriter.WriteLine($"\t<{nameof(SkinTriangle)}>"); streamWriter.WriteLine($"\t\t<{nameof(SkinTriangle.Sides)}>{string.Join(' ', skinTriangle.Sides)}</{nameof(SkinTriangle.Sides)}>"); streamWriter.WriteLine($"\t</{nameof(SkinTriangle)}>"); }