Example #1
0
    def test_dfs_disconnected(self):
        g = Graph([[0,1],[2,3]])
        depth_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)

        depth_first_search(g, 2)

        for i in range(2,4):
            self.assertTrue(g.get_node(i).visited)
Example #2
0
    def test_dfs_disconnected(self):
        g = Graph([[0, 1], [2, 3]])
        depth_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)

        depth_first_search(g, 2)

        for i in range(2, 4):
            self.assertTrue(g.get_node(i).visited)
Example #3
0
    def test_dfs_check_order(self):
        g = Graph([[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]])

        depth_first_search(g, 0)
        if g.get_node(1).visited < g.get_node(2).visited:
            self.assertTrue(g.get_node(3).visited < g.get_node(2).visited)
            self.assertTrue(g.get_node(4).visited < g.get_node(2).visited)
        else:
            self.assertTrue(g.get_node(5).visited < g.get_node(1).visited)
            self.assertTrue(g.get_node(6).visited < g.get_node(1).visited)

        self.assertTrue(g.get_node(0).visited < g.get_node(1).visited)
        self.assertTrue(g.get_node(0).visited < g.get_node(2).visited)
        self.assertTrue(g.get_node(1).visited < g.get_node(3).visited)
        self.assertTrue(g.get_node(1).visited < g.get_node(4).visited)
        self.assertTrue(g.get_node(2).visited < g.get_node(5).visited)
        self.assertTrue(g.get_node(2).visited < g.get_node(6).visited)
Example #4
0
    def test_dfs_check_order(self):
        g = Graph([[0,1], [0,2], [1,3], [1,4], [2,5], [2,6]])

        depth_first_search(g, 0)
        if g.get_node(1).visited < g.get_node(2).visited:
            self.assertTrue(g.get_node(3).visited < g.get_node(2).visited)
            self.assertTrue(g.get_node(4).visited < g.get_node(2).visited)
        else:
            self.assertTrue(g.get_node(5).visited < g.get_node(1).visited)
            self.assertTrue(g.get_node(6).visited < g.get_node(1).visited)

        self.assertTrue(g.get_node(0).visited < g.get_node(1).visited)
        self.assertTrue(g.get_node(0).visited < g.get_node(2).visited)
        self.assertTrue(g.get_node(1).visited < g.get_node(3).visited)
        self.assertTrue(g.get_node(1).visited < g.get_node(4).visited)
        self.assertTrue(g.get_node(2).visited < g.get_node(5).visited)
        self.assertTrue(g.get_node(2).visited < g.get_node(6).visited)
Example #5
0
    def test_dfs_self_edges(self):
        g = Graph([[0, 0], [0, 1], [1, 1], [2, 2], [2, 0]])
        depth_first_search(g, 0)

        for i in range(3):
            self.assertTrue(g.get_node(i).visited)
Example #6
0
    def test_dfs_simple_connected(self):
        g = Graph([[0, 1], [1, 2], [2, 0]])
        depth_first_search(g, 0)

        for i in range(3):
            self.assertTrue(g.get_node(i).visited)
Example #7
0
    def test_dfs_self_edges(self):
        g = Graph([[0,0],[0,1],[1,1],[2,2],[2,0]])
        depth_first_search(g, 0)

        for i in range(3):
            self.assertTrue(g.get_node(i).visited)
Example #8
0
    def test_dfs_simple_connected(self):
        g = Graph([[0,1],[1,2],[2,0]])
        depth_first_search(g, 0)

        for i in range(3):
            self.assertTrue(g.get_node(i).visited)