Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            BehaviourScript script = new BehaviourScript();

            script.Parse(s);
            script.Interpreter.PreVisit();
            script.Interpreter.EnterBlockNode("Start");
        }
Exemplo n.º 2
0
        public void ConditionTest_1()
        {
            BehaviourScript script = new BehaviourScript();

            ScriptException ex = Assert.Throws <ScriptException>(() => script.Parse(script_5));

            Assert.That(ex.Message, Is.EqualTo("Parsing Error: Unexpected Token: ELSEIF at 12.18"));

            Assert.Pass();
        }
Exemplo n.º 3
0
        public void ConditionTest_2()
        {
            double d = 0;

            d = GetValueFromInput("10");
            Assert.True(d == 1);

            d = GetValueFromInput("5");
            Assert.True(d == 2);

            d = GetValueFromInput("20");
            Assert.True(d == 3);

            d = GetValueFromInput("41");
            Assert.True(d == 4);

            d = GetValueFromInput("40");
            Assert.True(d == 5);

            Assert.Pass();

            double GetValueFromInput(string input)
            {
                string script_6 = $@"
               
                double d = {input};

                [Start]
                    if(d == 10) then
                        d = 1;
                    elif(d < 10) then
                        d = 2;
                    elif(d == 20) then
                        d = 3;
                    elif(d > 40) then
                        d = 4;
                    else
                        d = 5;
                    end
                end
            ";

                BehaviourScript script = new BehaviourScript();

                script.Parse(script_6);
                script.Interpreter.PreVisit();
                script.Interpreter.EnterBlockNode("Start");
                return(((DoubleValue)script.Interpreter.Current["d"]).Value);
            }
        }
Exemplo n.º 4
0
        public void Test2()
        {
            BehaviourScript script = new BehaviourScript();

            script.Parse(script_2);
            script.Interpreter.PreVisit();

            double d  = ((DoubleValue)script.Interpreter.Current["d"]).Value;
            double d1 = ((DoubleValue)script.Interpreter.Current["d1"]).Value;
            double d2 = ((DoubleValue)script.Interpreter.Current["d2"]).Value;
            double d3 = ((DoubleValue)script.Interpreter.Current["d3"]).Value;

            Assert.IsTrue(d == 103);
            Assert.IsTrue(d1 == 160);
            Assert.IsTrue(d2 == 400);
            Assert.IsTrue(d3 == 800);

            Assert.Pass();
        }