Exemplo n.º 1
0
 def test_order(self):
     x = boolean.Symbol(1)
     y = boolean.Symbol(2)
     self.assertTrue(x < ~x)
     self.assertTrue(~x > x)
     self.assertTrue(~x < y)
     self.assertTrue(y > ~x)
Exemplo n.º 2
0
 def test_literals(self):
     l1 = boolean.Symbol(1)
     l2 = boolean.Symbol(1)
     self.assertTrue(l1 in l1.literals)
     self.assertTrue(l1 in l2.literals)
     self.assertTrue(l2 in l1.literals)
     self.assertTrue(l2 in l2.literals)
     self.assertRaises(AttributeError, setattr, l1, "literals", 1)
Exemplo n.º 3
0
 def test_distributive(self):
     a = self.a
     b = self.b
     c = self.c
     d = boolean.Symbol("d")
     e = boolean.Symbol("e")
     self.assertTrue((a * (b + c)).distributive() == (a * b) + (a * c))
     t1 = boolean.AND(a, (b + c), (d + e))
     t2 = boolean.OR(boolean.AND(a, b, d), boolean.AND(a, b, e),
                     boolean.AND(a, c, d), boolean.AND(a, c, e))
     self.assertTrue(t1.distributive() == t2)
Exemplo n.º 4
0
 def test_class_order(self):
     order = (
         (boolean.TRUE, boolean.FALSE),
         (boolean.Symbol(), boolean.Symbol("x")),
         (boolean.parse("x*y"), ),
         (boolean.parse("x+y"), ),
     )
     for i, tests in enumerate(order):
         for case1 in tests:
             for j in range(i + 1, len(order)):
                 for case2 in order[j]:
                     self.assertTrue(case1 < case2)
                     self.assertTrue(case2 > case1)
Exemplo n.º 5
0
 def test_printing(self):
     a = boolean.Symbol("a")
     self.assertTrue(str(~a) == "~a")
     self.assertTrue(repr(~a) == "NOT(Symbol('a'))")
     expr = boolean.parse("~(a*a)", eval=False)
     self.assertTrue(str(expr) == "~(a*a)")
     self.assertTrue(repr(expr) == "NOT(AND(Symbol('a'), Symbol('a')))")
Exemplo n.º 6
0
 def test_cancel(self):
     a = boolean.Symbol("a")
     parse = lambda x: boolean.parse(x, eval=False)
     self.assertTrue(~a == (~a).cancel())
     self.assertTrue(a == parse("~~a").cancel())
     self.assertTrue(~a == parse("~~~a").cancel())
     self.assertTrue(a == parse("~~~~a").cancel())
Exemplo n.º 7
0
 def test_eval(self):
     a = boolean.Symbol("a")
     self.assertTrue(~a == ~a)
     self.assertFalse(a == boolean.parse("~~a", eval=False))
     self.assertTrue(a == ~~a)
     self.assertTrue(~a, ~~~a)
     self.assertTrue(a, ~~~~a)
     self.assertTrue(~(a * a * a) == ~(a * a * a))
Exemplo n.º 8
0
 def test_literals(self):
     a = boolean.Symbol("a")
     l = ~a
     self.assertTrue(l.isliteral)
     self.assertTrue(l in l.literals)
     self.assertTrue(len(l.literals) == 1)
     l = boolean.parse("~(a*a)", eval=False)
     self.assertFalse(l.isliteral)
     self.assertTrue(a in l.literals)
     self.assertTrue(len(l.literals) == 1)
Exemplo n.º 9
0
 def test_equal(self):
     a = boolean.Symbol("a")
     b = boolean.Symbol("a")
     c = boolean.Symbol("b")
     d = boolean.Symbol()
     e = boolean.Symbol()
     # Test __eq__.
     self.assertTrue(a == a)
     self.assertTrue(a == b)
     self.assertFalse(a == c)
     self.assertFalse(b == c)
     self.assertTrue(d == d)
     self.assertFalse(d == e)
     self.assertFalse(a == d)
     # Test __ne__.
     self.assertFalse(a != a)
     self.assertFalse(a != b)
     self.assertTrue(a != c)
     self.assertTrue(b != c)
Exemplo n.º 10
0
 def test_init(self):
     boolean.Symbol(1)
     boolean.Symbol("a")
     boolean.Symbol(None)
     boolean.Symbol(sum)
     boolean.Symbol((1, 2, 3))
     boolean.Symbol([1, 2])
     self.assertRaises(TypeError, boolean.Symbol, 1, 2)
Exemplo n.º 11
0
 def test_literalize(self):
     s = boolean.Symbol(1)
     self.assertTrue(s.literalize() is s)
Exemplo n.º 12
0
 def test_isliteral(self):
     self.assertTrue(boolean.Symbol(1).isliteral is True)
Exemplo n.º 13
0
 def test_printing(self):
     self.assertTrue(str(boolean.Symbol("a")) == "a")
     self.assertTrue(str(boolean.Symbol(1)) == "1")
     self.assertTrue(repr(boolean.Symbol("a")), "Symbol('a')")
     self.assertTrue(repr(boolean.Symbol(1)) == "Symbol(1)")
Exemplo n.º 14
0
 def test_isliteral(self):
     s = boolean.Symbol(1)
     self.assertTrue(boolean.NOT(s).isliteral)
     self.assertFalse(boolean.parse("~(a+b)").isliteral)
Exemplo n.º 15
0
 def test_eval(self):
     s = boolean.Symbol(1)
     self.assertTrue(s.eval() is s)
Exemplo n.º 16
0
 def test_annihilator(self):
     a = boolean.Symbol("a")
     p = lambda x: boolean.parse(x, eval=False)
     self.assertTrue(p("a*a").annihilator is boolean.FALSE)
     self.assertTrue(p("a+a").annihilator is boolean.TRUE)
Exemplo n.º 17
0
Arquivo: dot.py Projeto: vraman/Party
def _to_expr(l:LabelsMap) -> boolean.Expression:
    expr = boolean.TRUE
    for var, val in l.items():
        s = boolean.Symbol(var)
        expr = (expr * s) if val else (expr * ~s)
    return expr