Пример #1
0
def test_destination_is_not_reachable_if_path_does_not_exists():
    dg = DiGraph()
    dg.add_nodes_from([1, 2, 3, 4, 5])
    dg.add_edge(1, 2)
    dg.add_edge(2, 3)
    dg.add_edge(3, 4)

    assert not is_reachable(dg, 1, 5)
Пример #2
0
def test_bfs_on_directed_graph():
    dg = DiGraph()
    dg.add_nodes_from([1, 2, 3, 4, 5])
    dg.add_edge(1, 2)
    dg.add_edge(1, 3)
    dg.add_edge(2, 4)
    dg.add_edge(3, 4)

    assert bfs(dg, 1) == [1, 2, 3, 4]
Пример #3
0
def test_get_path_returns_path_when_path_exists():
    dg = DiGraph()
    dg.add_nodes_from([1, 2, 3, 4, 5])
    dg.add_edge(1, 2)
    dg.add_edge(2, 3)
    dg.add_edge(3, 4)
    dg.add_edge(4, 2)

    assert get_path(dg, 1, 4) == [1, 2, 3, 4]
Пример #4
0
def test_get_path_raises_path_not_found_error_if_no_path_exists():
    dg = DiGraph()
    dg.add_nodes_from([1, 2, 3, 4, 5])
    dg.add_edge(1, 2)
    dg.add_edge(2, 3)
    dg.add_edge(3, 4)
    dg.add_edge(4, 2)

    with pytest.raises(PathNotFoundError):
        get_path(dg, 1, 5)
Пример #5
0
def test_get_path_returns_path_when_source_and_destination_are_same():
    dg = DiGraph()
    dg.add_nodes_from([1, 2, 3, 4, 5])

    assert get_path(dg, 1, 1) == [1]
Пример #6
0
def test_source_is_reachable_from_source():
    dg = DiGraph()
    dg.add_nodes_from([1, 2, 3, 4, 5])

    assert is_reachable(dg, 1, 1)