Esempio n. 1
0
    def test_topological_sort_1(self):
        test_node_1 = OrderedNodeBase(node_name='test_node_1')
        test_node_2 = OrderedNodeBase(node_name='test_node_2')
        test_node_3 = OrderedNodeBase(node_name='test_node_3')
        test_graph = GraphBase()
        test_graph.add_direct_edge(from_node=test_node_1, to_node=test_node_2)
        test_graph.add_direct_edge(from_node=test_node_1, to_node=test_node_3)

        test_graph.add_direct_edge(from_node=test_node_3, to_node=test_node_2)
        self.assertListEqual(test_graph.topological_sort(),
                             [('test_node_1', 0), ('test_node_3', 1), ('test_node_2', 2)])
        self.assertDictEqual(
            test_graph.get_node_levels(),
            {0: ['test_node_1'], 1: ['test_node_3'], 2: ['test_node_2']}
        )
Esempio n. 2
0
 def test_topological_sort_3(self):
     test_node_1 = OrderedNodeBase(node_name='test_node_1')
     test_node_2 = OrderedNodeBase(node_name='test_node_2')
     test_node_3 = OrderedNodeBase(node_name='test_node_3')
     test_node_4 = OrderedNodeBase(node_name='test_node_4')
     test_node_5 = OrderedNodeBase(node_name='test_node_5')
     test_graph = GraphBase()
     test_graph.add_direct_edge(from_node=test_node_1, to_node=test_node_2)
     test_graph.add_direct_edge(from_node=test_node_1, to_node=test_node_3)
     test_graph.add_direct_edge(from_node=test_node_4, to_node=test_node_2)
     test_graph.add_direct_edge(from_node=test_node_4, to_node=test_node_3)
     test_graph.add_direct_edge(from_node=test_node_4, to_node=test_node_5)
     self.assertDictEqual(
         test_graph.get_node_levels(),
         {0: ['test_node_1', 'test_node_4'], 1: ['test_node_2', 'test_node_3', 'test_node_5']}
     )