public void CreateListWithVariableAsTail() { Context context = new Context(); var expr = new ListExpression(new IExpression[] { new ConstantExpression(1), new ConstantExpression(2) }, new VariableExpression(new Variable("Tail"))); var result = expr.Evaluate(context, true); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(List)); Assert.AreEqual("[1,2|Tail]", result.ToString()); }
public void CreateListWithTail() { Context context = new Context(); var list = List.MakeList(new object[] { 3, 4 }); context.SetValue("Tail", list); var expr = new ListExpression(new IExpression[] { new ConstantExpression(1), new ConstantExpression(2) }, new VariableExpression(new Variable("Tail"))); var result = expr.Evaluate(context); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(List)); Assert.AreEqual("[1,2,3,4]", result.ToString()); }
public void CreateSimpleList() { Context context = new Context(); var expr = new ListExpression(new IExpression[] { new ConstantExpression(1), new AtomExpression(new Atom("x")), new AtomExpression(new Atom("y")) }); Assert.IsFalse(expr.HasVariable()); var result = expr.Evaluate(context, true); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(List)); var list = (List)result; Assert.IsNotNull(list.Head); Assert.IsNotNull(list.Tail); Assert.AreEqual("[1,x,y]", list.ToString()); }
public void RaiseWhenUnboundVariable() { Context context = new Context(); var expr = new ListExpression(new IExpression[] { new ConstantExpression(1), new VariableExpression(new Variable("X")), new AtomExpression(new Atom("y")) }); Assert.IsTrue(expr.HasVariable()); try { expr.Evaluate(context, false); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual("variable 'X' is unbound", ex.Message); } }
public void RaiseIfUnboundVariableAsTail() { Context context = new Context(); var expr = new ListExpression(new IExpression[] { new ConstantExpression(1), new ConstantExpression(2) }, new VariableExpression(new Variable("Tail"))); try { expr.Evaluate(context, false); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual("variable 'Tail' is unbound", ex.Message); } }