def test_add_edge_nodes():
    '''
    Adding an edge between non-existant edges should cause those nodes to be
    returned by .nodes().
    '''
    g = UndirectedGraph()
    assert g.add_edge('a', 'b', 42)
    assert len(list(g.nodes())) == 2
    assert 'a' in g.nodes()
    assert 'b' in g.nodes()
def test_add_nodes():
    '''
    Adding a node should cause that node to appear in the return value of .nodes().
    '''
    g = UndirectedGraph()
    assert g.add_node('a')
    assert 'a' in g.nodes()
    assert len(list(g.nodes())) == 1

    assert g.add_node('a') == False
    assert 'a' in g.nodes()
    assert len(list(g.nodes())) == 1

    assert g.add_node('b')
    assert 'a' in g.nodes()
    assert 'b' in g.nodes()
    assert len(list(g.nodes())) == 2
def test_simple_integration():
    '''
    test a simple use case, retesting assumptions at each step.
    '''
    g = UndirectedGraph()

    assert g.add_node('a')
    assert g.contains('a')
    assert len(list(g.nodes())) == 1
    assert 'a' in g.nodes()
    assert len(list(g.neighbors('a'))) == 0

    assert g.add_node('b')
    assert g.contains('b')
    assert len(list(g.nodes())) == 2
    assert 'a' in g.nodes()
    assert 'b' in g.nodes()
    assert len(list(g.neighbors('a'))) == 0
    assert len(list(g.neighbors('b'))) == 0

    assert g.add_node('c')
    assert g.contains('c')
    assert len(list(g.nodes())) == 3
    assert 'a' in g.nodes()
    assert 'b' in g.nodes()
    assert 'c' in g.nodes()
    assert len(list(g.neighbors('a'))) == 0
    assert len(list(g.neighbors('b'))) == 0
    assert len(list(g.neighbors('c'))) == 0

    g.add_edge('a', 'b')
    edges = list(g.edges())
    assert len(edges) == 2
    assert ('a', 'b', 1) in edges
    assert ('b', 'a', 1) in edges
    assert g.contains('a')
    assert g.contains('b')
    assert g.contains('c')
    assert len(list(g.nodes())) == 3
    assert 'a' in g.nodes()
    assert 'b' in g.nodes()
    assert 'c' in g.nodes()
    assert len(list(g.neighbors('a'))) == 1
    assert ('b', 1) in g.neighbors('a')
    assert len(list(g.neighbors('b'))) == 1
    assert ('a', 1) in g.neighbors('b')
    assert len(list(g.neighbors('c'))) == 0

    g.add_edge('a', 'c')
    edges = list(g.edges())
    assert len(edges) == 4
    assert ('a', 'b', 1) in edges
    assert ('b', 'a', 1) in edges
    assert ('a', 'c', 1) in edges
    assert ('c', 'a', 1) in edges
    assert g.contains('a')
    assert g.contains('b')
    assert g.contains('c')
    assert len(list(g.nodes())) == 3
    assert 'a' in g.nodes()
    assert 'b' in g.nodes()
    assert 'c' in g.nodes()
    assert len(list(g.neighbors('a'))) == 2
    assert ('b', 1) in g.neighbors('a')
    assert ('c', 1) in g.neighbors('a')
    assert len(list(g.neighbors('b'))) == 1
    assert ('a', 1) in g.neighbors('b')
    assert len(list(g.neighbors('c'))) == 1
    assert ('a', 1) in g.neighbors('c')

    edges = list(g.edges())
    assert ('a', 'b', 1) in edges
    assert ('b', 'a', 1) in edges
    assert ('a', 'c', 1) in edges
    assert ('c', 'a', 1) in edges