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

            CExpression exp = CExpressionBuilder.Build("Min(3, 2) * (Neg(var1) + 4)", this);

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

            CheckInternalErrors();
            Assert.AreEqual(res, 2);

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

            CheckInternalErrors();
            Assert.AreEqual(res, 14);
        }
Esempio n. 2
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. 3
0
        public void TestMethodOneInternalFunc1()
        {
            ResetTestState();
            Console.WriteLine(MethodBase.GetCurrentMethod().Name);

            CExpression exp = CExpressionBuilder.Build("Round(3.1)", this);

            double res = exp.GetValue(this);

            CheckInternalErrors();
            Assert.AreEqual(res, 3);
        }
Esempio n. 4
0
        public void TestMethodBracers()
        {
            ResetTestState();
            Console.WriteLine(MethodBase.GetCurrentMethod().Name);

            CExpression exp = CExpressionBuilder.Build("(1 + 2) * ((3 + 4) - (5 + 1))", this);

            double res = exp.GetValue(this);

            CheckInternalErrors();
            Assert.AreEqual(res, 3);
        }
Esempio n. 5
0
        public void TestMethodOneInternalFunc3()
        {
            ResetTestState();
            Console.WriteLine(MethodBase.GetCurrentMethod().Name);

            CExpression exp = CExpressionBuilder.Build("Rand(1,100)", this);

            double res = exp.GetValue(this);

            CheckInternalErrors();

            Assert.IsTrue(res >= 1 && res <= 100);
        }
Esempio n. 6
0
        public void TestMethodOneInternalFunc2()
        {
            ResetTestState();
            Console.WriteLine(MethodBase.GetCurrentMethod().Name);

            CExpression exp = CExpressionBuilder.Build("Min(3, 2) * (Neg(var1) + 4)", this);

            Dictionary <string, double> dic = new Dictionary <string, double>();

            dic.Add("var1", 3);

            double res = exp.GetValue(dic.TryGetValue, this);

            CheckInternalErrors();
            Assert.AreEqual(res, 2);

            dic["var1"] = -3;
            res         = exp.GetValue(dic.TryGetValue, this);

            CheckInternalErrors();
            Assert.AreEqual(res, 14);
        }
Esempio n. 7
0
        public void TestMethodSimpleSum()
        {
            ResetTestState();
            Console.WriteLine(MethodBase.GetCurrentMethod().Name);

            Dictionary <string, double> dic = new Dictionary <string, double>();

            dic.Add("var1", 3);

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

            double res = exp.GetValue(dic.TryGetValue, this);

            CheckInternalErrors();
            Assert.AreEqual(res, 6.1);
        }
Esempio n. 8
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);
        }