Beispiel #1
0
 def test_topological_sort_error(self):
     """test_topological_sort_error: Make sure that 'topological_sort' raises the correct error
     """
     node_0 = WeightedNode(1, [2], {(1, 2): 1})
     node_1 = WeightedNode(2, [1], {(2, 1): 1})
     graph = WeightedGraph([node_0, node_1])
     with self.assertRaises(TypeError):
         graph.topological_sort()
Beispiel #2
0
 def test_topological_sort(self):
     """test_topological_sort: There is a picture in this folder showing the visual
     representation of this graph. Testing generating a topologically sorted list
     of graph vertices
     """
     node_0 = WeightedNode(5, [11], {(5, 11): 1})
     node_1 = WeightedNode(11, [2, 9, 10], {(11, 2): 1, (11, 9): 1, (11, 10): 1})
     node_2 = WeightedNode(2, [], {})
     node_3 = WeightedNode(7, [8, 11], {(7, 8): 1, (7, 11): 1})
     node_4 = WeightedNode(8, [9], {(8, 9): 1})
     node_5 = WeightedNode(9, [], {})
     node_6 = WeightedNode(3, [8, 10], {(3, 8): 1, (3, 10): 1})
     node_7 = WeightedNode(10, [], {})
     graph = WeightedGraph([node_0, node_1, node_2, node_3, node_4, node_5, node_6, node_7])
     self.assertEqual(graph.topological_sort(), [7, 5, 11, 3, 10, 8, 9, 2])