Beispiel #1
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)
Beispiel #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", 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)))))
Beispiel #3
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)))))
Beispiel #4
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)
Beispiel #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)
Beispiel #6
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)
Beispiel #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))
Beispiel #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))
Beispiel #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)
Beispiel #10
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)