コード例 #1
0
ファイル: test_diagram.py プロジェクト: samuelkolb/py-xadd
    def test_multiplication(self):
        pool = Pool()
        pool.int_var("x")
        two = pool.terminal("2")
        x = pool.terminal("x")

        test1 = pool.bool_test(LinearTest("x", ">="))
        test2 = pool.apply(Multiplication, pool.bool_test(LinearTest("x - 5", "<=")), x)

        product = pool.apply(Multiplication, test1, test2)
        result = Diagram(pool, pool.apply(Multiplication, product, two))

        for i in range(0, 10):
            evaluated = result.evaluate({"x": i})
            if 0 <= i <= 5:
                self.assertEqual(2 * i, evaluated)
            else:
                self.assertEqual(0, evaluated)
コード例 #2
0
ファイル: test_diagram.py プロジェクト: TomMcL/py-xadd
    def test_multiplication(self):
        pool = Pool()
        pool.int_var("x")
        two = pool.terminal("2")
        x = pool.terminal("x")

        test1 = pool.bool_test(LinearTest("x", ">="))
        test2 = pool.apply(Multiplication,
                           pool.bool_test(LinearTest("x - 5", "<=")), x)

        product = pool.apply(Multiplication, test1, test2)
        result = Diagram(pool, pool.apply(Multiplication, product, two))

        for i in range(0, 10):
            evaluated = result.evaluate({"x": i})
            if 0 <= i <= 5:
                self.assertEqual(2 * i, evaluated)
            else:
                self.assertEqual(0, evaluated)
コード例 #3
0
ファイル: test_diagram.py プロジェクト: samuelkolb/py-xadd
    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)
コード例 #4
0
ファイル: test_diagram.py プロジェクト: TomMcL/py-xadd
    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)