def testGraphDFS(self): G = graph.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 = G.depth_first_search(1, filter=filters.find(5)) assert st == {1: None, 2: 1, 3: 2, 5: 3} st, pre, post = G.depth_first_search(1, filter=filters.find(2)) assert st == {1: None, 2: 1}
def testGraphBFS(self): G = graph.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 = G.breadth_first_search(1, filter=filters.find(5)) assert st == {1: None, 2: 1, 5: 1}
def testDigraphDFS(self): G = graph.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 = G.depth_first_search(1, filter=filters.find(5)) assert st == {1: None, 2: 1, 3: 4, 4: 2, 5: 3}
def testEmptyGraphBFS(self): G = graph.graph() st, lo = G.breadth_first_search(filter=filters.find(5)) assert st == {} assert lo == []