def test_sg_neighbors_error(): """Ensure error is raised if node does not exist in graph.""" from simple_graph import SimpleGraph test_sg = SimpleGraph() with pytest.raises(IndexError) as message: test_sg.neighbors("a") assert "That node is not in the graph." in str(message)
def test_sg_neighbors(): """Ensure neighbors for node that exists are returned.""" from simple_graph import SimpleGraph test_sg = SimpleGraph() test_sg.add_edge("b", "z") test_sg.add_edge("b", "c") assert test_sg.neighbors("b") == ["z", "c"]
def test_neighbors_error(): from simple_graph import SimpleGraph new_graph = SimpleGraph() new_graph.graph = {'A': {'B': 15}} with pytest.raises(KeyError): new_graph.neighbors('E')
def test_neighbors(): from simple_graph import SimpleGraph new_graph = SimpleGraph() new_graph.graph = {'A': {'B': 15}} assert new_graph.neighbors('A') == ['B']
def test_neighbors_empty(): from simple_graph import SimpleGraph instance = SimpleGraph() assert instance.neighbors('waffles') is None
def test_neighbors(): from simple_graph import SimpleGraph instance = SimpleGraph() instance.add_edge('waffles', 'waffles2') instance.add_edge('waffles', 'waffles3') assert instance.neighbors('waffles') == {'waffles2', 'waffles3'}