def test_little_weights_path(self):
     graph = GraphFactory.create_graph(
         5, [[None, 1, None, None, -1], [1, None, 1, None, None],
             [None, 1, None, None, None], [None, None, 1, None, None],
             [None, None, None, -1, None]], True, True)
     self.assertListEqual(FordBellman().find_path(graph, 0, 1),
                          [1, 5, 4, 3, 2])
Beispiel #2
0
 def get_test_line(self, node_count, start_node, finish_node, graph,
                   weighted_graph, planar_graph,
                   negative_weighted_graph):
     print(node_count)
     bfs_time, bfs_delta = self.time_test(
         Bfs().find_path, graph, start_node, finish_node)
     dfs_time, dfs_delta = self.time_test(
         Dfs().find_path, graph, start_node, finish_node)
     dijkstra_time, dijkstra_delta = self.time_test(
         Dijkstra().find_path, weighted_graph, start_node, finish_node)
     ford_bellman_time, ford_bellman_delta = self.time_test(
         FordBellman().find_path, negative_weighted_graph, start_node,
         finish_node)
     a_star_time, a_star_delta_time = self.time_test(
         AStar().find_path, planar_graph, start_node, finish_node)
     bfs_memory = self.memory_test(
         Bfs().find_path, graph, start_node, finish_node)
     dfs_memory = self.memory_test(
         Dfs().find_path, graph, start_node, finish_node)
     dijkstra_memory = self.memory_test(
         Dijkstra().find_path, weighted_graph, start_node, finish_node)
     ford_bellman_memory = self.memory_test(
         FordBellman().find_path, negative_weighted_graph, start_node,
         finish_node)
     a_star_memory = self.memory_test(AStar().find_path, planar_graph,
                                      start_node, finish_node)
     test_result = {
         'Count of nodes': node_count, 'BFS average time': bfs_time,
         'BFS delta time': bfs_delta, 'DFS average time': dfs_time,
         'DFS delta time': dfs_delta,
         'Dijkstra average time': dijkstra_time,
         'Dijkstra delta time': dijkstra_delta,
         'Ford-Bellman average time': ford_bellman_time,
         'Ford-Bellman delta time': ford_bellman_delta,
         'A_Star average time': a_star_time,
         'A_Star delta time': a_star_delta_time, 'BFS memory': bfs_memory,
         'DFS memory': dfs_memory, 'Dijkstra memory': dijkstra_memory,
         'Ford-Bellman memory': ford_bellman_memory,
         'A_Star memory': a_star_memory}
     return test_result
 def test_negative_weight_cycle(self):
     graph = GraphFactory.create_graph(
         3, [[None, -1, -2], [-1, None, -4], [-1, -4, None]], True, True)
     self.assertIsNone(FordBellman().find_path(graph, 0, 2))
 def test_no_path(self):
     graph = GraphFactory.create_graph(
         4, [[None, 1, None, None], [None, None, -2, None],
             [None, None, None, 3], [None, None, None, 0]], True, True)
     self.assertIsNone(FordBellman().find_path(graph, 3, 1))
 def test_simple_path(self):
     graph = GraphFactory.create_graph(
         4, [[None, 1, None, None], [None, None, -2, None],
             [None, None, None, 3], [None, None, None, 11]], True, True)
     self.assertListEqual(FordBellman().find_path(graph, 0, 2), [1, 2, 3])
 def test_unordered_graph(self):
     graph = GraphFactory.create_graph(2, [[0, 0], [0, 0]], True, False)
     with self.assertRaises(TypeError) as context:
         FordBellman().find_path(graph, 0, 1)
     self.assertIsInstance(context.exception, TypeError)
 def test_unweighted_graph(self):
     graph = GraphFactory.create_graph(2, [[None, 1], [1, None]], False,
                                       True)
     with self.assertRaises(TypeError) as context:
         FordBellman().find_path(graph, 1, 2)
     self.assertIsInstance(context.exception, TypeError)