def test_0(prt=sys.stdout): L = len(sys.argv[1:]) g = cli_get_fin(sys.argv[1] if L != 0 else "../thirdparty/tinyG.txt") G = Graph(g) cc = CC(G) # number of connected components M = cc.count() prt.write("{M} components\n".format(M=M)) # compute list of vertices in each connected component components = [cx.deque() for i in range(M)] for v in range(G.V()): components[cc.id(v)].append(v) # enqueue(v) # print results for i in range(M): for v in components[i]: prt.write("{v} ".format(v=v)) prt.write("\n")
def test_0(prt=sys.stdout): """Test BFS using Graph from file represented with ints.""" prt.write("\ntest_0: BFS using Graph with ints\n") L = len(sys.argv[1:]) g = cli_get_fin(sys.argv[1] if L != 0 else join(TEST_DIR, "tinyCG.txt")) G = Graph(g) prt.write(str(G)) s = int(sys.argv[2]) if L > 1 else 0 bfs = BreadthFirstPaths(G, s) for v in range(G.V()): if bfs.hasPathTo(v): prt.write("{} to {} ({}): ".format(s, v, bfs.distTo(v))) for x in reversed(bfs.pathTo(v)): if x == s: prt.write(str(x)) else: prt.write("-{}".format(x)) prt.write("\n") else: prt.write.printf("{} to {} (-): not connected\n".format(s, v))