public void ShouldCalculateARectangleArea()
        {
            var rectangles = new List <Rectangle> {
                new Rectangle(10, 3)
            };

            var area = calculator.Area(rectangles);

            Assert.AreEqual(30.0, area, 0.01);
        }
Example #2
0
 public static void Main(string[] args)
 {
     AreaCalculator areaCalculator = new AreaCalculator();
     var rectangle = new Rectangle();
     rectangle.Width = 200;
     rectangle.Height = 100;
     var circle = new Circle();
     circle.Radius = 10;
     Object[] shapes = new Object[] { rectangle, circle };
     areaCalculator.Area(shapes);
 }
Example #3
0
    public static void Main(string[] args)
    {
        Rectangle rectangle = new Rectangle();

        rectangle.Width  = 20;
        rectangle.Height = 20;

        AreaCalculator areacalculator = new AreaCalculator();

        Console.WriteLine(areacalculator.Area(rectangle));
    }
Example #4
0
    public static void Main(string[] args)
    {
        AreaCalculator areaCalculator = new AreaCalculator();
        var            rectangle1     = new Rectangle();

        rectangle1.Width  = 200;
        rectangle1.Height = 100;
        var rectangle2 = new Rectangle();

        rectangle2.Width  = 300;
        rectangle2.Height = 100;
        Rectangle[] rectangles = new Rectangle[] { rectangle1, rectangle2 };
        areaCalculator.Area(rectangles);
    }
Example #5
0
        //static void Main(string[] args)
        //{
        //    Person person = new Teacher();
        //    person.ShowInfo();

        //    Student student = new Student();
        //    student.ShowInfo();

        //    Console.Read();
        //}
        #endregion

        #region Virtual Methods
        //static void Main(string[] args)
        //{
        //    User user = new User();
        //    user.ShowRole();

        //    user = new GoldUser();
        //    user.ShowRole();

        //    SilverUser silverUser = new SilverUser();
        //    silverUser.ShowRole();

        //    user = new BronzeUser();
        //    user.ShowRole();

        //    Console.Read();
        //}
        #endregion

        #region OCP
        static void Main(string[] args)
        {
            Rectangle rectangle = new Rectangle(2, 4);
            Circle    circle    = new Circle(3);

            AreaCalculator areaCalculator = new AreaCalculator();
            var            shapes         = new List <Shape> {
                rectangle, circle
            };

            double area = areaCalculator.Area(shapes);

            Console.WriteLine(area);
            Console.Read();
        }
Example #6
0
        public void Can_calculate_area_of_collection_of_shapes()
        {
            // Arrange
            var shapes = new Shape[] { new Rectangle {
                                           Height = 10, Width = 4
                                       }, new Circle {
                                           Radius = 10
                                       } };

            // Act
            var areas = _areaCalc.Area(shapes);

            // Assert
            Assert.AreEqual(354.15, Math.Truncate(areas * 100) / 100);
        }
Example #7
0
        private static void OCPExercise()
        {
            List <IShape> shapes = new List <IShape>()
            {
                new Rectangle()
                {
                    Height = 10, Width = 20
                },
                new Circle()
                {
                    Radius = 50
                }
            };
            AreaCalculator areaCalculator = new AreaCalculator();

            WriteLine(areaCalculator.Area(shapes));
        }
Example #8
0
        public static void Main(string[] args)
        {
            AreaCalculator ac = new AreaCalculator();

            var rec = new Rectangle
            {
                Width  = 8,
                Height = 4
            };

            var cir = new Circle()
            {
                Radius = 8
            };

            object[] shapes = new object[2];

            shapes[0] = rec;
            shapes[1] = cir;

            ac.Area(shapes);
            Console.WriteLine("End bad example");

            //Open/Closed Principle
            Console.WriteLine("\n" + "Begin Open Closed example");

            OAreaCalculator oCalc = new OAreaCalculator();

            var oRec = new ORectangle
            {
                Width  = 8,
                Height = 4
            };

            var oCir = new OCircle()
            {
                Radius = 8
            };

            OShape[] Oshapes = new OShape[2];

            Oshapes[0] = oRec;
            Oshapes[1] = oCir;

            oCalc.OArea(Oshapes);
        }
Example #9
0
 public void TestAreaCalculator()
 {
     AreaCalculator Calc = AreaCalculator.GetInstance();
     Assert.AreEqual(6, Calc.Area(3, 4, 5));
 }
Example #10
0
        public void GetSquareArea()
        {
            var area = areaCalculator.Area(shapes2);

            Assert.AreEqual(area, 300);
        }