#!/usr/bin/env python3 from test_more import ok, eq from graph_tools import Graph g = Graph(directed=False) g.create_configuration_graph([3, 2, 2, 1, 1, 1, 0]) ok(g.degree(1) == 3) ok(g.degree(2) == 2) ok(g.degree(3) == 2) ok(g.degree(4) == 1) ok(g.degree(5) == 1) ok(g.degree(6) == 1) ok(g.degree(7) == 0) g = Graph(directed=False) g.create_configuration_graph([3, 3, 3, 3, 3, 3]) for v in g.vertices(): ok(g.degree(v) == 3) g = Graph(directed=False) g.create_random_regular_graph(10, 3) for v in g.vertices(): ok(g.degree(v) == 3)
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())