def test_basic_linear_path_graph(self):
     """
     Tests when there is a path from start to end with at least 1 node in
     the middle, it will find the end.
     """
     self.assertEquals(Dijkstras().dijkstras(self.g3, 'a', 'b'),
                       (3, ['a', 'c', 'b']))
 def test_large_cyclical_graph_to_check_multiple_paths(self):
     """
     Tests the algorithm will return a path when on a large graph with some
     cyclical paths.
     """
     self.assertEquals(Dijkstras().dijkstras(self.g9, 'a', 'b'),
                       (6, ['a', 'c', 'd', 'g', 'b']))
 def test_no_start_vertex_in_graph(self):
     """
     Tests an error will return when no ending vertex is found in the given
     graph.
     """
     self.assertEquals(Dijkstras().dijkstras(self.g13, 'a', 'b'),
                       '\'a\' as a start node not found')
 def test_large_mostly_linear_graph_to_check_multiple_paths(self):
     """
     Tests the algorithm will return a path when on a large and mostly
     linear graph.
     """
     self.assertEquals(Dijkstras().dijkstras(self.g8, 'a', 'b'),
                       (5, ['a', 'c', 'd', 'b']))
 def test_random_node_disconnected_graphs(self):
     """
     Tests the algorithm will return a complete path and not get confused
     when a vertex has no edges.
     """
     self.assertEquals(Dijkstras().dijkstras(self.g7, 'a', 'b'),
                       (3, ['a', 'c', 'b']))
 def test_end_disconnected_graph(self):
     """
     Tests the algorithm will return an error when the end is not found.
     """
     path = Dijkstras().dijkstras(self.g10, 'a', 'b')
     self.assertTrue(
         'The proclaimed end vertex \'b\' was not reached.' in path,
         'The end was found when it was not supposed to be.\
             The return was \'{}\''.format(path))
 def test_small_cycle_inside_of_graph(self):
     """
     Tests the algorithm will not get stuck in a cycle.
     """
     distance, path = Dijkstras().dijkstras(self.g5, 'a', 'b')
     self.assertEquals(distance, 3)
     self.assertTrue(
         path == ['a', 'c', 'e', 'b'] or path == ['a', 'd', 'e', 'b'],
         'path was {} instead of {} or {}'.format(path,
                                                  ['a', 'c', 'e', 'b'],
                                                  ['a', 'd', 'e', 'b']))
 def test_small_square_cyclical_graph(self):
     """
     Tests when there is a square cyclical graph, it will choose one of the
     paths to the end.
     """
     distance, path = Dijkstras().dijkstras(self.g4, 'a', 'b')
     self.assertEquals(distance, 2)
     self.assertTrue(
         path == ['a', 'c', 'b'] or path == ['a', 'd', 'b'],
         'path was {} instead of {} or {}'.format(path, ['a', 'c', 'b'],
                                                  ['a', 'd', 'b']))
 def test_choose_end_not_random_vertex_graph(self):
     """
     Tests when given 3 points, will choose the right one at the end.
     """
     self.assertEquals(Dijkstras().dijkstras(self.g2, 'a', 'b'),
                       (2, ['a', 'b']))
 def test_basic_two_point_graph(self):
     """
     Tests when given two points, will go from start to end.
     """
     self.assertEquals(Dijkstras().dijkstras(self.g1, 'a', 'b'),
                       (1, ['a', 'b']))
 def test_no_end_vertex_in_graph(self):
     """
     Tests an error will return when no vertex is found in the given graph.
     """
     self.assertEquals(Dijkstras().dijkstras(self.g12, 'a', 'b'),
                       '\'b\' as an end node not found')
 def test_no_vertex_in_graph(self):
     """
     Tests an error will return when no vertex is found in the given graph.
     """
     self.assertEquals(Dijkstras().dijkstras(self.g11, 'a', 'b'),
                       'No vertex found in graph')