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_del_edge(): from simple_graph import SimpleGraph instance = SimpleGraph() instance.add_edge('waffles', 'waffles2') instance.add_edge('waffles', 'waffles3') instance.del_edge('waffles', 'waffles2') assert instance.graph_dict['waffles'] == {'waffles3': 1}
def test_sg_del_edge(): """Ensure supplied edge is deleted from appropriate node.""" from simple_graph import SimpleGraph test_sg = SimpleGraph() test_sg.add_edge("B", "c") test_sg.del_edge("B", "c") assert ("B", "c") not in test_sg.edges()
def test_del_node(): from simple_graph import SimpleGraph new_graph = SimpleGraph() new_graph.add_edge('A', 'B', 25) new_graph.add_edge('B', 'A', 10) new_graph.del_node('A') assert new_graph.graph == {'B': {}}
def test_sg_verify_edge_weights(): """Verify that when edges are added to the graph with a specified weight they have that weight.""" from simple_graph import SimpleGraph test_graph = SimpleGraph() test_graph.add_edge("a", "b", 7) assert test_graph.graph["a"][0][1] == 7
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_sg_del_edge_error(): """Ensure del_edge throws IndexError if called with node not in graph.""" from simple_graph import SimpleGraph test_sg = SimpleGraph() test_sg.add_edge("a", "b") with pytest.raises(IndexError) as message: test_sg.del_edge("c", "b") assert "That edge is not in the graph." in str(message)
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_del_node(): """Ensure correct node is deleted, and all its edges are removed.""" from simple_graph import SimpleGraph test_sg = SimpleGraph() test_sg.add_edge("a", "c") test_sg.add_edge("b", "c") test_sg.add_edge("c", "b") test_sg.del_node("c") assert "c" not in test_sg.edges()
def sample_g(): """Create an empty graph.""" from simple_graph import SimpleGraph g = SimpleGraph() a_to_e = 'abcde' for char in a_to_e: for char2 in a_to_e: if char != char2: g.add_edge(char2, char) return g
def graph_test_case_two(): """Return a test instance for graph traversal.""" from simple_graph import SimpleGraph instance = SimpleGraph() instance.add_edge("a", "d") instance.add_edge("a", "c") instance.add_edge("a", "b") instance.add_edge("d", "g") instance.add_edge("g", "h") instance.add_edge("h", "j") instance.add_edge("h", "i") instance.add_edge("b", "e") instance.add_edge("e", "f") return instance
def make_graph(): g = SimpleGraph() g.add_edge('a', 'b') g.add_edge('b', 'c') g.add_edge('c', 'f') g.add_edge('g', 'f') g.add_edge('a', 'd') g.add_edge('d', 'e') g.add_edge('e', 'a') return g
def graph_test_case_one(): """Return a test instance of graph traversal.""" from simple_graph import SimpleGraph instance = SimpleGraph() instance.add_edge("a", "b") instance.add_edge("a", "c") instance.add_edge("c", "d") instance.add_edge("c", "e") instance.add_edge("e", "h") instance.add_edge("e", "g") instance.add_edge("e", "f") return instance
def test_sg_edges(): """Ensure edges returns correct list of edges in graph.""" from simple_graph import SimpleGraph test_sg = SimpleGraph() test_sg.add_edge("node_a", "node_b") assert test_sg.edges() == [("node_a", "node_b")]
def test_edges(): from simple_graph import SimpleGraph new_graph = SimpleGraph() new_graph.add_edge('A', 'B', 25) assert new_graph.edges() == [('A', 'B', 25)]
def test_add_edge(): from simple_graph import SimpleGraph new_graph = SimpleGraph() new_graph.add_edge('B', 'A', 25) assert 'A' in new_graph.graph['B'] assert new_graph.graph['B']['A'] == 25
def test_sg_add_edge(): """Ensure new edge is added to the graph.""" from simple_graph import SimpleGraph test_sg = SimpleGraph() test_sg.add_edge("node_a", "node_b") assert test_sg.graph["node_a"] == [("node_b", 1)]
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
def test_adjacent(): from simple_graph import SimpleGraph instance = SimpleGraph() instance.add_edge('waffles', 'waffles2') assert instance.adjacent('waffles', 'waffles2')
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'}
def test_del_node_edge(): from simple_graph import SimpleGraph instance = SimpleGraph() instance.add_edge('waffles', 'waffles2') instance.del_node('waffles2') assert instance.graph_dict == {'waffles': {}}
def test_edge_display(): from simple_graph import SimpleGraph instance = SimpleGraph() instance.add_edge('waffles', 'waffles2') assert instance.edges()[0] == 'waffles-waffles2'
def test_sg_adjacent_true(): """Ensure adjacent returns true if a and b share an edge.""" from simple_graph import SimpleGraph test_sg = SimpleGraph() test_sg.add_edge("a", "b") assert test_sg.adjacent("a", "b") is True
def make_graph_cycle(): g = SimpleGraph() g.add_edge('a', 'b') g.add_edge('b', 'c') g.add_edge('c', 'a') return g