def test_and_3(self): wff = "Person(A) & Person(B)" expr = And(Predicate("Person", [Const("A")]), Predicate("Person", [Const("B")])) tree = FoplParser.parse(wff) self.assertEqual(tree.expr, expr) self.assertEqual(tree.constants, ["A", "B"])
def test_complex_4(self): wff = "P(A)|P(B)&P(C)|P(D)" expr = Or( Or(Predicate("P", [Const("A")]), And(Predicate("P", [Const("B")]), Predicate("P", [Const("C")]))), Predicate("P", [Const("D")])) tree = FoplParser.parse(wff) self.assertEqual(tree.expr, expr) self.assertEqual(tree.constants, ["A", "B", "C", "D"])
def test_complex_2(self): wff = "(A)a,b (E)c (Person(a)&Person(b)&Person(c)&Parent(a,b)&Parent(b,c)->Grandparent(a,c))" expr = AllQuantor( Var("a"), AllQuantor( Var("b"), ExistentialQuantor( Var("c"), Impl( And( And( And( And(Predicate("Person", [Var("a")]), Predicate("Person", [Var("b")])), Predicate("Person", [Var("c")])), Predicate("Parent", [Var("a"), Var("b")])), Predicate("Parent", [Var("b"), Var("c")])), Predicate("Grandparent", [Var("a"), Var("c")]))))) tree = FoplParser.parse(wff) self.assertEqual(tree.expr, expr)
def test_complex_1(self): wff = "(A)a (E)b (Person(a)&Person(b)->Parent(a,b))" expr = AllQuantor( Var("a"), ExistentialQuantor( Var("b"), Impl( And(Predicate("Person", [Var("a")]), Predicate("Person", [Var("b")])), Predicate("Parent", [Var("a"), Var("b")])))) tree = FoplParser.parse(wff) self.assertEqual(tree.expr, expr)
def test_complex_3(self): wff = "(P(A)->K(f(A,B))&P(C))<->!(E(C,D)|K(A))" expr = Eq( Impl( Predicate("P", [Const("A")]), And(Predicate("K", [Func("f", [Const("A"), Const("B")])]), Predicate("P", [Const("C")]))), Not( Or(Predicate("E", [Const("C"), Const("D")]), Predicate("K", [Const("A")])))) tree = FoplParser.parse(wff) self.assertEqual(tree.expr, expr) self.assertEqual(tree.constants, ["A", "B", "C", "D"])
def test_complex_5(self): wff = "(A)a (P(a)->K(f(a,B))&P(C)<->!(E(C,D)|K(a)))" expr = AllQuantor( Var("a"), Eq( Impl( Predicate("P", [Var("a")]), And(Predicate("K", [Func("f", [Var("a"), Const("B")])]), Predicate("P", [Const("C")]))), Not( Or(Predicate("E", [Const("C"), Const("D")]), Predicate("K", [Var("a")]))))) tree = FoplParser.parse(wff) self.assertEqual(tree.expr, expr) self.assertEqual(tree.constants, ["B", "C", "D"])