Пример #1
0
        public void CreateTriangle_Starting_In_0_0()
        {
            int            numberOfVertices = 3;
            double         sideLength       = 2;
            RegularPolygon triangle         = factory.CreatePolygon(numberOfVertices, sideLength, new Vertex(0, 0));

            Assert.AreEqual(numberOfVertices, triangle.Vertices.Length);
            Assert.IsTrue(triangle.Vertices[0].Equals(new Vertex(0, 0)));
            Assert.IsTrue(triangle.Vertices[1].Equals(new Vertex(2, 0)));
            Assert.IsTrue(triangle.Vertices[2].Equals(new Vertex(1, 1.73)));
        }
Пример #2
0
        /// <summary>
        /// Creates RegularPolygon object with specified attributes and according to Mode from 'parameters':
        /// displays polygon description on console or saves it to default file.
        /// </summary>
        /// <param name="parameters"></param>
        private static void CalculateRegularPolygon(InputParameters parameters)
        {
            RegularPolygonFactory factory = new RegularPolygonFactory();

            try
            {
                RegularPolygon polygon = factory.CreatePolygon(parameters.NumberOfVertices, parameters.SideLength, new Vertex(0, 0));
                switch (parameters.Mode)
                {
                case ApplicationMode.SaveToFile:
                {
                    SaveToFile(polygon, _fileToSaveName);
                    break;
                }

                case ApplicationMode.ConsoleDisplay:
                {
                    Console.WriteLine(polygon.ToString());
                    break;
                }

                default:
                {
                    WriteErrorLine("Unknown application mode.");
                    break;
                }
                }
            }
            catch (RegularPolygonFactoryException ex)
            {
                WriteErrorLine(ex.Message);
            }
            catch (Exception ex) //Catches any exception, because cannot handle any kind of exception differently than only inform user about it.
            {
                WriteErrorLine(ex.Message);
            }
        }