public void TestLibrary() { Assert.AreEqual(TruStatement.Interpret("{nor true true}"), new TruBool(false)); Assert.AreEqual(TruStatement.Interpret("{xor true true}"), new TruBool(false)); Assert.AreEqual(TruStatement.Interpret("{xnor false false}"), new TruBool(true)); Assert.AreEqual(TruStatement.Interpret("{implies true false}"), new TruBool(false)); Assert.AreEqual(TruStatement.Interpret("{majority true false false}"), new TruBool(false)); }
public void TestBuiltIns() { Assert.AreEqual(TruStatement.Interpret("{nand true true}"), new TruBool(false)); Assert.AreEqual(TruStatement.Interpret("{and true true}"), new TruBool(true)); Assert.AreEqual(TruStatement.Interpret("{or false false}"), new TruBool(false)); Assert.AreEqual(TruStatement.Interpret("{not true}"), new TruBool(false)); Assert.AreEqual(TruStatement.Interpret("{equals true true}"), new TruBool(true)); Assert.AreEqual(TruStatement.Interpret("{equals {lambda {} true} {lambda {} true}}"), new TruBool(false)); Assert.AreEqual(TruStatement.Interpret("{let {[f {lambda {} true}]} {equals f f}}"), new TruBool(true)); Assert.AreEqual(TruStatement.Interpret("{if true true false}"), new TruBool(true)); Assert.AreEqual(TruStatement.Interpret("{and false {lambda {} true}}"), new TruBool(false)); // Short circuit evaluation Assert.ThrowsException <TruRuntimeException>(() => TruStatement.Interpret("{and true {lambda {} true}}")); }
public void TestTruEquals() { Assert.IsTrue(new TruBool(true).Equals(new TruBool(true))); Assert.IsFalse(new TruBool(true).Equals(new TruBool(false))); Assert.IsFalse(new TruBool(true).Equals(null)); Assert.IsTrue(new TruId("x").Equals(new TruId("x"))); Assert.IsFalse(new TruId("x").Equals(new TruId("t"))); Assert.IsTrue(TruLibrary.Library.Find("and").Equals(TruLibrary.Library.Find("and"))); Assert.IsFalse(TruLibrary.Library.Find("and").Equals(TruLibrary.Library.Find("or"))); TruLambda lamb0 = new TruLambda(new string[] { "x" }, new TruId("x")); TruLambda lamb1 = new TruLambda(new string[] { "x" }, new TruId("x")); TruLambda lamb2 = new TruLambda(new string[] {}, new TruId("x")); TruLambda lamb3 = new TruLambda(new string[] { "y" }, new TruId("x")); TruLambda lamb4 = new TruLambda(new string[] { "x" }, new TruId("y")); Assert.IsTrue(lamb0.Equals(lamb1)); Assert.IsFalse(lamb0.Equals(lamb2)); Assert.IsFalse(lamb0.Equals(lamb3)); Assert.IsFalse(lamb0.Equals(lamb4)); TruCall call0 = new TruCall(new TruId("and"), new TruExpr[] { new TruBool(true), new TruCall(new TruId("not"), new TruExpr[] { new TruBool(false) }) }); TruCall call1 = new TruCall(new TruId("and"), new TruExpr[] { new TruBool(true), new TruCall(new TruId("not"), new TruExpr[] { new TruBool(false) }) }); TruCall call2 = new TruCall(new TruId("and"), new TruExpr[] { new TruBool(true), new TruCall(new TruId("not"), new TruExpr[] { new TruBool(true) }) }); TruCall call3 = new TruCall(new TruId("nand"), new TruExpr[] { new TruBool(true), new TruCall(new TruId("not"), new TruExpr[] { new TruBool(false) }) }); Assert.IsTrue(call0.Equals(call1)); Assert.IsFalse(call0.Equals(call2)); Assert.IsFalse(call0.Equals(call3)); TruExpr let0 = TruExpr.Parse("{let {[a false]} a}"); TruExpr let1 = TruExpr.Parse("{let {[a false]} a}"); TruExpr let2 = TruExpr.Parse("{let {} true}"); Assert.IsTrue(let0.Equals(let1)); Assert.IsFalse(let0.Equals(let2)); TruStatement def0 = TruStatement.Parse("{define x true}"); TruStatement def1 = TruStatement.Parse("{define x true}"); TruStatement def2 = TruStatement.Parse("{define x false}"); Assert.IsTrue(def0.Equals(def1)); Assert.IsFalse(def0.Equals(def2)); }