def test_bfs_check_order(self): g = Graph([[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]) breadth_first_search(g, 0) self.assertTrue( g.get_node(0).visited < min(self.__get_visited_values(g, [1, 2]))) self.assertTrue( g.get_node(1).visited < min( self.__get_visited_values(g, [3, 4, 5, 6]))) self.assertTrue( g.get_node(2).visited < min( self.__get_visited_values(g, [3, 4, 5, 6])))
def test_bfs_disconnected(self): g = Graph([[0, 1], [2, 3]]) breadth_first_search(g, 0) for i in range(2): self.assertTrue(g.get_node(i).visited) for i in range(2, 4): self.assertFalse(g.get_node(i).visited) breadth_first_search(g, 2) for i in range(2, 4): self.assertTrue(g.get_node(i).visited)
def test_bfs_disconnected(self): g = Graph([[0,1],[2,3]]) breadth_first_search(g, 0) for i in range(2): self.assertTrue(g.get_node(i).visited) for i in range(2,4): self.assertFalse(g.get_node(i).visited) breadth_first_search(g, 2) for i in range(2,4): self.assertTrue(g.get_node(i).visited)
def test_bfs_simple_connected(self): g = Graph([[0, 1], [1, 2], [2, 0]]) breadth_first_search(g, 0) for i in range(3): self.assertTrue(g.get_node(i).visited)
def test_bfs_self_edges(self): g = Graph([[0, 0], [0, 1], [1, 1], [2, 2], [2, 0]]) breadth_first_search(g, 0) for i in range(3): self.assertTrue(g.get_node(i).visited)
def test_bfs_simple_connected(self): g = Graph([[0,1],[1,2],[2,0]]) breadth_first_search(g, 0) for i in range(3): self.assertTrue(g.get_node(i).visited)
def test_bfs_check_order(self): g = Graph([[0,1], [0,2], [1,3], [1,4], [2,5], [2,6]]) breadth_first_search(g, 0) self.assertTrue(g.get_node(0).visited < min(self.__get_visited_values(g, [1,2]))) self.assertTrue(g.get_node(1).visited < min(self.__get_visited_values(g, [3,4,5,6]))) self.assertTrue(g.get_node(2).visited < min(self.__get_visited_values(g, [3,4,5,6])))
def test_bfs_self_edges(self): g = Graph([[0,0],[0,1],[1,1],[2,2],[2,0]]) breadth_first_search(g, 0) for i in range(3): self.assertTrue(g.get_node(i).visited)