Ejemplo n.º 1
0
 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])))
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
 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])))
Ejemplo n.º 8
0
    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)