def test_bidirectional_weight_name(): G = nx.cycle_graph(7) nx.set_edge_attributes(G, 'weight', 1) nx.set_edge_attributes(G, 'foo', 1) G.edge[1][2]['foo'] = 7 paths = list(nx.bidirectional_all_simple_paths(G, 0, 3)) solution = [[0, 1, 2, 3], [0, 6, 5, 4, 3]] assert_equal(paths, solution)
def test_bidirectional_weight_name(): G = nx.cycle_graph(7) nx.set_edge_attributes(G, 'weight', 1) nx.set_edge_attributes(G, 'foo', 1) G.edge[1][2]['foo'] = 7 paths = list(nx.bidirectional_all_simple_paths(G, 0, 3)) solution = [[0, 1, 2, 3], [0, 6, 5, 4, 3]] assert_equal(paths, solution)
def test_bidirectional_shortest_simple_paths(): G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted") paths = nx.bidirectional_all_shortest_paths(G, 1, 12) assert_equal(next(paths), [1, 5, 6, 10, 11, 12]) assert_equal(next(paths), [1, 5, 6, 7, 8, 12]) assert_equal( [len(path) for path in nx.bidirectional_all_simple_paths(G, 1, 12)], sorted([len(path) for path in nx.all_simple_paths(G, 1, 12)]))
def test_bidirectional_shortest_simple_paths(): G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted") paths = nx.bidirectional_all_shortest_paths(G, 1, 12) assert_equal(next(paths), [1, 5, 6, 10, 11, 12]) assert_equal(next(paths), [1, 5, 6, 7, 8, 12]) assert_equal( [len(path) for path in nx.bidirectional_all_simple_paths(G, 1, 12)], sorted([len(path) for path in nx.all_simple_paths(G, 1, 12)]))
def test_bidirectional_target_missing(): G = nx.Graph() G.add_path([1, 2, 3]) paths = list(nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 1, 4))
def test_bidirectional_source_missing(): G = nx.Graph() G.add_path([1, 2, 3]) paths = list(nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 0, 3))
def test_bidirectional_cutoff_zero(): G = nx.complete_graph(4) paths = nx.bidirectional_all_simple_paths(G, 0, 3, cutoff=0) assert_equal(list(list(p) for p in paths), []) paths = nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 0, 3, cutoff=0) assert_equal(list(list(p) for p in paths), [])
def test_bidirectional_all_simple_paths_empty(): G = nx.path_graph(4) paths = nx.bidirectional_all_simple_paths(G, 0, 3, cutoff=2) assert_equal(list(list(p) for p in paths), [])
def test_bidirectional_all_simple_paths_directed(): G = nx.DiGraph() G.add_path([1, 2, 3]) G.add_path([3, 2, 1]) paths = nx.bidirectional_all_simple_paths(G, 1, 3) assert_equal(list(list(p) for p in paths), [[1, 2, 3]])
def test_bidirectional_all_simple_paths_multigraph_with_cutoff(): G = nx.MultiGraph([(1, 2), (1, 2), (1, 10), (10, 2)]) paths = nx.bidirectional_all_simple_paths(G, 1, 2, cutoff=1) assert_equal(list(list(p) for p in paths), [[1, 2], [1, 2]])
def test_bidirectional_all_simple_paths_cutoff(): G = nx.complete_graph(4) paths = nx.bidirectional_all_simple_paths(G, 0, 1, cutoff=1) assert_equal(list(list(p) for p in paths), [[0, 1]]) paths = nx.bidirectional_all_simple_paths(G, 0, 1, cutoff=2) assert_equal(list(list(p) for p in paths), [[0, 1], [0, 2, 1], [0, 3, 1]])
def test_bidirectional_all_simple_paths_cutoff(): G = nx.complete_graph(4) paths = nx.bidirectional_all_simple_paths(G, 0, 1, cutoff=1) assert_equal(list(list(p) for p in paths), [[0, 1]]) paths = nx.bidirectional_all_simple_paths(G, 0, 1, cutoff=2) assert_equal(list(list(p) for p in paths), [[0, 1], [0, 2, 1], [0, 3, 1]])
def test_bidirectional_target_missing(): G = nx.Graph() G.add_path([1, 2, 3]) paths = list(nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 1, 4))
def test_bidirectional_source_missing(): G = nx.Graph() G.add_path([1, 2, 3]) paths = list(nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 0, 3))
def test_bidirectional_cutoff_zero(): G = nx.complete_graph(4) paths = nx.bidirectional_all_simple_paths(G, 0, 3, cutoff=0) assert_equal(list(list(p) for p in paths), []) paths = nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 0, 3, cutoff=0) assert_equal(list(list(p) for p in paths), [])
def test_bidirectional_all_simple_paths_empty(): G = nx.path_graph(4) paths = nx.bidirectional_all_simple_paths(G, 0, 3, cutoff=2) assert_equal(list(list(p) for p in paths), [])
def test_bidirectional_all_simple_paths_directed(): G = nx.DiGraph() G.add_path([1, 2, 3]) G.add_path([3, 2, 1]) paths = nx.bidirectional_all_simple_paths(G, 1, 3) assert_equal(list(list(p) for p in paths), [[1, 2, 3]])
def test_bidirectional_all_simple_paths_multigraph_with_cutoff(): G = nx.MultiGraph([(1, 2), (1, 2), (1, 10), (10, 2)]) paths = nx.bidirectional_all_simple_paths(G, 1, 2, cutoff=1) assert_equal(list(list(p) for p in paths), [[1, 2], [1, 2]])
def test_bidirectional_all_simple_paths(): G = nx.path_graph(4) paths = nx.bidirectional_all_simple_paths(G, 0, 3) assert_equal(list(list(p) for p in paths), [[0, 1, 2, 3]])
def test_bidirectional_all_simple_paths(): G = nx.path_graph(4) paths = nx.bidirectional_all_simple_paths(G, 0, 3) assert_equal(list(list(p) for p in paths), [[0, 1, 2, 3]])