예제 #1
0
 def test_parse(self):
     a, b, c = boolean.symbols("a", "b", "c")
     parse = boolean.parse
     self.assertTrue(parse("0") == parse("(0)") == boolean.FALSE)
     self.assertTrue(parse("1") == parse("(1)") == boolean.TRUE)
     self.assertTrue(parse("a") == parse("(a)") == a)
     self.assertTrue(parse("~a") == parse("~(a)") == parse("(~a)") == ~a)
     self.assertTrue(parse("~~a") == ~~a)
     self.assertTrue(parse("a*b") == a * b)
     self.assertTrue(parse("~a*b") == ~a * b)
     self.assertTrue(parse("a*~b") == a * ~b)
     self.assertTrue(
         parse("a*b*c") == parse("a*b*c", eval=False) == boolean.AND(
             a, b, c))
     self.assertTrue(
         parse("~a*~b*~c") == parse("~a*~b*~c", eval=False) == boolean.AND(
             ~a, ~b, ~c))
     self.assertTrue(parse("a+b") == a + b)
     self.assertTrue(parse("~a+b") == ~a + b)
     self.assertTrue(parse("a+~b") == a + ~b)
     self.assertTrue(
         parse("a+b+c") == parse("a+b+c", eval=False) == boolean.OR(
             a, b, c))
     self.assertTrue(parse("~a+~b+~c") == boolean.OR(~a, ~b, ~c))
     self.assertTrue(parse("(a+b)") == a + b)
     self.assertTrue(parse("a*(a+b)") == a * (a + b))
     self.assertTrue(parse("a*(a+~b)") == a * (a + ~b))
     self.assertTrue(
         parse("(a*b)+(b*((c+a)*(b+(c*a))))") == parse(
             "a*b + b*(c+a)*(b+c*a)") == (a * b) + (b * ((c + a) *
                                                         (b + (c * a)))))
예제 #2
0
 def test_parse(self):
     a, b, c = boolean.symbols("a", "b", "c")
     parse = boolean.parse
     self.assertTrue(parse("0") == parse("(0)") == boolean.FALSE)
     self.assertTrue(parse("1") == parse("(1)") == boolean.TRUE)
     self.assertTrue(parse("a") == parse("(a)") == a)
     self.assertTrue(parse("~a") == parse("~(a)") == parse("(~a)") == ~a)
     self.assertTrue(parse("~~a") == ~ ~a)
     self.assertTrue(parse("a*b") == a * b)
     self.assertTrue(parse("~a*b") == ~a * b)
     self.assertTrue(parse("a*~b") == a * ~b)
     self.assertTrue(parse("a*b*c") == parse("a*b*c", simplify=False) ==
                     boolean.AND(a, b, c))
     self.assertTrue(parse("~a*~b*~c") == parse("~a*~b*~c", simplify=False) ==
                     boolean.AND(~a, ~b, ~c))
     self.assertTrue(parse("a+b") == a + b)
     self.assertTrue(parse("~a+b") == ~a + b)
     self.assertTrue(parse("a+~b") == a + ~b)
     self.assertTrue(parse("a+b+c") == parse("a+b+c", simplify=False) ==
                     boolean.OR(a, b, c))
     self.assertTrue(parse("~a+~b+~c") == boolean.OR(~a, ~b, ~c))
     self.assertTrue(parse("(a+b)") == a + b)
     self.assertTrue(parse("a*(a+b)") == a * (a + b))
     self.assertTrue(parse("a*(a+~b)") == a * (a + ~b))
     self.assertTrue(parse("(a*b)+(b*((c+a)*(b+(c*a))))") ==
                     parse("a*b + b*(c+a)*(b+c*a)") ==
                     (a * b) + (b * ((c + a) * (b + (c * a)))))
예제 #3
0
 def test_demorgan(self):
     a, b = boolean.symbols("a", "b")
     parse = lambda x: boolean.parse(x, simplify=False)
     self.assertTrue(parse("~(a*b)").demorgan() == ~a + ~b)
     self.assertTrue(parse("~(a+b+c)").demorgan()
                     == parse("~a*~b*~c"))
     self.assertTrue(parse("~(~a*b)").demorgan() == a + ~b)
예제 #4
0
 def test_subs(self):
     a, b, c = boolean.symbols("a", "b", "c")
     expr = a * b + c
     self.assertEqual(expr.subs({a: b}), b + c)
     self.assertEqual(expr.subs({a: a}), expr)
     self.assertEqual(expr.subs({a: b + c}), boolean.parse("(b+c)*b+c"))
     self.assertEqual(expr.subs({a * b: a}), a + c)
     self.assertEqual(expr.subs({c: boolean.TRUE}), boolean.TRUE)
예제 #5
0
 def test_subs(self):
     a, b, c = boolean.symbols("a", "b", "c")
     expr = a * b + c
     self.assertEqual(expr.subs({a: b}), b + c)
     self.assertEqual(expr.subs({a: a}), expr)
     self.assertEqual(expr.subs({a: b + c}), boolean.parse("(b+c)*b+c"))
     self.assertEqual(expr.subs({a * b: a}), a + c)
     self.assertEqual(expr.subs({c: boolean.TRUE}), boolean.TRUE)
예제 #6
0
 def test_bool(self):
     a, b, c = boolean.symbols("a", "b", "c")
     expr = a * b + c
     self.assertRaises(TypeError, bool, expr.subs({a: boolean.TRUE}, simplify=False))
     self.assertRaises(TypeError, bool, expr.subs({b: boolean.TRUE}, simplify=False))
     self.assertRaises(TypeError, bool, expr.subs({c: boolean.TRUE}, simplify=False))
     self.assertRaises(TypeError, bool, expr.subs({a: boolean.TRUE, b: boolean.TRUE}, simplify=False))
     self.assertTrue(expr.subs({c: boolean.TRUE}, simplify=True))
     self.assertTrue(expr.subs({a: boolean.TRUE, b: boolean.TRUE}, simplify=True))
예제 #7
0
 def test_order(self):
     x, y, z = boolean.symbols(1, 2, 3)
     self.assertTrue(boolean.AND(x, y) < boolean.AND(x, y, z))
     self.assertTrue(not boolean.AND(x, y) > boolean.AND(x, y, z))
     self.assertTrue(boolean.AND(x, y) < boolean.AND(x, z))
     self.assertTrue(not boolean.AND(x, y) > boolean.AND(x, z))
     self.assertTrue(boolean.AND(x, y) < boolean.AND(y, z))
     self.assertTrue(not boolean.AND(x, y) > boolean.AND(y, z))
     self.assertTrue(not boolean.AND(x, y) < boolean.AND(x, y))
     self.assertTrue(not boolean.AND(x, y) > boolean.AND(x, y))
예제 #8
0
 def test_order(self):
     x, y, z = boolean.symbols(1, 2, 3)
     self.assertTrue(boolean.AND(x, y) < boolean.AND(x, y, z))
     self.assertTrue(not boolean.AND(x, y) > boolean.AND(x, y, z))
     self.assertTrue(boolean.AND(x, y) < boolean.AND(x, z))
     self.assertTrue(not boolean.AND(x, y) > boolean.AND(x, z))
     self.assertTrue(boolean.AND(x, y) < boolean.AND(y, z))
     self.assertTrue(not boolean.AND(x, y) > boolean.AND(y, z))
     self.assertTrue(not boolean.AND(x, y) < boolean.AND(x, y))
     self.assertTrue(not boolean.AND(x, y) > boolean.AND(x, y))
예제 #9
0
 def setUp(self):
     self.a, self.b, self.c = boolean.symbols("a", "b", "c")
     self.t1 = boolean.DualBase(self.a, self.b, eval=False)
     self.t2 = boolean.DualBase(self.a, self.b, self.c, eval=False)
     self.t3 = boolean.DualBase(self.a, self.a, eval=False)
     self.t4 = boolean.DualBase("a", "b", "c", eval=False)
예제 #10
0
 def test_demorgan(self):
     a, b, c = boolean.symbols("a", "b", "c")
     parse = lambda x: boolean.parse(x, eval=False)
     self.assertTrue(parse("~(a*b)").demorgan() == ~a + ~b)
     self.assertTrue(parse("~(a+b+c)").demorgan() == parse("~a*~b*~c"))
     self.assertTrue(parse("~(~a*b)").demorgan() == a + ~b)
예제 #11
0
 def setUp(self):
     self.a, self.b, self.c = boolean.symbols("a", "b", "c")
     self.t1 = boolean.DualBase(self.a, self.b, simplify=False)
     self.t2 = boolean.DualBase(self.a, self.b, self.c, simplify=False)
     self.t3 = boolean.DualBase(self.a, self.a, simplify=False)
     self.t4 = boolean.DualBase("a", "b", "c", simplify=False)