示例#1
0
        public static double GetAveragePerimeter(this ShapeCollection shapes)
        {
            int    count  = shapes.Count();
            double area   = shapes.TotalPerimeter();
            double result = area / count;

            return(result);
        }
示例#2
0
        public void GetDefaultShapeCollection_ShouldReturnDefaultObjectInstanceCollection()
        {
            IEnumerable <AbstractShape> expectedShapeCollection = new List <AbstractShape>()
            {
                new Circle("Nom_1", 12),
                new Circle("Nom_2", 15),
                new Triangle("Nom_3", 16)
            };

            ShapeManager shapeManager = new ShapeManager();

            ShapeCollection actualShapeCollection = shapeManager.GetDefaultShapeCollection();

            Assert.AreEqual(expectedShapeCollection.Count(), actualShapeCollection.Count());

            foreach (AbstractShape expectedAbstractShape in expectedShapeCollection)
            {
                Assert.IsNotNull(actualShapeCollection.SingleOrDefault <AbstractShape>(x => x.Name == expectedAbstractShape.Name && x.Surface == expectedAbstractShape.Surface));
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            #region Text Color
            Console.ForegroundColor = ConsoleColor.Red;
            #endregion
            #region Creating Shapes
            Circle   circle   = new Circle(2);
            Triangle triangle = new Triangle(3, 4, 5);
            Square   square   = new Square(2);
            #endregion
            #region Calling Methods
            // Circle
            circle.GetArea();
            circle.GetPerimeter();
            Console.WriteLine("-------------------------------------------\n");
            // Triangle
            triangle.GetArea();
            triangle.GetPerimeter();
            Console.WriteLine("-------------------------------------------\n");
            // Square
            square.GetArea();
            square.GetPerimeter();
            Console.WriteLine("-------------------------------------------\n");
            Console.WriteLine("-------------------------------------------\n");

            ShapeCollection shapes = new ShapeCollection();
            shapes.AddShape(new Circle(2));
            shapes.AddShape(new Square(4));
            shapes.AddShape(new Triangle(3, 4, 5));
            Console.WriteLine($"There are total of {shapes.Count()} shapes\n");
            Console.WriteLine("The total area of the collection is {0}. \n", shapes.TotalArea());
            Console.WriteLine("The total perimeter of the collection is {0}. \n", shapes.TotalPerimeter());
            #endregion


            Console.WriteLine("\nPress enter to exit...");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            //Circle krug = new Circle(3);

            //double fside = 3;
            //double sside = 4;
            //double tside = 5;

            //if (Triangle.IsValidTriangle(fside, sside, tside))
            //{
            //    Triangle triangle = new Triangle(fside, sside, tside);
            //    Console.WriteLine(triangle.GetArea());
            //}
            //else
            //{
            //    Console.WriteLine("That is not valid");
            //}

            //double side = -2;
            //if (Square.IsValid(side))
            //{
            //    Square square = new Square(side);
            //    Console.WriteLine(square.GetArea());
            //}
            //else
            //{
            //    Console.WriteLine("That is not valid");
            //}


            ShapeCollection shapes = new ShapeCollection();

            shapes.AddShape(new Circle(10));
            shapes.AddShape(new Triangle(3, 4, 5));
            shapes.AddShape(new Triangle(3, 10, 12));
            shapes.AddShape(new Square(10));

            Console.WriteLine($"There are {shapes.Count()} shapes");
            Console.WriteLine($"Total area is {shapes.TotalArea()} ");
            Console.WriteLine($"Total perimeter is {shapes.TotalPerimeter()} ");

            Console.WriteLine($"Average area is {shapes.GetAverageArea()} ");
            Console.WriteLine($"Average area is {Helper.GetAverageArea(shapes)} ");

            Console.WriteLine(Helper.IsEven(2));
            Console.WriteLine(Helper.IsEven(3));

            Console.WriteLine(2.IsEven());
            Console.WriteLine(3.IsEven());

            var x = 10;

            Console.WriteLine(Helper.AddOne(Helper.Double(Helper.Square(x))));
            Console.WriteLine(x.Square().Double().AddOne());

            Triangle t = new Triangle(3, 7, 9);

            // these two are completely the same
            Console.WriteLine(IShapeHelper.GetRatio(t));
            Console.WriteLine(t.GetRatio());

            // these two are completely the same
            Console.WriteLine(IShapeHelper.GetMultipliedArea(t, 3));
            Console.WriteLine(t.GetMultipliedArea(3));
        }