Example #1
0
 public void TestOefening2()
 {
     Utils.Object Obj = new Utils.Object("First.Oefenreeks1");
     Obj.AssertClass();
     Obj.AssertMethod(First.Program.ISPOS, typeof(bool), new Type[] { typeof(float) });
     Assert.That(Obj.Method(First.Program.ISPOS, typeof(float)).Invoke(5.67f), Is.True, "Getallen groter dan nul zijn positief");
     Assert.That(Obj.Method(First.Program.ISPOS, typeof(float)).Invoke(-12f), Is.False, "Negatieve getallen zijn kleiner dan null");
 }
Example #2
0
        public void TestOefening5()
        {
            Utils.Object Obj = new Utils.Object("First.Oefenreeks1");
            Obj.AssertClass();
            Obj.AssertMethod(First.Program.OPPRH, typeof(float), new Type[] { typeof(float), typeof(float) });

            Assert.That(Obj.Method(First.Program.OPPRH, new Type[] { typeof(float), typeof(float) }).Invoke(new object[] { 4.1f, 5f }), Is.EqualTo(20.5f).Within(.0005), "Foute Berekening");
            Assert.That(Obj.Method(First.Program.OPPRH, new Type[] { typeof(float), typeof(float) }).Invoke(new object[] { 1.1f, 3.4f }), Is.EqualTo(3.74f).Within(.0005), "Foute Berekening");
        }
Example #3
0
        public void TestOefening4()
        {
            Utils.Object Obj = new Utils.Object("First.Oefenreeks1");
            Obj.AssertClass();
            Obj.AssertMethod(First.Program.OPPRH, typeof(int), new Type[] { typeof(int), typeof(int) });

            Assert.That(Obj.Method(First.Program.OPPRH, new Type[] { typeof(int), typeof(int) }).Invoke(new object[] { 4, 5 }), Is.EqualTo(20), "Foute Berekening");
            Assert.That(Obj.Method(First.Program.OPPRH, new Type[] { typeof(int), typeof(int) }).Invoke(new object[] { 14, 10 }), Is.EqualTo(140), "Foute Berekening");
        }
Example #4
0
        public void IsPlayer2Winning()
        {
            var board = new Utils.Object("First.ScoreBoard");

            board.AssertMethod("IsPlayer2Winning", typeof(bool));

            Assert.That(board.Method("IsPlayer2Winning").Invoke(), Is.False, "Player 2 should not be winning when both scores are zero");
            board.Method("PointToPlayer2").Invoke();
            Assert.That(board.Method("IsPlayer2Winning").Invoke(), Is.True, "Player 2 should be winning when she has more points");
        }
Example #5
0
        public void PointToPlayer2()
        {
            var board = new Utils.Object("First.ScoreBoard");

            board.AssertMethod("PointToPlayer2", typeof(void));

            board.Method("PointToPlayer2").Invoke();
            Assert.That(board.Prop("Player2Score").Get(), Is.EqualTo(1), "PointToPlayer1 verhoogt het aantal punten niet met 1");

            board.Method("PointToPlayer2").Invoke();
            Assert.That(board.Prop("Player2Score").Get(), Is.EqualTo(2), "PointToPlayer1 verhoogt het aantal punten niet met 1");
        }
Example #6
0
        public void Reset()
        {
            var board = new Utils.Object("First.ScoreBoard");

            board.AssertMethod("Reset", typeof(void));

            // increase scores
            board.Method("PointToPlayer1").Invoke();
            board.Method("PointToPlayer2").Invoke();
            // reset and check if all are zero
            board.Method("Reset").Invoke();
            Assert.That(board.Prop("Player1Score")?.Get(), Is.EqualTo(0), "Reset does not reset all scores");
            Assert.That(board.Prop("Player2Score")?.Get(), Is.EqualTo(0), "Reset does not reset all scores");
        }
Example #7
0
        static void DoOef3()
        {
            if (!ValidateCoordinate())
            {
                return;
            }
            if (!ValidateCircle())
            {
                return;
            }

            Console.WriteLine();
            var circle = new Utils.Object("First.Circle");

            Console.WriteLine("Setting the radius of your circle to 4.5 ...");
            circle.Prop("Radius").Set(4.5f);
            Console.WriteLine("Settings the position of your circle to (3, 4) ...");
            var coord = new Utils.Object("First.Coordinate");

            coord.Method("Set", new Type[] { typeof(float), typeof(float) }).Invoke(new object[] { 3, 4 });
            circle.Prop("Pos").Set(coord.Instance);

            Console.WriteLine();
            Console.WriteLine("The area should be 63.61725");
            Console.WriteLine("Your value is " + circle.Prop("Area").Get());
            Console.WriteLine();
            Console.WriteLine("The perimeter should be 28.27433");
            Console.WriteLine("Your value is " + circle.Prop("Perimeter").Get());
        }
Example #8
0
        static void DoOef2()
        {
            if (!ValidateCoordinate())
            {
                return;
            }
            Console.WriteLine();

            Console.Write("Enter an X coordinate: ");
            float x = Convert.ToSingle(Console.ReadLine());

            Console.Write("Enter an Y coordinate: ");
            float y = Convert.ToSingle(Console.ReadLine());

            Console.WriteLine();

            var coord1 = new Utils.Object("First.Coordinate");

            coord1.Prop("X").Set(x);
            coord1.Prop("Y").Set(y);
            Console.WriteLine("When using X and Y properties, the values of your object are ");
            Console.WriteLine("X: " + coord1.Prop("X").Get());
            Console.WriteLine("Y: " + coord1.Prop("Y").Get());

            var coord2 = new Utils.Object("First.Coordinate");

            coord2.Method("Set", new Type[] { typeof(float), typeof(float) }).Invoke(new object[] { x, y });
            Console.WriteLine("When using the Set method, the values of your object are ");
            Console.WriteLine("X: " + coord2.Prop("X").Get());
            Console.WriteLine("Y: " + coord2.Prop("Y").Get());
        }
Example #9
0
        static void DoOef4()
        {
            if (!ValidateCoordinate())
            {
                return;
            }
            if (!ValidateRectangle())
            {
                return;
            }
            Console.WriteLine();

            var rectangle = new Utils.Object("First.Rectangle");

            Console.WriteLine("Setting the width of your rectangle to 4 ...");
            rectangle.Prop("Width").Set(4f);
            Console.WriteLine("Setting the height of your rectnagle to 6 ...");
            rectangle.Prop("Height").Set(6f);
            Console.WriteLine("Settings the position of your rectangle to (3, 4) ...");
            var coord = new Utils.Object("First.Coordinate");

            coord.Method("Set", new Type[] { typeof(float), typeof(float) }).Invoke(new object[] { 3, 4 });
            rectangle.Prop("Pos").Set(coord.Instance);

            Console.WriteLine();
            Console.WriteLine("Value\t\tExpected\tYours");
            Console.WriteLine("UpperLeft\t(1, 7)\t\t" + ToString(new Utils.Object(rectangle.Prop("UpperLeft").Get())));
            Console.WriteLine("UpperRight\t(5, 7)\t\t" + ToString(new Utils.Object(rectangle.Prop("UpperRight").Get())));
            Console.WriteLine("LowerLeft\t(1, 1)\t\t" + ToString(new Utils.Object(rectangle.Prop("LowerLeft").Get())));
            Console.WriteLine("LowerRight\t(5, 1)\t\t" + ToString(new Utils.Object(rectangle.Prop("LowerRight").Get())));

            Console.WriteLine();
            Console.WriteLine("Area\t\t24\t\t" + rectangle.Prop("Area").Get());
            Console.WriteLine("Perimeter\t16\t\t" + rectangle.Prop("Perimeter").Get());
        }
Example #10
0
        public void TestOefening10()
        {
            Utils.Object Obj = new Utils.Object("First.Oefenreeks1");
            Obj.AssertClass();
            Obj.AssertMethod(First.Program.DECR, typeof(void), new Type[] { typeof(int[]), typeof(int) });

            int[] arr  = { 5, 6, 7, 8 };
            int[] arr2 = { 0, 1, 2, 3 };
            Obj.Method(First.Program.DECR, new Type[] { typeof(int[]), typeof(int) }).Invoke(new object[] { arr, 5 });
            Assert.That(ArraysAreEqual(arr, arr2), Is.True, "De verlaging is niet correct");
        }
Example #11
0
        public void Age()
        {
            var person = new Utils.Object("First.Person");

            if (person.AssertClass())
            {
                person.AssertMethod("Age", typeof(int));
            }

            Random gen = new Random();

            for (int i = 0; i < 10; i++)
            {
                DateTime start = new DateTime(1900, 1, 1);
                int      range = (DateTime.Today - start).Days;

                var myDate = start.AddDays(gen.Next(range));
                person.Prop("DateOfBirth")?.Set(myDate);

                int expectedAge = (DateTime.Now.Year - myDate.Year) - 1;
                if (DateTime.Now.Month > myDate.Month)
                {
                    expectedAge++;
                }
                else if (DateTime.Now.Month == myDate.Month &&
                         DateTime.Now.Day >= myDate.Day)
                {
                    expectedAge++;
                }

                var calculatedAge = (int)person.Method("Age")?.Invoke();
                Assert.That(calculatedAge, Is.EqualTo(expectedAge), "De berekening van de leeftijd is niet juist");
                if (calculatedAge != expectedAge)
                {
                    break;                                               // no need to continue after an error
                }
            }
        }
Example #12
0
        static void StartScoreBoard()
        {
            if (!Utils.Object.DoesClassExist("First.ScoreBoard"))
            {
                Console.WriteLine("Er bestaat geen class 'ScoreBoard'.");
                return;
            }

            var board = new Utils.Object("First.ScoreBoard");

            if (board.IsValid)
            {
                var menu = new Utils.Menu();
                menu.AddOption('1', "Geef een punt aan Player 1",
                               () =>
                {
                    board.Method("PointToPlayer1")?.Invoke();
                    Console.WriteLine("Player 1 heeft nu "
                                      + board.Prop("Player1Score")?.Get()
                                      + " punten.");
                }
                               );

                menu.AddOption('2', "Geef een punt aan Player 2",
                               () =>
                {
                    board.Method("PointToPlayer2")?.Invoke();
                    Console.WriteLine("Player 2 heeft nu "
                                      + board.Prop("Player2Score")?.Get()
                                      + " punten.");
                }
                               );

                menu.AddOption('3', "Reset de scores",
                               () =>
                {
                    board.Method("Reset")?.Invoke();

                    Console.WriteLine("Player 1 heeft nu "
                                      + board.Prop("Player1Score")?.Get()
                                      + " punten.");
                    Console.WriteLine("Player 2 heeft nu "
                                      + board.Prop("Player2Score")?.Get()
                                      + " punten.");
                }
                               );

                menu.AddOption('4', "Geef de spelers een naam",
                               () =>
                {
                    Console.Write("Naam voor speler 1: ");
                    string player1 = Console.ReadLine();
                    board.Prop("Player1Name")?.Set(player1);

                    Console.Write("Naam voor speler 2: ");
                    string player2 = Console.ReadLine();
                    board.Prop("Player2Name")?.Set(player2);
                }
                               );

                menu.AddOption('5', "Toon het scorebord",
                               () =>
                {
                    Console.WriteLine(
                        board.Prop("Player1Name")?.Get()
                        + " heeft "
                        + board.Prop("Player1Score")?.Get()
                        + " punten."
                        );
                    Console.WriteLine(
                        board.Prop("Player2Name")?.Get()
                        + " heeft "
                        + board.Prop("Player2Score")?.Get()
                        + " punten."
                        );

                    if ((bool)board.Method("IsPlayer1Winning")?.Invoke() == true)
                    {
                        Console.WriteLine(
                            board.Prop("Player1Name")?.Get()
                            + " wint."
                            );
                    }
                    else if ((bool)board.Method("IsPlayer2Winning")?.Invoke() == true)
                    {
                        Console.WriteLine(
                            board.Prop("Player2Name")?.Get()
                            + " wint."
                            );
                    }
                    else
                    {
                        Console.WriteLine("Gelijkspel!");
                    }

                    Console.WriteLine(
                        "Het verschil bedraagt "
                        + board.Method("Distance")?.Invoke()
                        + " punten."
                        );
                }
                               );

                menu.Start();
            }
        }
Example #13
0
        public void Distance()
        {
            var board = new Utils.Object("First.ScoreBoard");

            board.AssertMethod("Distance", typeof(int));

            Assert.That(board.Method("Distance").Invoke(), Is.EqualTo(0), "When both players have zero points, the distance should be zero");

            board.Method("PointToPlayer1").Invoke();
            Assert.That(board.Method("Distance").Invoke(), Is.EqualTo(1), "The distance between scores is not correctly calculated");

            board.Method("PointToPlayer1").Invoke();
            Assert.That(board.Method("Distance").Invoke(), Is.EqualTo(2), "The distance between scores is not correctly calculated");

            board.Method("PointToPlayer2").Invoke();
            Assert.That(board.Method("Distance").Invoke(), Is.EqualTo(1), "The distance between scores is not correctly calculated");

            board.Method("PointToPlayer2").Invoke();
            Assert.That(board.Method("Distance").Invoke(), Is.EqualTo(0), "The distance between scores is not correctly calculated");

            board.Method("PointToPlayer2").Invoke();
            Assert.That(board.Method("Distance").Invoke(), Is.EqualTo(1), "The distance between scores is not correctly calculated");

            board.Method("PointToPlayer2").Invoke();
            Assert.That(board.Method("Distance").Invoke(), Is.EqualTo(2), "The distance between scores is not correctly calculated");
        }