public Evaluate ( Context context, bool withvars = false ) : object | ||
context | Context | |
withvars | bool | |
Результат | object |
public void EvaluateWithThreeExpressions() { Context context = new Context(); FunExpression expr1 = this.MakeExpression("fun(0) -> 1 end."); FunExpression expr2 = this.MakeExpression("fun(1) -> 1 end."); FunExpression expr3 = this.MakeExpression("fun(X) -> f(X-1) + f(X-2) end."); MultiFunExpression mexpr = new MultiFunExpression(new FunExpression[] { expr1, expr2, expr3 }); var result = mexpr.Evaluate(context); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(MultiFunction)); var mfunc = (MultiFunction)result; Assert.IsNotNull(mfunc.Functions); Assert.AreEqual(3, mfunc.Functions.Count); }
public void RaiseIfArityIsWrong() { Context context = new Context(); FunExpression expr1 = this.MakeExpression("fun(0) -> 1 end."); FunExpression expr2 = this.MakeExpression("fun(1) -> 1 end."); FunExpression expr3 = this.MakeExpression("fun(X, Y) -> f(X-1) + f(X-2) end."); MultiFunExpression mexpr = new MultiFunExpression(new FunExpression[] { expr1, expr2, expr3 }); try { mexpr.Evaluate(context); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual("head mismatch", ex.Message); } }
public void EvaluateWithOneExpression() { Context context = new Context(); FunExpression expr = this.MakeExpression("fun(0) -> 1 end."); MultiFunExpression mexpr = new MultiFunExpression(new FunExpression[] { expr }); Assert.IsFalse(mexpr.HasVariable()); var result = mexpr.Evaluate(context); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(MultiFunction)); var mfunc = (MultiFunction)result; Assert.IsNotNull(mfunc.Functions); Assert.AreEqual(1, mfunc.Functions.Count); }