示例#1
0
 public void FuncEval_NoParameter_EvaulatesCorrectly()
 {
     BuiltInFunctionResolver.FunctionCall fc = ((x, y) => 4);
     var funcRes = new BuiltInFunctionResolver(fc, vt);
     vt.RegisterResolver("Test", funcRes);       //Register the function defined above as "Sqrt"
     var theTerm = tp.Parse("Test()");
     var result = theTerm.Eval(vt);
     Assert.AreEqual(4, result);
 }
示例#2
0
 public void FuncEval_SingleParameter_EvaluatesCorrectly()
 {
     BuiltInFunctionResolver.FunctionCall fc = ((x, y) => (float)Math.Sqrt(((float)x[0].Eval(vt))));
     var funcRes = new BuiltInFunctionResolver(fc, vt);
     vt.RegisterResolver("Sqrt", funcRes);       //Register the function defined above as "Sqrt"
     var theTerm = tp.Parse("Sqrt(9)");
     var result = theTerm.Eval(vt);
     Assert.AreEqual(3, (float)result);
 }
示例#3
0
        public void FuncEval_MultipleParams_EvaluatesCorrectly()
        {
            BuiltInFunctionResolver.FunctionCall sqrt = ((x, y) => (float)Math.Sqrt(((float)x[0].Eval(vt))));
            var funcRes = new BuiltInFunctionResolver(sqrt, vt);
            vt.RegisterResolver("Sqrt", funcRes);       //Register the function defined above as "Sqrt"

            BuiltInFunctionResolver.FunctionCall pow = ((x, y) => (float)Math.Pow((float)x[0].Eval(vt), (float)x[1].Eval(vt)));
            var fr = new BuiltInFunctionResolver(pow, vt);
            vt.RegisterResolver("Pow", fr);       //Register the function defined above as "Pow"
            var theTerm = tp.Parse("Pow(4, Sqrt(4))");
            var result = theTerm.Eval(vt);
            Assert.AreEqual(16, (float)result);
        }