コード例 #1
0
class TestMap(unittest.TestCase):
    def setUp(self) -> None:
        self.base_node = Morphy()

    def test_arrow_register(self):
        self.assertTrue(hasattr(self.base_node, 'map'))

    def test_one_to_one_connections(self):
        map_node = self.base_node.map(lambda x: x)
        self.assertTrue(map_node.parent_nodes[0] is self.base_node)
        self.assertTrue(self.base_node.child_nodes[0] is map_node)

    def test_one_to_many(self):
        node_0 = self.base_node.map(lambda x: x)
        node_1 = self.base_node.map(lambda x: x)
        node_2 = self.base_node.map(lambda x: x)

        self.assertTrue(self.base_node.child_nodes, [node_0, node_1, node_2])
        self.assertTrue(node_0.parent_nodes, [self.base_node])
        self.assertTrue(node_1.parent_nodes, [self.base_node])
        self.assertTrue(node_2.parent_nodes, [self.base_node])

    def test_data_flow(self):
        node_1 = self.base_node.map(lambda x: x + 1)
        node_2 = node_1.map(lambda x: x * 2)
        result = []
        node_3 = node_2.sink(result.append)

        self.base_node.emit(1)
        self.assertEqual([4], result)
コード例 #2
0
    def test_union_map(self):
        base = Morphy()
        node_0 = base.map(lambda x: x + 1)
        node_1 = base.map(lambda x: x - 1)
        node_2 = base.map(lambda x: x * 10)
        result = []
        node_3 = Morphy().union_map([node_0, node_1, node_2],
                                    func=lambda x: x + 1)
        node_4 = node_3.sink(result.append)

        base.emit(1)
        self.assertEqual([3, 1, 11], result)
コード例 #3
0
class TestMorphy(unittest.TestCase):
    def setUp(self) -> None:
        self.base_node = Morphy()

    def test_basic(self):
        self.assertEqual([], self.base_node.child_nodes)
        self.assertEqual([None], self.base_node.parent_nodes)

    def test_catch(self):
        error_node = self.base_node.map(lambda x: x / 0)

        self.base_node.emit(1)

    def test_connect(self):
        next_node = Morphy()
        next_node.connect(self.base_node)
        self.assertEqual([], self.base_node.child_nodes)
        self.assertEqual([None, next_node], self.base_node.parent_nodes)