def test_add_edge():

    graph = Graph()
    vertex_1 = graph.add_vertex('test1')
    vertex_2 = graph.add_vertex('test2')
    assert len(graph.get_neighbors(vertex_1)) == 0
    graph.add_edge(vertex_1, vertex_2)
    assert len(graph.get_neighbors(vertex_1)) == 1
def test_get_neighbors_none():
    g = Graph()
    node_a = g.add_node('a')
    node_b = g.add_node('b')
    node_c = g.add_node('c')
    node_d = g.add_node('d')
    actual = g.get_neighbors(node_a)
    expected = []
    assert actual == expected
def test_get_neighbors_1():
    g = Graph()
    node_a = g.add_node('a')
    node_b = g.add_node('b')
    node_c = g.add_node('c')
    node_d = g.add_node('d')
    g.add_edge(node_a, node_b)
    actual = len(g.get_neighbors(node_a))
    expected = 1
    assert actual == expected
def test_get_neighbors():

    graph = Graph()

    test1 = graph.add_vertex('test1')

    test2 = graph.add_vertex('test2')

    graph.add_edge(test1, test2)

    neighbors = graph.get_neighbors(test1)

    assert len(neighbors) == 1

    neighbor = neighbors[0]

    assert neighbor.vertex.value == 'test2'

    assert neighbor.weight == 1
Beispiel #5
0
def test_empty_graph():
    graph = Graph()
    assert graph.get_vertices() == None
    assert graph.get_neighbors("key") == None
    assert len(graph) == 0