annotate python/testgraph.py @ 277:046017431c6a

Started register allocator
author Windel Bouwman
date Thu, 26 Sep 2013 21:14:25 +0200
parents
children 9fca39eebe50
rev   line source
277
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
1 #!/usr/bin/python
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
2
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
3 import unittest
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
4 import graph
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
5
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
6 class GraphTestCase(unittest.TestCase):
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
7 def testEdge(self):
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
8 g = graph.Graph(False)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
9 n1 = g.newNode()
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
10 n2 = g.newNode()
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
11 g.addEdge(n1, n2)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
12 self.assertTrue(g.hasEdge(n2, n1))
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
13 self.assertTrue(g.hasEdge(n1, n2))
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
14 g.delNode(n1)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
15 g.delNode(n2)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
16
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
17 def testDegree(self):
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
18 g = graph.Graph(False)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
19 n1 = g.newNode()
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
20 n2 = g.newNode()
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
21 n3 = g.newNode()
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
22 g.addEdge(n1, n2)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
23 g.addEdge(n1, n3)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
24 self.assertEqual(2, n1.Degree)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
25 self.assertEqual(1, n2.Degree)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
26 g.delNode(n2)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
27 self.assertEqual(1, n1.Degree)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
28
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
29 class DigraphTestCase(unittest.TestCase):
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
30 pass
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
31
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
32
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
33 if __name__ == '__main__':
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
34 unittest.main()
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
35