Esempio n. 1
0
  1 -> 2;
  1 -> 4;
}
""".splitlines()
g.import_graph('dot', buf)
eq(len(g.vertices()), 3)
eq(len(g.edges()), 2)
ok(g.is_directed())
ok(g.has_edge(1, 2))
ok(g.has_edge(1, 4))

g = Graph(directed=True, multiedged=True)
buf = """// comment here
digraph sample {
  1 [color=yellow];
  2;
  1 -> 2 [bw="1.5Mb",delay="10ms",
          type="RED"];
  1 -> 2;
}
""".splitlines()
g.import_graph('dot', buf)
eq(len(g.vertices()), 2)
eq(len(g.edges()), 2)
eq(g.is_directed(), 1)
ok(g.has_edge(1, 2))
eq(g.get_vertex_attribute(1, 'color'), 'yellow')
eq(g.get_edge_attribute_by_id(1, 2, 0, 'bw'), '1.5Mb')
eq(g.get_edge_attribute_by_id(1, 2, 0, 'delay'), '10ms')
eq(g.get_edge_attribute_by_id(1, 2, 0, 'type'), 'RED')
Esempio n. 2
0
#!/usr/bin/env python3

from test_more import ok, eq
from graph_tools import Graph

g = Graph(directed=True)
g.add_vertices(1, 2, 3)
g.add_edge(1, 2)
g.add_edge(1, 2)
g.add_edge(2, 3)

name, val, val2 = 'foo', 'bar', 'buzz'
g.set_graph_attribute(name, val)
eq(g.get_graph_attribute(name), val)

g.set_vertex_attribute(1, name, val)
eq(g.get_vertex_attribute(1, name), val)

g.set_edge_attribute_by_id(1, 2, 0, name, val)
eq(g.get_edge_attribute_by_id(1, 2, 0, name), val)

g.set_edge_attribute_by_id(1, 2, 1, name, val2)
eq(g.get_edge_attribute_by_id(1, 2, 1, name), val2)

g.set_edge_weight_by_id(1, 2, 0, val)
eq(g.get_edge_weight_by_id(1, 2, 0), val)

g.set_edge_weight_by_id(1, 2, 1, val2)
eq(g.get_edge_weight_by_id(1, 2, 1), val2)