def test_invalid_node(): graph = Graph() node1 = graph.add_node(1) node2 = graph.add_node(2) other_graph = Graph() with pytest.raises(InvalidNodeError): other_graph.add_edge(node1, node2)
def large_graph(): graph = Graph() bos = graph.add_node("bos") pvd = graph.add_node("pvd") jfk = graph.add_node("jfk") bwi = graph.add_node("bwi") ordd = graph.add_node("ordd") mia = graph.add_node("mia") dfw = graph.add_node("dfw") sfo = graph.add_node("sfo") lax = graph.add_node("lax") graph.add_edge_undirected(bos, sfo, 2704) graph.add_edge_undirected(bos, ordd, 867) graph.add_edge_undirected(bos, jfk, 187) graph.add_edge_undirected(bos, mia, 1258) graph.add_edge_undirected(pvd, jfk, 144) graph.add_edge_undirected(pvd, ordd, 849) graph.add_edge_undirected(jfk, ordd, 740) graph.add_edge_undirected(jfk, dfw, 1391) graph.add_edge_undirected(jfk, bwi, 184) graph.add_edge_undirected(jfk, mia, 1090) graph.add_edge_undirected(bwi, ordd, 621) graph.add_edge_undirected(bwi, mia, 946) graph.add_edge_undirected(ordd, dfw, 802) graph.add_edge_undirected(ordd, sfo, 1846) graph.add_edge_undirected(mia, dfw, 1121) graph.add_edge_undirected(mia, lax, 2342) graph.add_edge_undirected(dfw, sfo, 1464) graph.add_edge_undirected(dfw, lax, 1235) graph.add_edge_undirected(sfo, lax, 337) return graph, bos, lax
def small_graph(): graph = Graph() a = graph.add_node("a") b = graph.add_node("b") c = graph.add_node("c") graph.add_edge_undirected(a, b, 1) graph.add_edge_undirected(a, c, 2) graph.add_edge_undirected(b, c, 3) return (graph, a, b, c)
def test_no_loops_allowed(): graph = Graph() node = graph.add_node("node") with pytest.raises(LoopError): graph.add_edge(node, node)