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 TestLambdas() { SortedSet <string> variables; var test = new LambdaExpression("x", x); VariableLister <bool> lister = new VariableLister <bool>(); test.Accept(lister); Assert.AreEqual(1, lister.Variables.Count); Assert.IsTrue(lister.Variables.Contains("x")); test = new LambdaExpression("x", x); FreeVariableLister freeLister = new FreeVariableLister(); variables = test.Accept(freeLister); Assert.AreEqual(0, variables.Count); test = new LambdaExpression("x", logicLoop); freeLister = new FreeVariableLister(); variables = test.Accept(freeLister); Assert.AreEqual(0, variables.Count); }