Exemplo n.º 1
0
 def test_iff(self):
     statement_a = Symbol('a')
     statement_b = Symbol('b')
     statement_iff = Iff(statement_a, statement_b)
     self.assertEqual(statement_iff.arity, 2)
     self.assertEqual(repr(statement_iff), "iff(a, b)")
     self.assertEqual(str(statement_iff), "(a <-> b)")
Exemplo n.º 2
0
 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')))
Exemplo n.º 3
0
 def test_or(self):
     statement_a = Symbol('a')
     statement_b = Symbol('b')
     statement_or = Or(statement_a, statement_b)
     self.assertEqual(statement_or.arity, 2)
     self.assertEqual(repr(statement_or), "or(a, b)")
     self.assertEqual(str(statement_or), "(a | b)")
Exemplo n.º 4
0
 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)")
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 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)")
Exemplo n.º 8
0
 def test_print_cnf_list(self):
     cnf = list()
     a_symbol = Symbol("a")
     b_symbol = Symbol("b")
     not_a = Not(a_symbol)
     not_b = Not(b_symbol)
     cnf.append([a_symbol, b_symbol])
     cnf.append([not_b, a_symbol])
     cnf.append([not_a, not_b])
     writer = StringIO()
     util.print_cnf_list(cnf, out=writer)
     cnf_list = "[[a, b], [~b, a], [~a, ~b]]\n"
     self.assertEqual(cnf_list, writer.getvalue())
Exemplo n.º 9
0
 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))
Exemplo n.º 10
0
 def test_cnf_converter_symbol(self):
     statement = Symbol("a")
     statement = converter.convert_formula(statement)
     expected = Symbol("a")
     self.assertEqual(expected, statement)
Exemplo n.º 11
0
 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)
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
 def test_is_tautology_bad_input(self):
     self.assertFalse(util.is_tautology("a"))
     self.assertFalse(util.is_tautology([Symbol("a")]))
Exemplo n.º 15
0
 def test_symbol_gt_symbol(self):
     self.assertGreater(Symbol('b'), Symbol('a'))
Exemplo n.º 16
0
 def test_cnf_list_as_disjunction(self):
     cnf = [Symbol("a"), Symbol("b")]
     expected = util.cnf_list_as_disjunction(cnf)
     self.assertEqual(expected, Or(Symbol("a"), Symbol("b")))
Exemplo n.º 17
0
 def test_is_tautology(self):
     cnf = list()
     cnf.append(Symbol("a"))
     cnf.append(Not(Symbol("a")))
     is_taut = util.is_tautology(cnf)
     self.assertTrue(is_taut)
Exemplo n.º 18
0
 def test_symbol(self):
     statement = Symbol('a')
     self.assertEqual(statement.arity, 0)
     self.assertEqual(repr(statement), "a")
     self.assertEqual(str(statement), "a")
Exemplo n.º 19
0
 def test_not(self):
     statement_a = Symbol('a')
     statement_not = Not(statement_a)
     self.assertEqual(statement_not.arity, 1)
     self.assertEqual(repr(statement_not), "not(a)")
     self.assertEqual(str(statement_not), "~a")
Exemplo n.º 20
0
 def test_operator_ge_symbol(self):
     self.assertGreaterEqual(Not(Symbol("a")), Not(Symbol("a")))
Exemplo n.º 21
0
 def test_operator_gt_symbol(self):
     self.assertGreater(Not(Symbol("a")), Symbol("b"))
Exemplo n.º 22
0
 def test_operator_le_symbol(self):
     self.assertLessEqual(Not(Symbol('a')), Not(Symbol('b')))
Exemplo n.º 23
0
 def test_operator_not_lt_symbol(self):
     self.assertFalse(Not(Symbol("a")) < Symbol("b"))
Exemplo n.º 24
0
 def test_symbol_ge_operator_1(self):
     self.assertGreaterEqual(Symbol('b'), Symbol('a'))
Exemplo n.º 25
0
 def test_negate_not(self):
     negate = util.negate_formula(Not(Symbol("a")))
     self.assertEqual(Symbol("a"), negate)
Exemplo n.º 26
0
 def test_symbol_lt_operator_1(self):
     self.assertLess(Symbol('a'), Not(Symbol('a')))
Exemplo n.º 27
0
 def test_is_tautology_negative(self):
     cnf = list()
     cnf.append(Symbol("a"))
     cnf.append(Symbol("b"))
     is_taut = util.is_tautology(cnf)
     self.assertFalse(is_taut)
Exemplo n.º 28
0
 def test_symbol_lt_symbol_1(self):
     self.assertLess(Symbol('a'), Symbol('b'))
Exemplo n.º 29
0
 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)
Exemplo n.º 30
0
 def test_symbol_le_symbol(self):
     self.assertLessEqual(Symbol('a'), Symbol('b'))