-
Notifications
You must be signed in to change notification settings - Fork 3
/
DAG_tests.py
executable file
·44 lines (36 loc) · 1.37 KB
/
DAG_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
import unittest
import DAG
class Node(object):
def __init__(self,names,reqParents=None,reqChildren=None):
self.Names = [names] if isinstance(names,str) else names
self.requestedParents = reqParents if reqParents is not None else []
self.requestedChildren = reqChildren if reqChildren is not None else []
def Changed(self,*args,**kw):
pass
class DAGTester(unittest.TestCase):
def test_building(self):
dag = DAG.DAG()
node1 = Node('node1',[],['node3'])
dag.Add(node1)
node2 = Node('node2',['node1'])
dag.Add(node2)
self.assertEqual(len(dag),2)
self.assertEqual(dag.Parents(node2),[node1])
self.assertEqual(dag.Children(node1),[node2])
node3 = Node('node3')
dag.Add(node3)
self.assertEqual(dag.Parents(node3),[node1])
dag.Remove(node1)
self.assertEqual(len(dag),2)
self.assertEqual(dag.Parents(node2),[])
self.assertEqual(dag.Parents(node3),[])
dag.Add(node1)
self.assertEqual(dag.Parents(node3),[node1])
self.assertEqual(dag.Parents(node2),[node1])
self.assertEqual(dag.Children(node1),[node3,node2])
node4 = Node('node4',[node1])
dag.Add(node4)
self.assertEqual(dag.Parents(node4),[node1])
if __name__=='__main__':
unittest.main()