Пример #1
0
def test_positive1(f):
    graph = Graph()

    graph.create_vertex_by_id('A')
    graph.create_vertex_by_id('B')
    graph.create_vertex_by_id('C')
    graph.create_vertex_by_id('D')
    graph.create_vertex_by_id('E')

    graph.add_edge('A', 'C', 2)
    graph.add_edge('A', 'B', 4)

    graph.add_edge('B', 'C', 3)
    graph.add_edge('B', 'D', 2)
    graph.add_edge('B', 'E', 3)

    graph.add_edge('C', 'B', 1)
    graph.add_edge('C', 'D', 4)
    graph.add_edge('C', 'E', 5)

    graph.add_edge('E', 'D', 1)

    distance = f(graph, graph.get_vertex_by_id('A'))

    distance_to_c = get_distance(graph.get_vertex_by_id('C'), distance)
    assert distance_to_c == 2

    distance_to_b = get_distance(graph.get_vertex_by_id('B'), distance)
    assert distance_to_b == 3

    distance_to_e = get_distance(graph.get_vertex_by_id('E'), distance)
    assert distance_to_e == 6

    distance_to_d = get_distance(graph.get_vertex_by_id('D'), distance)
    assert distance_to_d == 5
Пример #2
0
def test_get_vertex_by_id_negative2():
    graph = Graph()

    with pytest.raises(DataStructureIsEmptyException) as exception_info:
        vertex = graph.get_vertex_by_id('A')

    assert str(exception_info.value) == data_structure_is_empty_message()
Пример #3
0
def test_bfs_positive1():
    graph = Graph()

    graph.create_vertex_by_id('A')

    distance = bfs(graph, graph.get_vertex_by_id('A'))

    assert distance['A'] == 0
Пример #4
0
def test_get_vertex_by_id_negative1():
    graph = Graph()

    graph.create_vertex_by_id('B')

    with pytest.raises(NotContainsElementException) as exception_info:
        vertex = graph.get_vertex_by_id('A')

    assert str(exception_info.value) == not_contains_vertex_message('A')
Пример #5
0
def test_dijkstra_positive2(f):
    graph = Graph()

    graph.create_vertex_by_id('A')
    graph.create_vertex_by_id('B')
    graph.create_vertex_by_id('C')
    graph.create_vertex_by_id('D')

    graph.add_edge('A', 'C', 2)
    graph.add_edge('A', 'B', 4)

    distance = f(graph, graph.get_vertex_by_id('A'))

    distance_to_b = get_distance(graph.get_vertex_by_id('B'), distance)
    assert distance_to_b == 4

    distance_to_c = get_distance(graph.get_vertex_by_id('C'), distance)
    assert distance_to_c == 2

    distance_to_d = get_distance(graph.get_vertex_by_id('D'), distance)
    assert distance_to_d is None
Пример #6
0
def test_get_vertex_by_id_positive():
    graph = Graph()

    graph.create_vertex_by_id('A')
    graph.create_vertex_by_id('B')
    graph.create_vertex_by_id('C')
    length = len(graph)

    vertex = graph.get_vertex_by_id('A')

    assert vertex.identifier == 'A'
    assert length == len(graph)
Пример #7
0
def test_bfs_positive2():
    graph = Graph()

    graph.create_vertex_by_id('A')
    graph.create_vertex_by_id('B')
    graph.create_vertex_by_id('C')
    graph.create_vertex_by_id('D')

    graph.add_edge('A', 'B')
    graph.add_edge('A', 'C')

    distance = bfs(graph, graph.get_vertex_by_id('A'))

    assert distance['A'] == 0
    assert distance['B'] == 1
    assert distance['C'] == 1

    assert distance['D'] is None