예제 #1
0
        public void Case2()
        {
            var text = @"app PeaceKeeper
{
    on Init =>
    {
        'Begin' >> @>log;
        //@r = @b = 1;
        @bx >> @>log;
        'End' >> @>log;
    }
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) => {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message, "Begin");
                    break;

                case 2:
                    Assert.AreEqual(message, "NULL");
                    break;

                case 3:
                    Assert.AreEqual(message, "End");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }
예제 #2
0
        private static void TstTestRunner()
        {
            _logger.Log("Begin");

            var text = @"app PeaceKeeper
{
    on Init =>
    {
        try
        {
            'Begin' >> @>log;
            'End' >> @>log;        
        }
        else
        {
            'else' >> @>log;
        }
        ensure
        {
            'ensure' >> @>log;
        }

        'End of `Init`' >> @>log;
    }
}";

            BehaviorTestEngineInstance.Run(text,
                                           (n, message) => {
                _logger.Log($"n = {n}; message = {message}");
            });

            _logger.Log("End");
        }
예제 #3
0
        public void Case1_b()
        {
            var text = @"app PeaceKeeper
{
    {: see(I, #`gun 1`) :}

	on {: see(I, #`gun 1`) :} => 
    {
	    'D' >> @>log;
	}
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) =>
            {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message.Contains("D"), true);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }
예제 #4
0
        public void Case3()
        {
            var text = @"app PeaceKeeper
{
    {: barrel(#a) :}
    {: see(I, #a) :}

    on {: see(I, $x) & barrel($x) & !focus(I, friend) :} => 
    {
         @x >> @>log;
    }
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) =>
            {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message, "NULL");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }
예제 #5
0
        public void Case2_a()
        {
            var text = @"app PeaceKeeper
{
    fun a(@param_1) =>
    {
        '`a` has been called!' >> @>log;
        @param_1 >> @>log;

        error {: see(I, #a) :};

        'End of `a`' >> @>log;
    }

    on Init =>
    {
        try
        {
            'Begin' >> @>log;
            a(param_1: 1);
            'End' >> @>log;        
        }
        catch
        {
            'catch' >> @>log;
        }

        'End of `Init`' >> @>log;
    }
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) => {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message, "Begin");
                    break;

                case 2:
                    Assert.AreEqual(message, "`a` has been called!");
                    break;

                case 3:
                    Assert.AreEqual(message, "1");
                    break;

                case 4:
                    Assert.AreEqual(message, "catch");
                    break;

                case 5:
                    Assert.AreEqual(message, "End of `Init`");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }
예제 #6
0
        public void Case12_b()
        {
            var text = @"app PeaceKeeper
{
    fun a(@param_1)
    {
        '`a` (any) has been called!' >> @>log;
        @param_1 >> @>log;
    }

    fun a(@param_1: number | string)
    {
        '`a` (number | string) has been called!' >> @>log;
        @param_1 >> @>log;
    }

    on Init =>
    {
        'Begin' >> @>log;
        a(param_1: 1);
        a(param_1: 'Hi');
        'End' >> @>log;
    }
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) => {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message, "Begin");
                    break;

                case 2:
                    Assert.AreEqual(message, "`a` (number | string) has been called!");
                    break;

                case 3:
                    Assert.AreEqual(message, "1");
                    break;

                case 4:
                    Assert.AreEqual(message, "`a` (number | string) has been called!");
                    break;

                case 5:
                    Assert.AreEqual(message, "Hi");
                    break;

                case 6:
                    Assert.AreEqual(message, "End");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }
예제 #7
0
        public void Case11_b()
        {
            var text = @"app PeaceKeeper
{
    on Init =>
    {
        try
        {
            'Begin' >> @>log;
            'End' >> @>log;        
        }
        else
        {
            'else' >> @>log;
        }
        ensure
        {
            'ensure' >> @>log;
        }

        'End of `Init`' >> @>log;
    }
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) => {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message, "Begin");
                    break;

                case 2:
                    Assert.AreEqual(message, "End");
                    break;

                case 3:
                    Assert.AreEqual(message, "else");
                    break;

                case 4:
                    Assert.AreEqual(message, "ensure");
                    break;

                case 5:
                    Assert.AreEqual(message, "End of `Init`");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }
예제 #8
0
        public void Case6()
        {
            var text = @"app PeaceKeeper
{
    fun a(@param_1)
    {
        '`a` (1) has been called!' >> @>log;
        @param_1 >> @>log;
    }

    fun a(@param_1, @param_2)
    {
        '`a` (2) has been called!' >> @>log;
        @param_1 >> @>log;
        @param_2 >> @>log;
    }

    on Init =>
    {
        'Begin' >> @>log;
        @param_1 = 12;

        a(@param_1);
        'End' >> @>log;
    }
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) => {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message, "Begin");
                    break;

                case 2:
                    Assert.AreEqual(message, "`a` (1) has been called!");
                    break;

                case 3:
                    Assert.AreEqual(message, "12");
                    break;

                case 4:
                    Assert.AreEqual(message, "End");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }
예제 #9
0
        public void Case1()
        {
            var text = @"app PeaceKeeper is [0.5] exampleClass
{
    on Init =>
    {
        'Begin' >> @>log;
        exampleClass is human >> @>log;
        exampleClass is not human >> @>log;
        use exampleClass is [0.5] human;
        exampleClass is human >> @>log;
        exampleClass is not human >> @>log;
        use exampleClass is not human;
        exampleClass is human >> @>log;
        exampleClass is not human >> @>log;
        use @@self is linux;
        @@self is linux >> @>log;
        'End' >> @>log;
    }
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) =>
            {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message, "Begin");
                    break;

                case 2:
                    Assert.AreEqual(message, "0");
                    break;

                case 3:
                    Assert.AreEqual(message, "1");
                    break;

                case 4:
                    Assert.AreEqual(message, "0.5");
                    break;

                case 5:
                    Assert.AreEqual(message, "0.5");
                    break;

                case 6:
                    Assert.AreEqual(message, "0");
                    break;

                case 7:
                    Assert.AreEqual(message, "1");
                    break;

                case 8:
                    Assert.AreEqual(message, "1");
                    break;

                case 9:
                    Assert.AreEqual(message, "End");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }
예제 #10
0
        public void Case3()
        {
            var text = @"linvar logic for range [0, 1]
{
    constraints:
	    for inheritance;

	terms:
		minimal = L(0, 0.1);
		low = Trapezoid(0, 0.05, 0.3, 0.45);
		middle = Trapezoid(0.3, 0.4, 0.6, 0.7);
		high = Trapezoid(0.55, 0.7, 0.95, 1);
		maximal = S(0.9, 1);
}

app PeaceKeeper is [very middle] exampleClass
{
    on Init =>
    {
        'Begin' >> @>log;
        exampleClass is human >> @>log;
        exampleClass is not human >> @>log;
        use exampleClass is [very middle] human;
        exampleClass is human >> @>log;
        exampleClass is not human >> @>log;
        use exampleClass is not human;
        exampleClass is human >> @>log;
        exampleClass is not human >> @>log;
        use @@self is linux;
        @@self is linux >> @>log;
        'End' >> @>log;
    }
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) =>
            {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message, "Begin");
                    break;

                case 2:
                    Assert.AreEqual(message, "0");
                    break;

                case 3:
                    Assert.AreEqual(message, "1");
                    break;

                case 4:
                    Assert.AreEqual(message, "0.5");
                    break;

                case 5:
                    Assert.AreEqual(message, "0.5");
                    break;

                case 6:
                    Assert.AreEqual(message, "0");
                    break;

                case 7:
                    Assert.AreEqual(message, "1");
                    break;

                case 8:
                    Assert.AreEqual(message, "1");
                    break;

                case 9:
                    Assert.AreEqual(message, "End");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }
예제 #11
0
        public void Case7()
        {
            var text = @"app PeaceKeeper
{
    fun a(@param_1) =>
    {
        '`a` has been called!' >> @>log;
        @param_1 >> @>log;

        error {: see(I, #a) :};

        'End of `a`' >> @>log;
    }

    on Init =>
    {
        try
        {
            'Begin' >> @>log;
            a(param_1: 1);
            'End' >> @>log;        
        }
        catch
        {
            'catch' >> @>log;
        }
        catch(@e)
        {
            'catch(@e)' >> @>log;
            @e >> @>log;
        }
        catch(@e) where {: hit(enemy, I) :}
        {
            'catch(@e) where {: hit(enemy, I) :}' >> @>log;
        }
        catch(@e) where {: see(I, $x) :}
        {
            'catch(@e) where {: see(I, $x) :}' >> @>log;
            @e >> @>log;
        }
        else
        {
            'else' >> @>log;
        }
        ensure
        {
            'ensure' >> @>log;
        }

        'End of `Init`' >> @>log;
    }
}";

            Assert.AreEqual(BehaviorTestEngineInstance.Run(text,
                                                           (n, message) => {
                switch (n)
                {
                case 1:
                    Assert.AreEqual(message, "Begin");
                    break;

                case 2:
                    Assert.AreEqual(message, "`a` has been called!");
                    break;

                case 3:
                    Assert.AreEqual(message, "1");
                    break;

                case 4:
                    Assert.AreEqual(message, "catch(@e) where {: see(I, $x) :}");
                    break;

                case 5:
                    Assert.AreEqual(true, message.Contains("ERROR:"));
                    Assert.AreEqual(true, message.Contains("{:"));
                    Assert.AreEqual(true, message.Contains("see(i,#a)"));
                    Assert.AreEqual(true, message.Contains(":}"));
                    break;

                case 6:
                    Assert.AreEqual(message, "ensure");
                    break;

                case 7:
                    Assert.AreEqual(message, "End of `Init`");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(n), n, null);
                }
            }), true);
        }