Beispiel #1
0
#!/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('tree', 10)
ok(g)
eq(len(g.vertices()), 10)
eq(len(g.edges()), 10 - 1)

g = Graph(directed=True, multiedged=True)
g = g.create_graph('tree', 100)
ok(g)
eq(len(g.vertices()), 100)
eq(len(g.edges()), 100 - 1)

g = Graph(directed=False, multiedged=True)
g = g.create_graph('tree', 10)
ok(g)
eq(len(g.vertices()), 10)
eq(len(g.edges()), 10 - 1)
ok(g.is_connected())
Beispiel #2
0
#!/usr/bin/env python3

from test_more import ok, eq
from graph_tools import Graph

g = Graph(directed=False, multiedged=True)
g = g.create_graph('barandom', 10, 20, 2)
ok(g)
eq(len(g.vertices()), 10)
ok(g.is_connected())

g = Graph(directed=False, multiedged=True)
g = g.create_graph('barandom', 100, 200, 2)
ok(g)
eq(len(g.vertices()), 100)
ok(g.is_connected())
Beispiel #3
0
#!/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('btree', 15)
ok(g)
eq(len(g.vertices()), 15)
eq(len(g.edges()), 15 - 1)

g = Graph(directed=True, multiedged=True)
g = g.create_graph('btree', 100)
ok(g)
eq(len(g.vertices()), 100)
eq(len(g.edges()), 100 - 1)

g = Graph(directed=False, multiedged=True)
g = g.create_graph('btree', 10)
ok(g)
eq(len(g.vertices()), 10)
eq(len(g.edges()), 10 - 1)
ok(g.is_connected())
Beispiel #4
0
#!/usr/bin/env python3

from test_more import ok, eq
from graph_tools import Graph

g = Graph(directed=False, multiedged=True)
g = g.create_graph('unknown')
ok(not g)

g = Graph(directed=True, multiedged=True)
g = g.create_graph('random', 4, 10)
ok(g)
eq(len(g.vertices()), 4)
eq(len(g.edges()), 10)
ok(g.is_connected())

g = Graph(directed=True, multiedged=True)
g = g.create_graph('random', 40, 100)
ok(g)
eq(len(g.vertices()), 40)
eq(len(g.edges()), 100)
ok(g.is_connected())

g = Graph(directed=True, multiedged=True)
g = g.create_graph('random', 4, 10)
ok(g)
eq(len(g.vertices()), 4)
eq(len(g.edges()), 10)
Beispiel #5
0
#!/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())
Beispiel #6
0
#!/usr/bin/env python3

from test_more import ok, eq
from graph_tools import Graph

g = Graph(directed=False, multiedged=True)
g = g.create_graph('barabasi', 10, 2, 2)
ok(g)
eq(len(g.vertices()), 10)
eq(len(g.edges()), 2 * (2 - 1) / 2 + (10 - 2) * 2)
ok(g.is_connected())

g = Graph(directed=False, multiedged=True)
g = g.create_graph('barabasi', 100, 3, 4)
ok(g)
eq(len(g.vertices()), 100)
eq(len(g.edges()), 3 * (3 - 1) / 2 + (100 - 3) * 4)
ok(g.is_connected())

g = Graph(directed=False, multiedged=True)
g = g.create_graph('ba', 10, 2, 2)
ok(g)
eq(len(g.vertices()), 10)
eq(len(g.edges()), 2 * (2 - 1) / 2 + (10 - 2) * 2)
ok(g.is_connected())