Esempio n. 1
0
        public void TestMethodSimpleAllOp1()
        {
            ResetTestState();
            Console.WriteLine(MethodBase.GetCurrentMethod().Name);

            List <Tuple <string, double> > lst = new List <Tuple <string, double> >();

            lst.Add(new Tuple <string, double>("var1", 3));
            lst.Add(new Tuple <string, double>("var2", 4));

            CExpression exp = CExpressionBuilder.Build("1 / 2 + var1 * var2 - 5.5 + 4^(1/2)", this);

            exp.SetArgIds(name =>
            {
                return(lst.FindIndex(t => t.Item1 == name));
            });

            double res = exp.GetValue(
                (int id, out double value) =>
            {
                value = 0;
                if (id < 0)
                {
                    return(false);
                }

                value = lst[id].Item2;
                return(true);
            },
                this);

            CheckInternalErrors();
            Assert.AreEqual(res, 9);
        }
Esempio n. 2
0
        public void TestMethodSimpleSumI()
        {
            ResetTestState();
            Console.WriteLine(MethodBase.GetCurrentMethod().Name);

            CExpression exp = CExpressionBuilder.Build("1.1 + 2 + var1", this);

            exp.SetArgIds(name => 0);

            double res = exp.GetValue(
                (int id, out double value) =>
            {
                value = 3;
                return(true);
            },
                this);

            CheckInternalErrors();
            Assert.AreEqual(res, 6.1);
        }