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.depth_first(start) == ['spam', 'bacon', 'eggs']
예제 #2
0
def test_one_way_depth_first():
    graph = Graph()
    austin = graph.add('austin')
    boston = graph.add('boston')
    graph.add_edge(austin, boston)
    assert graph.depth_first(austin) == ['austin', 'boston']
    assert graph.depth_first(boston) == ['boston']
예제 #3
0
def test_depth_first_single():
    graph = Graph()
    austin = graph.add('austin')
    assert graph.depth_first(austin) == ['austin']
예제 #4
0
def create_graph():
    graph = Graph()

    austin = graph.add('austin')
    boston = graph.add('boston')
    chicago = graph.add('chicago')
    detroit = graph.add('detroit')
    seattle = graph.add('seattle')
    sanFransisco = graph.add('sanfransisco')
    newOrleans = graph.add('neworleans')
    graph.add_double_edge(austin, boston)
    graph.add_double_edge(austin, detroit)
    graph.add_double_edge(boston, chicago)
    graph.add_double_edge(boston, detroit)
    graph.add_double_edge(chicago, newOrleans)
    graph.add_double_edge(detroit, seattle)
    graph.add_double_edge(detroit, sanFransisco)

    return (graph, austin)
예제 #5
0
def test_import():
    graph = Graph()
    assert graph.add_double_edge
def graph():
    graph = Graph()
    graph.addNode('A')
    graph.addNode('B')
    graph.addNode('C')
    graph.addNode('D')
    graph.addNode('E')
    graph.addNode('F')
    graph.addNode('G')
    graph.addNode('H')
    graph.addEdge('A', 'B')
    graph.addEdge('B', 'C')
    graph.addEdge('C', 'G')
    graph.addEdge('G', 'C')
    graph.addEdge('C', 'D')
    graph.addEdge('D', 'E')
    graph.addEdge('E', 'D')
    graph.addEdge('D', 'H')
    graph.addEdge('H', 'D')
    graph.addEdge('B', 'A')
    graph.addEdge('B', 'D')
    graph.addEdge('A', 'D')
    graph.addEdge('D', 'A')
    graph.addEdge('H', 'F')
    graph.addEdge('F', 'H')
    graph.addEdge('F', 'D')
    graph.addEdge('D', 'H')
    return graph
def test_breadth_1_edge():
    graph = Graph()
    first = graph.add_node('spam')
    second = graph.add_node('bacon')
    graph.add_edge(first, second)
    assert graph.depth_first(first) == ['spam', 'bacon']
def test_breadth_first_few_edges():
    graph = Graph()
    a = graph.add_node('A')
    b = graph.add_node('B')
    c = graph.add_node('C')
    g = graph.add_node('G')
    d = graph.add_node('D')
    e = graph.add_node('E')
    h = graph.add_node('H')
    f = graph.add_node('F')

    graph.add_edge(a, d)
    graph.add_edge(a, b)
    graph.add_edge(b, c)
    graph.add_edge(c, g)
    graph.add_edge(d, f)
    graph.add_edge(d, h)
    graph.add_edge(d, e)
    graph.add_edge(h, f)
    assert graph.depth_first(a) == ['A', 'B', 'C', 'G', 'D', 'E', 'H', 'F']