예제 #1
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");
        }
예제 #2
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");
 }
예제 #3
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");
        }
예제 #4
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");
        }
예제 #5
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");
        }
예제 #6
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");
        }
예제 #7
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");
        }
예제 #8
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");
        }
예제 #9
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
                }
            }
        }