def test_invert_terminal(self): pool = Pool() self.assertEquals(pool.zero_id, pool.invert(pool.one_id)) self.assertEquals(pool.one_id, pool.invert(pool.zero_id)) try: pool.invert(pool.terminal(2)) self.assertTrue(False) except RuntimeError: self.assertTrue(True)
def test_not(self): pool = Pool() pool.int_var("x") dd_true = Diagram(pool, pool.bool_test(LinearTest("x", ">="))) dd_false = Diagram(pool, pool.invert(dd_true.root_node.node_id)) for i in range(-5, 6): assignment = {"x": i} self.assertEqual((dd_true.evaluate(assignment) + 1) % 2, dd_false.evaluate(assignment))
def setUp(self): pool = Pool() pool.int_var("x") self.test1 = pool.bool_test(LinearTest("x", ">=")) self.test2 = pool.bool_test(LinearTest("x + 2", ">")) self.test3 = pool.bool_test(LinearTest("x + 1", "<=")) self.test4 = pool.bool_test(LinearTest("x - 5", "<=")) self.x = pool.terminal("x") p1 = pool.apply(Multiplication, self.test1, self.test4) p2 = pool.apply(Multiplication, pool.invert(self.test1), self.test2) p3 = pool.apply(Multiplication, pool.apply(Multiplication, pool.apply(Multiplication, pool.invert(self.test1), pool.invert(self.test2)), self.test3), self.test4) result = pool.apply(Summation, pool.apply(Summation, p1, p2), p3) result = pool.apply(Multiplication, result, self.x) self.diagram = Diagram(pool, result)
def setUp(self): pool = Pool() pool.int_var("x") self.test1 = pool.bool_test(LinearTest("x", ">=")) self.test2 = pool.bool_test(LinearTest("x + 2", ">")) self.test3 = pool.bool_test(LinearTest("x + 1", "<=")) self.test4 = pool.bool_test(LinearTest("x - 5", "<=")) self.x = pool.terminal("x") p1 = pool.apply(Multiplication, self.test1, self.test4) p2 = pool.apply(Multiplication, pool.invert(self.test1), self.test2) p3 = pool.apply( Multiplication, pool.apply( Multiplication, pool.apply(Multiplication, pool.invert(self.test1), pool.invert(self.test2)), self.test3), self.test4) result = pool.apply(Summation, pool.apply(Summation, p1, p2), p3) result = pool.apply(Multiplication, result, self.x) self.diagram = Diagram(pool, result)