Ejemplo n.º 1
0
    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")
Ejemplo n.º 2
0
    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")
Ejemplo n.º 3
0
    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")
Ejemplo n.º 4
0
    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")
Ejemplo n.º 5
0
    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")
Ejemplo n.º 6
0
    def test_eq_4(self):
        wff = "a2df1<->bash3"
        expr = Eq(Atom("a2df1"), Atom("bash3"))

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 7
0
    def test_impl_1(self):
        wff = "a->b"
        expr = Impl(Atom("a"), Atom("b"))

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 8
0
    def test_or_4(self):
        wff = "a2df1|bash3"
        expr = Or(Atom("a2df1"), Atom("bash3"))

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 9
0
    def test_atom_1(self):
        wff = "A"
        expr = Atom("A")

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 10
0
    def test_and_4(self):
        wff = "a2df1&bash3"
        expr = And(Atom("a2df1"), Atom("bash3"))

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 11
0
    def test_or_3(self):
        wff = "a | b"
        expr = Or(Atom("a"), Atom("b"))

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 12
0
    def test_atom_3(self):
        wff = "9af3b"
        expr = Atom("9af3b")

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 13
0
    def test_and_3(self):
        wff = "a & b"
        expr = And(Atom("a"), Atom("b"))

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 14
0
    def test_not_3(self):
        wff = "!a2df1"
        expr = Not(Atom("a2df1"))

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 15
0
    def test_clamp_2(self):
        wff = "( ads )"
        expr = Atom("ads")

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 16
0
    def test_eq_3(self):
        wff = "a <-> b"
        expr = Eq(Atom("a"), Atom("b"))

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 17
0
    def test_impl_4(self):
        wff = "a2df1->bash3"
        expr = Impl(Atom("a2df1"), Atom("bash3"))

        tree = PropParser.parse(wff)

        self.assertEqual(expr, tree.expr)
Ejemplo n.º 18
0
    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)
Ejemplo n.º 19
0
    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)
Ejemplo n.º 20
0
    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")
Ejemplo n.º 21
0
    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")
Ejemplo n.º 22
0
def parse(expr: str):
    return PropParser.parse(expr).expr
Ejemplo n.º 23
0
def parse(expr):
    if expr.startswith('[') and expr.endswith(']'):
        expr = expr[1:-1]
    return PropParser.parse(expr).expr