def test_impl_1(self): expected_permutations = [ "A->B", ] for expr_str in expected_permutations: expr = Parser.parse(expr_str).expr permutations = expr.permute() self.assertEqual(len(permutations), 1) expr = Parser.parse(expr_str).expr self.assertIn(expr, permutations, f"{expr_str} not in perms")
def test_eq_1(self): expected_permutations = [ "A<->B", ] for expr in expected_permutations: expr = Parser.parse(expr).expr permutations = expr.permute() self.assertEqual(len(permutations), len(expected_permutations)) for expected_permutation in expected_permutations: expr = Parser.parse(expected_permutation).expr self.assertIn(expr, permutations, f"{expected_permutation} missing")
def test_or_3(self): expected_permutations = [ "(A|B)|C", "A|(B|C)", ] for expr in expected_permutations: expr = Parser.parse(expr).expr permutations = expr.permute() self.assertEqual(len(permutations), len(expected_permutations)) for expected_permutation in expected_permutations: expr = Parser.parse(expected_permutation).expr self.assertIn(expr, permutations, f"{expected_permutation} missing")
def test_and_3(self): expected_permutations = [ "A&(B&C)", "(A&B)&C", ] for expr in expected_permutations: expr = Parser.parse(expr).expr permutations = expr.permute() self.assertEqual(len(permutations), len(expected_permutations)) for expected_permutation in expected_permutations: expr = Parser.parse(expected_permutation).expr self.assertIn(expr, permutations, f"{expected_permutation} missing")
def test_impl_3(self): expected_permutations = [ "A->((B->C)->D)", "A->(B->(C->D))", "((A->B)->C)->D", "(A->(B->C))->D", "(A->B)->(C->D)", ] for expr_str in expected_permutations: expr = Parser.parse(expr_str).expr permutations = expr.permute() self.assertEqual(len(permutations), 1) expr = Parser.parse(expr_str).expr self.assertIn(expr, permutations, f"{expr_str} not in perms")
def test_eq_4(self): wff = "a2df1<->bash3" expr = Eq(Atom("a2df1"), Atom("bash3")) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_impl_1(self): wff = "a->b" expr = Impl(Atom("a"), Atom("b")) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_or_4(self): wff = "a2df1|bash3" expr = Or(Atom("a2df1"), Atom("bash3")) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_atom_1(self): wff = "A" expr = Atom("A") tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_and_4(self): wff = "a2df1&bash3" expr = And(Atom("a2df1"), Atom("bash3")) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_or_3(self): wff = "a | b" expr = Or(Atom("a"), Atom("b")) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_atom_3(self): wff = "9af3b" expr = Atom("9af3b") tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_and_3(self): wff = "a & b" expr = And(Atom("a"), Atom("b")) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_not_3(self): wff = "!a2df1" expr = Not(Atom("a2df1")) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_clamp_2(self): wff = "( ads )" expr = Atom("ads") tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_eq_3(self): wff = "a <-> b" expr = Eq(Atom("a"), Atom("b")) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_impl_4(self): wff = "a2df1->bash3" expr = Impl(Atom("a2df1"), Atom("bash3")) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_complex_2(self): wff = "a|b&c|d&e&f" expr = Or(Or(Atom("a"), And(Atom("b"), Atom("c"))), And(And(Atom("d"), Atom("e")), Atom("f"))) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_complex_1(self): wff = "(a->b&c)<->!(d|a)" expr = Eq(Impl(Atom("a"), And(Atom("b"), Atom("c"))), Not(Or(Atom("d"), Atom("a")))) tree = PropParser.parse(wff) self.assertEqual(expr, tree.expr)
def test_eq_3(self): expected_permutations = [ "A<->((B<->C)<->D)", "A<->(B<->(C<->D))", "((A<->B)<->C)<->D", "(A<->(B<->C))<->D", "(A<->B)<->(C<->D)", ] for expr in expected_permutations: expr = Parser.parse(expr).expr permutations = expr.permute() self.assertEqual(len(permutations), len(expected_permutations)) for expected_permutation in expected_permutations: expr = Parser.parse(expected_permutation).expr self.assertIn(expr, permutations, f"{expected_permutation} missing")
def test_and_6(self): expr = Or(And(Atom("A"), Atom("B")), Atom("C")) expected_permutations = [ "A&B|C", ] permutations = expr.permute() self.assertEqual(len(permutations), len(expected_permutations)) for expected_permutation in expected_permutations: expr = Parser.parse(expected_permutation).expr self.assertIn(expr, permutations, f"{expected_permutation} missing")
def parse(expr: str): return PropParser.parse(expr).expr
def parse(expr): if expr.startswith('[') and expr.endswith(']'): expr = expr[1:-1] return PropParser.parse(expr).expr