Ejemplo n.º 1
0
 def testGraphDFS(self):
     G = pygraph.graph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(1, 5)
     G.add_edge(3, 5)
     st, pre, post = depth_first_search(G, 1, filter=filters.find(5))
     assert st == {1: None, 2: 1, 3: 2, 5: 3}
     st, pre, post = depth_first_search(G, 1, filter=filters.find(2))
     assert st == {1: None, 2: 1}
Ejemplo n.º 2
0
 def test_bfs_in_digraph(self):
     gr = testlib.new_digraph()
     gr.add_node('find-me')
     gr.add_edge(0, 'find-me')
     st, lo = breadth_first_search(gr, root=0, filter=filters.find('find-me'))
     assert st['find-me'] == 0
     for each in st:
         assert st[each] == None or st[each] == 0 or st[st[each]] == 0
Ejemplo n.º 3
0
 def test_dfs_in_digraph(self):
     gr = testlib.new_digraph()
     gr.add_node('find-me')
     gr.add_node('dont-find-me')
     gr.add_edge(0, 'find-me')
     gr.add_edge('find-me','dont-find-me')
     st, pre, post = depth_first_search(gr, root=0, filter=filters.find('find-me'))
     assert st['find-me'] == 0
     assert 'dont-find-me' not in st
Ejemplo n.º 4
0
 def testGraphBFS(self):
     G = pygraph.graph()
     G.add_nodes([1, 2, 3, 4, 5])
     G.add_edge(1, 2)
     G.add_edge(2, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 5)
     G.add_edge(1, 5)
     G.add_edge(3, 5)
     st, lo = breadth_first_search(G, 1, filter=filters.find(5))
     assert st == {1: None, 2: 1, 5: 1}
Ejemplo n.º 5
0
 def testDigraphDFS(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5, 6])
     G.add_edge(1, 2)
     G.add_edge(1, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 3)
     G.add_edge(5, 1)
     G.add_edge(3, 5)
     G.add_edge(5, 6)
     st, pre, post = depth_first_search(G, 1, filter=filters.find(5))
     assert st == {1: None, 2: 1, 3: 4, 4: 2, 5: 3}
Ejemplo n.º 6
0
 def testDigraphBFS(self):
     G = pygraph.digraph()
     G.add_nodes([1, 2, 3, 4, 5, 6])
     G.add_edge(1, 2)
     G.add_edge(1, 3)
     G.add_edge(2, 4)
     G.add_edge(4, 3)
     G.add_edge(5, 1)
     G.add_edge(3, 5)
     G.add_edge(5, 6)
     st, lo = G.breadth_first_search(1, filter=filters.find(5))
     assert st == {1: None, 2: 1, 3: 1, 4: 2, 5: 3}
Ejemplo n.º 7
0
 def test_bfs_in_empty_graph(self):
     gr = graph()
     st, lo = breadth_first_search(gr, filter=filters.find(5))
     assert st == {}
     assert lo == []
Ejemplo n.º 8
0
 def testEmptyGraphBFS(self):
     G = pygraph.graph()
     st, lo = breadth_first_search(G, filter=filters.find(5))
     assert st == {}
     assert lo == []