Пример #1
0
        public static void perf()
        {
            EnzymeDynamicContext dfp = new EnzymeDynamicContext();

            var rv = new EnzymeEngine(dfp);

            rv.Evaluate("$total = 0");

            double total = 0.0;

            double d = Environment.TickCount;

            for (int i = 0; i < 1000; i++)
            {
                total = total + 1;
                Console.WriteLine(total);
            }
            d = Environment.TickCount - d;

            double e = Environment.TickCount;
            for (int i = 0; i < 1000; i++)
            {
                rv.Evaluate("$total=$total+1");
                Console.WriteLine(dfp.GetFieldValue("total"));
            }
            e = Environment.TickCount - e;

            double pf = ((e - d) / e) * 100.0;
            Console.WriteLine("Performance loss: {0}", pf);
            Console.ReadLine();

        }
Пример #2
0
        public void ParseToTokensTest()
        {
            EnzymeEngine target = new EnzymeEngine(null); // TODO: Initialize to an appropriate value

            string codeLine = "If $21 == 001 AND $23 == 01 AND $27 == 001 THEN ($14 == 1 OR $15 == 6) AND ($12==3 OR $24==\"hello\")";

            Token actual = target.ParseToTokens(codeLine);

            Assert.AreEqual<Type>(typeof(IfWordToken), actual[0].TokenClassType);
            Assert.AreEqual<Type>(typeof(SymbolicToken), actual[1].TokenClassType);
            Assert.AreEqual<Type>(typeof(EqualityToken), actual[2].TokenClassType);
            Assert.AreEqual<Type>(typeof(NumberToken), actual[3].TokenClassType);
            Assert.AreEqual<Type>(typeof(AndWordToken), actual[4].TokenClassType);

            
        }
Пример #3
0
        static void Main(string[] args)
        {

            IEnzymeContext dfp = new TestingContext();

            var rv = new EnzymeEngine(dfp);

            StreamReader sr = new StreamReader("test.txt");

            while(!sr.EndOfStream)
            {
                string pp = sr.ReadLine().Trim();
                if (!string.IsNullOrEmpty(pp))
                    Console.WriteLine(rv.Evaluate(pp));
            }
        }
Пример #4
0
        public void EvaluateTest()
        {
            IEnzymeContext fieldsProvider = new EnzymeStaticContext(); // TODO: Initialize to an appropriate value
            EnzymeEngine target = new EnzymeEngine(fieldsProvider); // TODO: Initialize to an appropriate value
            
            string codeLine = "if $8 == 4+5 then 10 else 2*10";

            object expected = 20.0;
            object actual;
            
            actual = target.Evaluate(codeLine);


            Assert.AreEqual(expected, actual);
            
        }
Пример #5
0
        public void MoreEvalute()
        {
            IEnzymeContext fpr = new EnzymeDynamicContext();

            EnzymeEngine engine = new EnzymeEngine(fpr);

            Debug.Print(engine.Evaluate("$r1 = 20").ToString());
            Debug.Print(engine.Evaluate("$r2 = 12").ToString());

            double d = (double)engine.Evaluate("$R = ($r1*$r2)/($r1+$r2)");


            Assert.AreEqual(d, 7.5);

        }