Exemple #1
0
        public static void Main(string[] args)
        {
            var triangle = new Triangle(new List <Point>()
            {
                new Point(0, 0), new Point(5, 5), new Point(0, 5)
            });
            var rectangle = new Rectangle(new List <Point>()
            {
                new Point(0, 0), new Point(0, 5), new Point(5, 5), new Point(5, 0)
            });
            var rhombus =
                new Rhombus(new List <Point> {
                new Point(0, 1), new Point(2, 0), new Point(4, 1), new Point(2, 2)
            });
            var areaVisitor = new GetAreaVisitor();

            triangle.Accept(areaVisitor);
            Console.WriteLine(areaVisitor.Result);
            rectangle.Accept(areaVisitor);
            Console.WriteLine(areaVisitor.Result);
            rhombus.Accept(areaVisitor);
            Console.WriteLine(areaVisitor.Result);
            Console.WriteLine();
            var drawVisitor = new DrawingVisitor(new Point(5, 5));

            triangle.Accept(drawVisitor);
            rectangle.Accept(drawVisitor);
            rhombus.Accept(drawVisitor);
            var polygonLoveVisitor = new PolygonLoveVisitor();

            triangle.Accept(polygonLoveVisitor);
            rectangle.Accept(polygonLoveVisitor);
            rhombus.Accept(polygonLoveVisitor);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //Ex2 Part2
            List <object> operations = new List <object>();


            //Builder Ex8
            FitnessCreator MyFitness = new FitnessCreator(new FitnessBuilderA());

            MyFitness.CreateFitness();
            Console.WriteLine(MyFitness.GetFitnessTraining() + " A");

            MyFitness = new FitnessCreator(new FitnessBuilderB());
            MyFitness.CreateFitness();
            Console.WriteLine(MyFitness.GetFitnessTraining() + " B");

            //Visitor Ex6
            Circle   c      = new Circle("Im Circle");
            IVisitor threeD = new Visitor3D();

            Console.WriteLine($"3D = {c.Accept(threeD)}");

            Rectangle r    = new Rectangle("Im rectangle");
            IVisitor  twoD = new Visitor2D();

            Console.WriteLine($"2D = {r.Accept(twoD)}");

            Triangle t      = new Triangle("Im triangle");
            IVisitor update = new VisitorUpdateResolution();

            Console.WriteLine(t.Accept(update));
            Console.WriteLine(t.Accept(twoD));

            //Decorator Ex10
            IWindow windowBase = new Shading(new _3DLight(new ColorFrame(new BaseWindow())));

            Console.WriteLine(windowBase.GetDetails());

            //Part2 Ex1
            List <string> words = new List <string>
            {
                "java", "jjava", "vaj", "aavj", "j", "vjaa", "dan", "and", "ddan"
            };

            ListWordsOperation.findDuplicateWords(words);
        }
Exemple #3
0
        public void Accept_VisitWithTriangle()
        {
            var visitorMoq = new Mock <IShapeVisitor <int> >();
            var circle     = new Triangle(1, 1, 1);

            circle.Accept(visitorMoq.Object);

            visitorMoq.Verify(visitor => visitor.Visit(circle), Times.Once);
        }
Exemple #4
0
        public void ShouldCalculateAreaOfTriangle(double side1, double side2, double side3, double expectedArea)
        {
            areaCalculator = new AreaCalculator();

            var shape = new Triangle(side1, side2, side3);

            shape.Accept(areaCalculator);

            Assert.AreEqual(expectedArea, areaCalculator.ResultedArea.Value);
        }