public void TestFreeVariables() { SortedSet <string> variables; LogicExpression test = new NumExists("n", n == m); FreeVariableLister lister = new FreeVariableLister(); variables = test.Accept(lister); Assert.AreEqual(1, variables.Count); Assert.IsTrue(variables.Contains("m")); test = new NumExists("x", n == n); lister = new FreeVariableLister(); variables = test.Accept(lister); Assert.AreEqual(1, variables.Count); Assert.IsTrue(variables.Contains("n")); test = (new NumThe("n", n == two)) == two; lister = new FreeVariableLister(); variables = test.Accept(lister); Assert.AreEqual(0, variables.Count); //Assert.IsTrue(lister.Variables.Contains("n")); // this test shows that the original method does not work test = n == n & new NumExists("n", n == two); lister = new FreeVariableLister(); variables = test.Accept(lister); Assert.AreEqual(1, variables.Count); }
public void TestSubstitution() { var subst = new VariableSubstituter("n", two); var result = n.Accept(subst); Assert.AreEqual("2", testAsync(result, 200).Result); result = zero.Accept(subst); Assert.AreEqual("0", testAsync(result, 200).Result); var exists = new NumExists("n", n == n); result = exists.Accept(subst); Assert.AreEqual(True, testAsync(result, 200).Result); var test = new Apply(new LambdaExpression("n", n == n), two); Assert.AreEqual(True, testAsync(test, 200).Result); // test that substitution avoids explosions var test2 = new Apply(new LambdaExpression("x", logicTrue), logicLoop); Assert.AreEqual(True, testAsync(test2, 200).Result); var test3 = new Apply(new LambdaExpression("x", logicLoop), logicTrue); Assert.AreEqual(Loop, testAsync(test3, 500).Result); var test4 = new Apply(new LambdaExpression("x", x & logicTrue), logicLoop); Assert.AreEqual(Loop, testAsync(test4, 500).Result); var test5 = new Apply(new LambdaExpression("x", x | logicTrue), logicLoop); Assert.AreEqual(True, testAsync(test5, 500).Result); }
public T Visit(NumExists expression) { expression.Accept(this); return(default(T)); }