예제 #1
0
파일: EvalTest.cs 프로젝트: rincewound/VCal
 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
파일: EvalTest.cs 프로젝트: rincewound/VCal
 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
파일: EvalTest.cs 프로젝트: rincewound/VCal
        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);
        }
예제 #4
0
 public void RegFunc(string name, BuiltInFunctionResolver.FunctionCall call)
 {
     RegisterResolver(name, new BuiltInFunctionResolver(call, this));
 }