def test_add_edge_weight():
    graph = Graph()
    start = graph.add_node('start')
    end = graph.add_node('end')
    graph.add_edge(start, end, 20)
    expected = (end, 20)
    actual = graph._adjancency_list[start][0]
    assert actual == expected
def test_get_nodes():
    graph = Graph()
    shoe = graph.add_node('shoe')
    boot = graph.add_node('boot')
    sneaker = graph.add_node('sneaker')
    expected = 3
    actual = len(graph.get_nodes())
    assert actual == expected
Ejemplo n.º 3
0
def test_breadth_first_3_el():
    graph = Graph()
    start = graph.add_node('spam')
    middle = graph.add_node('bacon')
    end = graph.add_node('eggs')
    graph.add_edge(start, end)
    graph.add_edge(start, middle, 2)
    assert graph.breadth_first(start) == ['spam', 'eggs', 'bacon']
def test_size_many():
    graph = Graph()
    graph.add_node('shoe')
    graph.add_node('boot')
    graph.add_node('sandal')
    graph.add_node('slipper')
    graph.add_node('flipflop')
    graph.add_node('sneaker')
    expected = 6
    actual = graph.size()
    assert actual == expected
Ejemplo n.º 5
0
def test_breadth_first_few_edges():
    graph = Graph()
    first = graph.add_node('spam')
    second = graph.add_node('bacon')
    third = graph.add_node('eggs')
    fourth = graph.add_node('butter')
    graph.add_edge(first, second)
    graph.add_edge(first, third, 2)
    graph.add_edge(second, third, 3)
    graph.add_edge(third, fourth, 4)
    assert graph.breadth_first(first) == ['spam', 'bacon', 'eggs', 'butter']
def test_get_many_neighbors():
    graph = Graph()
    shoe = graph.add_node('shoe')
    boot = graph.add_node('boot')
    sandal = graph.add_node('sandal')
    flipflop = graph.add_node('flipflop')
    graph.add_edge(shoe, boot, 6)
    graph.add_edge(shoe, sandal, 5)
    graph.add_edge(shoe, flipflop, 12)
    graph.add_edge(boot, sandal, 5)
    neighbors = graph.get_neighbors(shoe)
    expected = [boot, 6, flipflop, 12, sandal, 5]
    assert len(neighbors) == 3
    assert neighbors[0][0].value == 'boot'
    assert neighbors[1][0].value == 'sandal'
    assert neighbors[2][0].value == 'flipflop'
    assert isinstance(neighbors[0][0], Vertex)
    assert neighbors[0][1] == 6
    assert neighbors[1][1] == 5
    assert neighbors[2][1] == 12
def test_get_neighbors():
    graph = Graph()
    shoe = graph.add_node('shoe')
    boot = graph.add_node('boot')
    graph.add_edge(shoe, boot, 6)
    neighbors = graph.get_neighbors(shoe)
    expected = (boot, 6)
    assert len(neighbors) == 1
    assert neighbors[0][0].value == 'boot'
    assert isinstance(neighbors[0][0], Vertex)
    assert neighbors[0][1] == 6
def test_add_node():
    graph = Graph()
    expected = 'shoe'
    actual = graph.add_node('shoe').value
    assert actual == expected
def test_add_edge():
    graph = Graph()
    start = graph.add_node('start')
    end = graph.add_node('end')
    graph.add_edge(start, end)
Ejemplo n.º 10
0
def test_breadth_1_edge():
    graph = Graph()
    first = graph.add_node('spam')
    second = graph.add_node('bacon')
    graph.add_edge(first, second)
    assert graph.breadth_first(first) == ['spam', 'bacon']