def test_add_edge(): a = Vertex("a") b = Vertex("b") e = Edge(a, b) t = Graph([a, b], []) t.add_edge(e) assert t[a][b] == e assert t[b][a] == e assert t.edge_count == 1
def test_create_unconnected_graph(): a = Vertex(1) t = Graph.unconnected([a]) assert isinstance(t, Graph) assert t.vertex_count == 1 assert t.edge_count == 0 assert len(list(t.keys())) == 1
def test_create_odd_connected_graph_odd_graph(): PASSED = False vs = [Vertex(x) for x in "abcde"] try: t = Graph.regular_connected(vs, 3) except AssertionError: PASSED = True if PASSED: assert True else: assert False
def test_create_odd_connected_graph_even_graph(): vs = [Vertex(x) for x in "abcd"] t = Graph.regular_connected(vs, 3) assert t.vertex_count == 4 assert t.edge_count == 6
def test_create_fully_connected_graph(): vs = [Vertex(x) for x in "abcdef"] t = Graph.fully_connected(vs) assert t.vertex_count == 6 assert t.edge_count == 15
def test_str(): a = Vertex("a") b = Vertex("b") e = Edge(a, b) t = Graph([a, b], [e]) assert t.__str__() == "Graph contains 2 vertices and 1 edge"
def test_add_vertex(): t = Graph([], []) a = Vertex("a") t.add_vertex(a) assert type(t[a]) == dict assert t.vertex_count == 1