def testDigraphDFS(self): G = pygraph.digraph() G.add_nodes([1, 2, 3, 4, 5, 6, 7, 8, 9]) G.add_edge(1, 2) G.add_edge(1, 3) G.add_edge(2, 4) G.add_edge(3, 5) G.add_edge(4, 6) G.add_edge(5, 7) G.add_edge(1, 8, wt=3) G.add_edge(7, 8, wt=3) G.add_edge(8, 9) G.add_edge(3, 9) st, pre, post = depth_first_search(G, 1, filter=filters.radius(2)) assert st == {1: None, 2: 1, 3: 1, 4: 2, 5: 3, 9: 3} st, pre, post = depth_first_search(G, 7, filter=filters.radius(2)) assert st == {7: None}
def testGraphBFS(self): G = pygraph.graph() G.add_nodes([1, 2, 3, 4, 5, 6, 7, 8, 9]) G.add_edge(1, 2) G.add_edge(1, 3) G.add_edge(2, 4) G.add_edge(3, 5) G.add_edge(4, 6) G.add_edge(5, 7) G.add_edge(1, 8, wt=3) G.add_edge(8, 9) G.add_edge(3, 9) st, lo = breadth_first_search(G, 1, filter=filters.radius(2)) assert st == {1: None, 2: 1, 3: 1, 4: 2, 5: 3, 9: 3}
def testbfs_in_empty_graph(self): gr = graph() st, lo = breadth_first_search(gr, filter=filters.radius(2)) assert st == {} assert lo == []
def test_dfs_in_digraph(self): gr = testlib.new_graph() st, pre, post = depth_first_search(gr, root=0, filter=filters.radius(3)) for each in st: assert (st[each] == None or st[each] == 0 or st[st[each]] == 0 or st[st[st[each]]] == 0)
def test_dfs_in_empty_graph(self): gr = graph() st, pre, post = depth_first_search(gr, filter=filters.radius(2)) assert st == {} assert pre == [] assert post == []
def test_bfs_in_graph(self): gr = testlib.new_graph() st, lo = breadth_first_search(gr, root=0, filter=filters.radius(3)) for each in st: assert (st[each] == None or st[each] == 0 or st[st[each]] == 0 or st[st[st[each]]] == 0)
def testEmptyGraphDFS(self): G = pygraph.graph() st, pre, post = depth_first_search(G, filter=filters.radius(2)) assert st == {} assert pre == [] assert post == []
def testEmptyGraphBFS(self): G = pygraph.graph() st, lo = breadth_first_search(G, filter=filters.radius(2)) assert st == {} assert lo == []