Skip to content

Commit ce4aa69

Browse files
committed
Added a test for GeneralGraph
Signed-off-by: wean2016 <[email protected]> Signed-off-by: ZhiyiHuang <[email protected]>
1 parent d507d77 commit ce4aa69

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/TestGeneralGraphMethods.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,25 @@ def test_set_nodes(self):
2525

2626
dag.set_nodes(new_nodes)
2727
self.assertEqual(dag.get_nodes(), new_nodes)
28+
29+
def test_is_ancestor_of(self):
30+
nodes = [GraphNode(str(i)) for i in range(0, 5)]
31+
graph = GeneralGraph(nodes)
32+
no_of_var = len(nodes)
33+
for i in range(no_of_var):
34+
for j in range(i + 1, no_of_var):
35+
graph.add_edge(Edge(nodes[i], nodes[j], Endpoint.TAIL, Endpoint.TAIL))
36+
37+
for i in range(no_of_var):
38+
for j in range(i + 1, no_of_var):
39+
edge = graph.get_edge(nodes[i], nodes[j])
40+
graph.remove_edge(edge)
41+
42+
graph.add_edge(Edge(nodes[0], nodes[3], Endpoint.TAIL, Endpoint.ARROW))
43+
graph.add_edge(Edge(nodes[1], nodes[3], Endpoint.TAIL, Endpoint.ARROW))
44+
graph.add_edge(Edge(nodes[3], nodes[2], Endpoint.TAIL, Endpoint.ARROW))
45+
graph.add_edge(Edge(nodes[3], nodes[4], Endpoint.TAIL, Endpoint.ARROW))
46+
47+
48+
assert graph.is_ancestor_of(nodes[3], nodes[2])
49+
assert not graph.is_ancestor_of(nodes[2], nodes[3])

0 commit comments

Comments
 (0)