public void RaiseIfArityIsWrong() { Context context = new Context(); FunctionForm form1 = this.MakeForm("f(0) -> 1."); FunctionForm form2 = this.MakeForm("f(1) -> 1."); FunctionForm form3 = this.MakeForm("f(X, Y) -> f(X-1) + f(X-2)."); MultiFunctionForm mform = new MultiFunctionForm(new FunctionForm[] { form1, form2, form3 }); try { mform.Evaluate(context); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual("head mismatch", ex.Message); } }
public void EvaluateWithOneForm() { Context context = new Context(); FunctionForm form = this.MakeForm("f(0) -> 1."); MultiFunctionForm mform = new MultiFunctionForm(new FunctionForm[] { form }); var result = mform.Evaluate(context); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(MultiFunction)); var mfunc = (MultiFunction)result; Assert.IsNotNull(mfunc.Functions); Assert.AreEqual(1, mfunc.Functions.Count); var defined = context.GetValue("f/1"); Assert.IsNotNull(defined); Assert.IsInstanceOfType(defined, typeof(MultiFunction)); Assert.AreSame(mfunc, defined); }