Beispiel #1
0
        public void ShapeShouldHaveEqualSides()
        {
            IShape shape = null;

            for (int i = 3; i < 10; i++)
            {
                shape = sf.CreateShape(5, i);
                Point[] array = shape.CalculateCorners();
                for (int j = 1; j < array.Length; j++)
                {
                    double calculatedLenght = Math.Sqrt(Math.Pow(array[j].x - array[j - 1].x, 2) + Math.Pow(array[j].y - array[j - 1].y, 2));
                    Assert.AreEqual(5, Math.Round(calculatedLenght));
                }
            }
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            Console.WriteLine(args[0] + " " + args[1]);
            int    numberOfCorners = 0;
            double lenghtOfSide;

            try
            {
                numberOfCorners = int.Parse(args[1]);
                if (numberOfCorners <= 2)
                {
                    throw new FormatException();
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Invalid parameter [1], please provide Integer value bigger than 2 - program will exit");
                Console.ReadKey();
                return(-1);
            }
            try
            {
                lenghtOfSide = double.Parse(args[0]);
                if (lenghtOfSide <= 0)
                {
                    throw new FormatException();
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("Invalid parameter [0], please provide Double positive value - program will exit");
                Console.ReadKey();
                return(-2);
            }
            ShapeFactory factory = new ShapeFactory();
            IShape       shape   = factory.CreateShape(lenghtOfSide, numberOfCorners);

            //TODO save to file or print on console
            switch (args[2])
            {
            case "f":
            {
                Console.WriteLine("Chosen print to file");
                break;
            }

            case "c":
            {
                Console.WriteLine("Field of shape: {0}", shape.CalculateField());
                Console.WriteLine("List of corners of this shape:");
                Point[] list = shape.CalculateCorners();
                for (int i = 0; i < numberOfCorners; i++)
                {
                    Console.WriteLine("X = {0}; Y = {1}", Math.Round(list[i].x, 4), Math.Round(list[i].y));
                }
                break;
            }

            default:
            {
                Console.WriteLine("Invalid 3rd argument provided");
                Console.WriteLine("Please provide \"c\" for console print and \"f\" for file save");
                break;
            }
            }
            Console.ReadKey();
            return(0);
        }