def test_non_equality(self): statement_a = Symbol('a') statement_b = Symbol('b') statement_and = And(statement_a, statement_b) statement_or = Or(statement_and, statement_b) self.assertNotEqual(statement_or, Or(And(Symbol('a'), Symbol('b')), Symbol('a')))
def test_convert_to_cnf(self): statement = Not(Iff(Symbol("a"), Symbol("c"))) statement = converter.convert_formula(statement) a_symbol = Symbol("a") c_symbol = Symbol("c") expected = And( And(Or(c_symbol, a_symbol), Or(Not(a_symbol), a_symbol)), And(Or(c_symbol, Not(c_symbol)), Or(Not(a_symbol), Not(c_symbol)))) self.assertEqual(expected, statement)
def test_equality(self): statement_a = Symbol('a') statement_b = Symbol('b') statement_and = And(statement_a, statement_b) statement_or = Or(statement_and, statement_a) statement_if = If(statement_or, statement_and) statement_iff = Iff(statement_if, statement_a) expected = Iff( If(Or(And(Symbol("a"), Symbol("b")), Symbol("a")), And(Symbol("a"), Symbol("b"))), Symbol("a")) self.assertTrue(expected == statement_iff) self.assertEqual(repr(expected), repr(statement_iff)) self.assertEqual(str(expected), str(statement_iff))
def test_and(self): statement_a = Symbol('a') statement_b = Symbol('b') statement_and = And(statement_a, statement_b) self.assertEqual(statement_and.arity, 2) self.assertEqual(repr(statement_and), "and(a, b)") self.assertEqual(str(statement_and), "(a & b)")
def test_parse_fol_1(self): Predicate.reset() Herbrand.reset() Skolem.reset() statement = parser.parse("forall(x,if(A(x),and(B(x),C(x))))") expected = Universal(Symbol("x"), If(Predicate("A", [Symbol("x")]), And(Predicate("B", [Symbol("x")]), Predicate("C", [Symbol("x")])))) self.assertEqual(expected, statement)
def test_complex(self): statement_a = Symbol('a') statement_b = Symbol('b') statement_and = And(statement_a, statement_b) statement_or = Or(statement_and, statement_a) statement_implies = If(statement_or, statement_and) statement_equiv = Iff(statement_implies, statement_a) self.assertEqual(repr(statement_equiv), "iff(if(or(and(a, b), a), " "and(a, b)), a)") self.assertEqual(str(statement_equiv), "((((a & b) | a) -> (a & b)) <-> a)")
def test_cnf_negation(self): statement = Not(Not(And(Symbol("a"), Symbol("b")))) statement = converter.convert_formula(statement) expected = And(Symbol("a"), Symbol("b")) self.assertEqual(expected, statement)
def test_cnf_or_distribution(self): statement = Or(And(Symbol("a"), Symbol("b")), Symbol("c")) statement = converter.convert_formula(statement) expected = And(Or(Symbol("a"), Symbol("c")), Or(Symbol("b"), Symbol("c"))) self.assertEqual(expected, statement)
def test_cnf_not_distribution(self): statement = Not(And(Symbol("a"), Symbol("b"))) statement = converter.convert_formula(statement) expected = Or(Not(Symbol("a")), Not(Symbol("b"))) self.assertEqual(expected, statement)
def test_cnf_converter_equiv(self): statement = Iff(Symbol("a"), Symbol("b")) statement = converter.convert_formula(statement) expected = And(Or(Not(Symbol("a")), Symbol("b")), Or(Not(Symbol("b")), Symbol("a"))) self.assertEqual(expected, statement)
def test_extra_paranthesis(self): statement = parser.parse("and((a),((b)))") self.assertEqual(And(Symbol("a"), Symbol("b")), statement)
def test_parse_and(self): statement = parser.parse("and(a, b)") self.assertEqual(statement, And(Symbol("a"), Symbol("b")))