Пример #1
0
        public void SideLengthLessThen0()
        {
            RegularPolygonFactory factory = new RegularPolygonFactory();


            RegularPolygon a = factory.GetRegularPolygon(3, -10);
        }
Пример #2
0
        /// <summary>
        /// Given the application parameters, creates regular polygon and depending on the option: saves it to default file or displays it on console
        /// /// </summary>
        /// <param name="parameters">Already parsed application parameters</param>
        private static void ProcessInput(AppParameters parameters)
        {
            RegularPolygonFactory factory = new RegularPolygonFactory();

            try
            {
                RegularPolygon polygon =
                    factory.CreateRegularPolygon(parameters.NumberOfVertices, parameters.SideLength, DefaultInitialVertex);
                switch (parameters.Option)
                {
                case AppParameters.ProcessType.DisplayOnConsole:
                    DU.DisplayText(polygon.ToString());
                    DU.DisplayText("Successfully completed operation", DU.InformationType.OnSuccess);
                    break;

                case AppParameters.ProcessType.SaveToFile:
                    SavePolygonToFile(DefaultFilePath, polygon);
                    break;
                }
            }
            catch (RegularPolygonFactoryLogicalException e)
            {
                DU.DisplayText(e.Message, DU.InformationType.OnError);
            }
        }
        public void CreateRegularPolygon_ValidInput_ShouldReturnCorrectValue()
        {
            RegularPolygon polygon = RegularPolygonFactory.createRegularPolygon(3, 2);

            Assert.AreEqual(3, polygon.VertexNumber);
            Assert.AreEqual(Math.Sqrt(3), polygon.Area, 0.01);
            Assert.AreEqual(3, polygon.VerticesCoordinates().Length);
        }
        public void HandleEvent()
        {
            polygonFactory          = new RegularPolygonFactory(PointsAmount);
            Canvas.CurFigureFactory = polygonFactory;
            Canvas.CurFigure        = null;
            MouseEventArgs eMouse = (MouseEventArgs)E;

            Canvas.PrevPoint = new System.Drawing.PointF(eMouse.X, eMouse.Y);
        }
        public void CreateRegularPolygon_Pentagon_ShouldReturnCorrectVerticies()
        {
            RegularPolygon polygon = RegularPolygonFactory.createRegularPolygon(5, 2);

            var verticies = polygon.VerticesCoordinates();

            Assert.IsTrue(verticies[0].Equals(new Vertex(0, 0)));
            Assert.IsTrue(verticies[1].Equals(new Vertex(-0.62, 1.9)));
            Assert.IsTrue(verticies[2].Equals(new Vertex(1, 3.08)));
            Assert.IsTrue(verticies[3].Equals(new Vertex(2.62, 1.9)));
            Assert.IsTrue(verticies[4].Equals(new Vertex(2, 0)));
        }
Пример #6
0
        public void RegularPolygonFactoryTest()
        {
            RegularPolygonFactory factory = new RegularPolygonFactory();



            RegularPolygon a = factory.GetRegularPolygon(3, 10);
            RegularPolygon b = factory.GetRegularPolygon(4, 10);
            RegularPolygon c = factory.GetRegularPolygon(6, 10);


            Assert.IsInstanceOfType(a, typeof(Triangle));
            Assert.IsInstanceOfType(b, typeof(Square));
            Assert.IsInstanceOfType(c, typeof(NSidedRegularPolygon));
        }
Пример #7
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);
            }
        }
Пример #8
0
        static void Main(string[] args)
        {
            int maxNumberOfInputArguments = 3;
            int minNumberOfInputArguments = 2;

            if (!InputValidationMethods.Validate(args, maxNumberOfInputArguments, minNumberOfInputArguments))
            {
                return;
            }

            int    vertexCount = Convert.ToInt32(args[0]);
            double sideLength  = Convert.ToDouble(args[1]);

            RegularPolygon polygon;

            try
            {
                polygon = RegularPolygonFactory.createRegularPolygon(vertexCount, sideLength);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            if (args.Length == maxNumberOfInputArguments)
            {
                FileHandler.saveVertices(args[2], polygon);
            }
            else
            {
                Console.WriteLine(polygon.ToString());
            }

            Console.ReadKey();
        }
Пример #9
0
        public void CoordinatesCalculationsTest()
        {
            RegularPolygonFactory factory = new RegularPolygonFactory();

            RegularPolygon a = factory.GetRegularPolygon(3, 2);


            Point[] d = a.GetCoordinates();


            Point[] g = { new Point {
                              x = 0, y = 0
                          }, new Point{
                              x = (float)-1.732051, y = (float)-0.9999999
                          }, new Point{
                              x = (float)-1.732051, y = (float)0.9999999
                          } };

            for (int i = 0; i < d.Length; i++)
            {
                Assert.AreEqual(Math.Round(d[i].x, 2), Math.Round(g[i].x, 2));
                Assert.AreEqual(Math.Round(d[i].y, 2), Math.Round(g[i].y, 2));
            }
        }
 public void Setup()
 {
     _factory        = new PolygonLibrary.RegularPolygonFactory();
     _initiaVertex   = new Vertex(0, 0);
     _standardLength = 2.0;
 }
 public void CreateRegularPolygon_InappropriateAmountOfVertices_ShouldThrowException()
 {
     RegularPolygon polygon = RegularPolygonFactory.createRegularPolygon(1, 2);
 }
Пример #12
0
 public void Initialize()
 {
     factory = new RegularPolygonFactory();
 }