Ejemplo n.º 1
0
        public void BoolArrayInitTest()
        {
            var context = new Context();
            var interpretator = new VariableInterpretator(context);

            var expressionString = "bool[] a = new bool[2];";
            interpretator.Run(expressionString);
            Assert.AreEqual(false, (context.Lookup("a").Value as bool[])[0]);
            Assert.AreEqual(false, (context.Lookup("a").Value as bool[])[1]);
            try
            {
                var errorVariable = (context.Lookup("a").Value as bool[])[2];
                Assert.Fail();
            }
            catch (IndexOutOfRangeException ex)
            {
            }
        }
Ejemplo n.º 2
0
        public void AccessVariableAfterInit()
        {
            var context = new Context();
            var interpretatorRegion = new RegionInterpretator(context);

            var expressionString = "int a = 0;" +
                                   "a = 54-33;" +
                                   "real b = 0;" +
                                   "b = 154.26/4.12+15*a-151;" +
                                   "bool c = false;" +
                                   "c = (b >= 4) && (a == 21) && (\"Apple\" == \"Apple\");" +
                                   "string pinkie = \"\";" +
                                   "pinkie =  \"Pinkie Pie\";" +
                                   "string s = pinkie + \" is coolest pony\";";
            interpretatorRegion.Run(expressionString);
            Assert.AreEqual(54 - 33, (int)context.Lookup("a").Value);
            Assert.AreEqual(154.26 / 4.12 + 15 * (54 - 33) - 151, (double)context.Lookup("b").Value);
            Assert.AreEqual((154.26 / 4.12 + 15 * (54 - 33) - 151 >= 4) && (54 - 33 == 21) && ("Apple" == "Apple"), (bool)context.Lookup("c").Value);
            Assert.AreEqual("Pinkie Pie is coolest pony", (string)context.Lookup("s").Value);
        }
Ejemplo n.º 3
0
        public void MultiInitVariableTest()
        {
            var context = new Context();
            var interpretatorRegion = new RegionInterpretator(context);

            var expressionString = "int a = 54-33;" +
                                   "real b = 154.26/4.12+15*(15.12*45.87)-151;" +
                                   "bool c = (5 >= 4) && (5*4 != 21) && (\"Apple\" == \"Apple\");"+
                                   "string s = \"Pinkie Pie\" + \" is coolest pony\";";

            interpretatorRegion.Run(expressionString);
            Assert.AreEqual(54 - 33, (int)context.Lookup("a").Value);
            Assert.AreEqual(154.26 / 4.12 + 15 * (15.12 * 45.87) - 151, (double)context.Lookup("b").Value);
            Assert.AreEqual((5 >= 4) && (5 * 4 != 21) && ("Apple" == "Apple"), (bool)context.Lookup("c").Value);
            Assert.AreEqual("Pinkie Pie is coolest pony", (string)context.Lookup("s").Value);
        }