Example #1
0
def test_breadth_first():
    g = Graph()
    v1 = g.add_node('Pandora')
    v2 = g.add_node('Mordor')
    g.add_nondirectional_edge(v1, v2, 110)
    expected = ['Pandora', 'Mordor']
    actual = g.breadth_first(v1)
    assert expected == actual
Example #2
0
def test_false_get_edges():
    g = Graph()
    v1 = g.add_node('Pandora')
    v2 = g.add_node('Mordor')
    v3 = g.add_node('Monstropolis')
    v4 = g.add_node('Metroville')
    v5 = g.add_node('Naboo')
    v6 = g.add_node('Narnia')

    g.add_nondirectional_edge(v1, v2, 110)
    g.add_nondirectional_edge(v2, v3, 50)
    g.add_nondirectional_edge(v2, v4, 12)
    g.add_nondirectional_edge(v3, v4, 75)
    g.add_nondirectional_edge(v3, v5, 43)
    g.add_nondirectional_edge(v4, v5, 23)
    g.add_nondirectional_edge(v4, v6, 14)
    g.add_nondirectional_edge(v5, v6, 21)

    actual = g.get_edge(['Naboo, Pandora'])
    expected = (False, '$0')
    assert actual == expected
Example #3
0
def test_depth_first_3():
    g = Graph()
    v1 = g.add_node('A')
    v2 = g.add_node('B')
    v3 = g.add_node('C')
    v4 = g.add_node('G')
    v5 = g.add_node('D')
    v6 = g.add_node('E')
    v7 = g.add_node('F')
    v8 = g.add_node('H')

    g.add_nondirectional_edge(v1, v2, 110)
    g.add_nondirectional_edge(v1, v5, 43)
    g.add_nondirectional_edge(v2, v3, 50)
    g.add_nondirectional_edge(v2, v5, 12)
    g.add_nondirectional_edge(v3, v4, 75)
    g.add_nondirectional_edge(v5, v6, 21)
    g.add_nondirectional_edge(v5, v8, 29)
    g.add_nondirectional_edge(v5, v7, 23)
    g.add_nondirectional_edge(v7, v8, 14)

    actual = g.depth_first(v5)
    expected = ['D', 'A', 'B', 'C', 'G', 'E', 'H', 'F']
    assert actual == expected