Exemplo n.º 1
0
def test_start_is_stop():
    g = DirectedGraph()
    g.add_edge('a', 'b')
    g.add_edge('b', 'c')
    g.add_edge('b', 'd')
    g.add_edge('e', 'f')

    assert depth_first_search_by_criteria(g, 'e', criterion) == ['e']
Exemplo n.º 2
0
def test_single_path_directed():
    g = DirectedGraph()
    g.add_edge('a', 'b')
    g.add_edge('b', 'c')
    g.add_edge('b', 'd')
    g.add_edge('d', 'e')
    g.add_edge('e', 'f')

    assert depth_first_search_by_criteria(g, 'a', criterion) == ['a', 'b', 'd', 'e']
Exemplo n.º 3
0
def test_graph_with_tie():
    g = UndirectedGraph()
    g.add_edge('a', 'b')
    g.add_edge('b', 'c')
    g.add_edge('b', 'd')
    g.add_edge('c', 'e')
    g.add_edge('d', 'e')
    found = depth_first_search_by_criteria(g, 'a', criterion)
    assert found == ['a', 'b', 'c', 'e'] or found == ['a', 'b', 'd', 'e']
Exemplo n.º 4
0
def test_no_path_undirected():
    '''
    Test BFS on a simple undirected graph that contains a no cycles, and no path to the goal.
    '''
    g = UndirectedGraph()
    g.add_edge('a', 'b')
    g.add_edge('b', 'c')
    g.add_edge('b', 'd')
    g.add_edge('e', 'f')

    assert depth_first_search_by_criteria(g, 'a', criterion) is None
Exemplo n.º 5
0
def test_multiple_paths_directed():
    g = DirectedGraph()
    g.add_edge('a', 'b')
    g.add_edge('b', 'c')
    g.add_edge('b', 'e')
    g.add_edge('b', 'd')
    g.add_edge('d', 'e')
    g.add_edge('e', 'f')

    found_path = depth_first_search_by_criteria(g, 'a', criterion)
    assert found_path == ['a', 'b', 'e'] or found_path == ['a', 'b', 'd', 'e']
Exemplo n.º 6
0
def test_no_path_directed_cycles():
    '''
    Test BFS on a simple directed graph that contains cycles, but no path to the goal.
    '''
    g = DirectedGraph()
    g.add_edge('a', 'b')
    g.add_edge('b', 'c')
    g.add_edge('c', 'a')
    g.add_edge('b', 'd')
    g.add_edge('e', 'f')

    assert depth_first_search_by_criteria(g, 'a', criterion) is None
Exemplo n.º 7
0
def test_single_path_with_cycles_directed():
    g = DirectedGraph()
    g.add_edge('a', 'b')
    g.add_edge('b', 'c')
    g.add_edge('c', 'h')
    g.add_edge('h', 'i')
    g.add_edge('i', 'j')
    g.add_edge('j', 'e')
    g.add_edge('b', 'd')
    g.add_edge('d', 'k')
    g.add_edge('k', 'f')
    g.add_edge('f', 'b')

    assert depth_first_search_by_criteria(g, 'a', criterion) == ['a', 'b', 'c', 'h', 'i', 'j', 'e']