def test_add_edge():
    from simple_graph import SimpleGraph
    instance = SimpleGraph()
    instance.add_node("waffles")
    instance.add_node("waffles2")
    instance.add_edge('waffles', 'waffles2')
    assert 'waffles2' in instance.graph_dict['waffles']
def test_sg_adjacent_false():
    """Ensure adjacent returns false if a and b don't share an edge."""
    from simple_graph import SimpleGraph
    test_sg = SimpleGraph()
    test_sg.add_node("a")
    test_sg.add_node("b")
    assert test_sg.adjacent("a", "b") is False
def test_display_nodes():
    from simple_graph import SimpleGraph
    instance = SimpleGraph()
    instance.add_node("waffles")
    instance.add_node("waffles2")
    instance.add_node("waffles3")
    for waffle in ['waffles', 'waffles2', 'waffles3']:
        assert waffle in instance.nodes()
def make_graph_three():
    my_graph = SimpleGraph()
    my_graph.add_node('a')
    my_graph.add_node('b')
    my_graph.add_node('c')
    my_graph.add_edge('a', 'c')
    my_graph.add_edge('b', 'a')
    return my_graph
def test_sg_add_node_error():
    """Ensure duplicate node raises IndexError."""
    from simple_graph import SimpleGraph
    test_sg = SimpleGraph()
    test_sg.add_node("node_a")
    with pytest.raises(IndexError) as message:
        test_sg.add_node("node_a")
    assert "That node already exists dumbo." in str(message)
def test_sg_adjace_error_two():
    """Ensure adjacent raises an error if either node doesn't exist."""
    from simple_graph import SimpleGraph
    test_sg = SimpleGraph()
    test_sg.add_node("a")
    with pytest.raises(IndexError) as message:
        test_sg.adjacent("a", "b")
    assert "Second argument is not in the graph." in str(message)
def test_add_node():
    """Test add node."""
    from simple_graph import SimpleGraph
    instance = SimpleGraph()
    instance.add_node("waffles")
    instance.add_node("waffles2")
    instance.add_node("waffles3")
    assert 'waffles' in instance.graph_dict
    assert 'waffles2' in instance.graph_dict
    assert 'waffles3' in instance.graph_dict
def fixture_graph():
    """Create a fixture."""
    from simple_graph import SimpleGraph
    obj = SimpleGraph()
    obj.add_node('A')
    obj.add_node('B')
    obj.add_node('C')
    obj.add_node('D')
    obj.add_node('E')
    obj.add_node('F')
    obj.add_node('G')
    obj.add_node('H')
    obj.add_edge('A', 'B', 45000000)
    obj.add_edge('A', 'C', .5)
    obj.add_edge('A', 'D', 8)
    obj.add_edge('C', 'E', 5)
    obj.add_edge('C', 'F', 1)
    obj.add_edge('F', 'E', 2)
    obj.add_edge('D', 'G', 7)
    obj.add_edge('G', 'H')
    return obj
Exemplo n.º 9
0
def test_add_node():
    from simple_graph import SimpleGraph
    new_graph = SimpleGraph()
    new_graph.add_node('A')
    assert list(new_graph.graph.keys()) == ['A']
    assert new_graph.graph['A'] == {}
def test_has_node():
    from simple_graph import SimpleGraph
    instance = SimpleGraph()
    instance.add_node("waffles")
    assert instance.has_node("waffles")
def test_del_non_existent_node2():
    from simple_graph import SimpleGraph
    instance = SimpleGraph()
    instance.add_node("waffles")
    with pytest.raises(ValueError):
        instance.del_edge('waffles', 'waffles2')
def test_del_node():
    from simple_graph import SimpleGraph
    instance = SimpleGraph()
    instance.add_node("waffles")
    instance.del_node('waffles')
    assert instance.graph_dict == {}
def make_graph_no_edges():
    my_graph = SimpleGraph()
    my_graph.add_node('a')
    my_graph.add_node('b')
    my_graph.add_node('c')
    return my_graph
def test_sg_add_node(data, result):
    """Ensure new node is added to the graph."""
    from simple_graph import SimpleGraph
    test_sg = SimpleGraph()
    test_sg.add_node(data)
    assert test_sg.graph[data] == result
def test_sg_has_node_true():
    """Ensure has_node returns true when called with node in graph."""
    from simple_graph import SimpleGraph
    test_sg = SimpleGraph()
    test_sg.add_node("a")
    assert test_sg.has_node("a") is True