Exemplo n.º 1
0
 def setUp(self):
     # Create test graph.
     self.g = graph.Graph()
     self.g.add_edge("a", "b", weight=0.5)
     self.g.add_edge("a", "c")
     self.g.add_edge("b", "d")
     self.g.add_edge("d", "e")
     self.g.add_node("x")
Exemplo n.º 2
0
 def setUp(self):
     # Create test graph.
     self.g = graph.Graph(layout=graph.SPRING, distance=10.0)
     self.g.add_node("a")
     self.g.add_node("b")
     self.g.add_node("c")
     self.g.add_edge("a", "b")
     self.g.add_edge("b", "c")
Exemplo n.º 3
0
 def setUp(self):
     # Create test graph.
     self.g = graph.Graph()
     self.g.add_node("a", radius=5, stroke=(0,0,0,1), strokewidth=1, fill=None, text=(0,0,0,1))
     self.g.add_node("b", radius=5)
     self.g.add_node("c", radius=5)
     self.g.add_edge("a", "b")
     self.g.add_edge("b", "c")
Exemplo n.º 4
0
 def test_insert(self):
     g = graph.Graph()
     g.add_edge("a", "b")
     g.add_node("c")
     graph.insert(g, g["c"], g["a"], g["b"])
     self.assertTrue(g.edge("a","b") is None)
     self.assertTrue(g.edge("a","c") is not None)
     self.assertTrue(g.edge("c","b") is not None)
     print "pattern.graph.insert()"
Exemplo n.º 5
0
 def test_cut(self):
     # Assert unlink Node(b) and redirect a->c and a->d.
     g = graph.Graph()
     g.add_edge("a", "b")
     g.add_edge("b", "c")
     g.add_edge("b", "d")
     graph.cut(g, g["b"])
     self.assertTrue(len(g["b"].edges) == 0)
     self.assertTrue(g.edge("a","c") is not None)
     self.assertTrue(g.edge("a","d") is not None)
     print "pattern.graph.cut()"
Exemplo n.º 6
0
 def test_redirect(self):
     # Assert transfer connections of Node(a) to Node(d).
     g = graph.Graph()
     g.add_edge("a", "b")
     g.add_edge("c", "a")
     g.add_node("d")
     graph.redirect(g, g["a"], "d")
     self.assertTrue(len(g["a"].edges) == 0)
     self.assertTrue(len(g["d"].edges) == 2)
     self.assertTrue(g.edge("d","c").node1 == g["c"])
     print "pattern.graph.redirect()"
Exemplo n.º 7
0
 def setUp(self):
     # Create test graph.
     self.g = graph.Graph()
     self.g.add_node("a")
     self.g.add_node("b")
     self.g.add_edge("a",
                     "b",
                     weight=0.0,
                     length=1.0,
                     type="is-a",
                     stroke=(0, 0, 0, 1),
                     strokewidth=1)
Exemplo n.º 8
0
 def test_copy(self):
     # Assert deep copy of Graph.
     g1 = self.g
     g2 = self.g.copy()
     self.assertTrue(set(g1) == set(g2))         # Same node id's.
     self.assertTrue(id(g1["a"]) != id(g2["b"])) # Different node objects.
     g3 = self.g.copy(nodes=[self.g["a"], self.g["b"]])
     g3 = self.g.copy(nodes=["a", "b"])
     self.assertTrue(len(g3.nodes), 2)
     self.assertTrue(len(g3.edges), 1)
     # Assert copy with subclasses of Node and Edge.
     class MyNode(graph.Node):
         pass
     class MyEdge(graph.Edge):
         pass
     g4 = graph.Graph()
     g4.append(MyNode, "a")
     g4.append(MyNode, "b")
     g4.append(MyEdge, "a", "b")
     g4 = g4.copy()
     self.assertTrue(isinstance(g4.nodes[0], MyNode))
     self.assertTrue(isinstance(g4.edges[0], MyEdge))
     print "pattern.graph.Graph.copy()"