Exemple #1
0
    def test_many_to_one(self):
        node_0, node_1, node_2 = Morphy(), Morphy(), Morphy()
        node_3 = Morphy().union([node_0, node_1, node_2])

        self.assertEqual(node_0.child_nodes[0], node_3)
        self.assertEqual(node_1.child_nodes[0], node_3)
        self.assertEqual(node_2.child_nodes[0], node_3)
        self.assertEqual(node_3.parent_nodes, [node_0, node_1, node_2])
Exemple #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)
Exemple #3
0
    def test_basic(self):
        base_node = Morphy()
        result = []
        next_node = base_node.filter(lambda x: x % 2 == 0, result.append)

        base_node.emit(1)
        base_node.emit(2)
        self.assertEqual([2], result)
Exemple #4
0
    def test_basic(self):
        node_0 = Morphy()
        node_1 = node_0.unpack()
        node_2 = node_1.map(lambda x: x * 2)
        result = []
        node_3 = node_2.sink(result.append)

        node_0.emit([1, 2, 3])
        self.assertEqual([2, 4, 6], result)
Exemple #5
0
 def setUp(self) -> None:
     self.base_node = Morphy()
Exemple #6
0
 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)