Ejemplo n.º 1
0
    def test_bfs_shortest_path(self):
        graph = Graph(graph = {
            'A' : ['B', 'F'],
            'B' : ['A', 'C'],
            'C' : ['B', 'D'],
            'D' : ['C', 'E'],
            'E' : ['D', 'G'],
            'F' : ['A', 'G']})

        path = Graph.bfs_shortest_path(graph, 'A', 'G')

        self.assertTrue(len(path) == 3, 'The shortest path is 3 units long.')
        self.assertEqual(path[1], 'F', 'The vertex between A and G is F.')