g.add_edge(1, 2) g.add_edge(1, 2) g.add_edge(2, 3) g.add_edge(3, 4) ok(g.has_edge(1, 2)) ok(g.has_edge(2, 3)) ok(not g.has_edge(2, 1)) ok(not g.has_edge(1, 3)) ok(not g.has_edge(4, 1)) eq(len(g.vertices()), 4) eq(len(g.successors(1)), 1) eq(len(g.predecessors(1)), 0) eq(len(g.neighbors(1)), 1) eq(len(g.neighbors(2)), 2) eq(len(g.edges()), 4) eq(len(g.unique_edges()), 3) eq(len(g.edges_from(1)), 2) eq(len(g.edges_to(1)), 0) eq(len(g.edges_at(1)), 2) eq(len(g.edges_from(2)), 1) eq(len(g.edges_to(2)), 2) eq(len(g.edges_at(2)), 3) eq(g.degree(1), 2) eq(g.degree(2), 3) eq(g.in_degree(1), 0) eq(g.out_degree(1), 2)
#!/usr/bin/env python3 from test_more import ok, eq from graph_tools import Graph g = Graph(directed=True, multiedged=True) g = g.create_graph('ring', 10, 1) ok(g) eq(len(g.vertices()), 10) eq(len(g.edges()), 10) for v in range(1, 11): eq(g.in_degree(v), 1) eq(g.out_degree(v), 1) g = Graph(directed=False, multiedged=True) g = g.create_graph('ring', 10, 1) ok(g) eq(len(g.vertices()), 10) eq(len(g.edges()), 10) for v in range(1, 11): eq(g.degree(v), 2) ok(g.is_connected())