annotate python/testgraph.py @ 278:9fca39eebe50

First implementation of regalloc with coalsesc
author Windel Bouwman
date Sun, 29 Sep 2013 14:08:15 +0200
parents 046017431c6a
children 2ccd57b1d78c
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):
278
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
8 g = graph.Graph()
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
9 n1 = graph.Node(g)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
10 g.addNode(n1)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
11 n2 = graph.Node(g)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
12 g.addNode(n2)
277
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
13 g.addEdge(n1, n2)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
14 self.assertTrue(g.hasEdge(n2, n1))
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
15 self.assertTrue(g.hasEdge(n1, n2))
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
16 g.delNode(n1)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
17 g.delNode(n2)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
18
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
19 def testDegree(self):
278
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
20 g = graph.Graph()
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
21 n1 = graph.Node(g)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
22 g.addNode(n1)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
23 n2 = graph.Node(g)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
24 g.addNode(n2)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
25 n3 = graph.Node(g)
9fca39eebe50 First implementation of regalloc with coalsesc
Windel Bouwman
parents: 277
diff changeset
26 g.addNode(n3)
277
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
27 g.addEdge(n1, n2)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
28 g.addEdge(n1, n3)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
29 self.assertEqual(2, n1.Degree)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
30 self.assertEqual(1, n2.Degree)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
31 g.delNode(n2)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
32 self.assertEqual(1, n1.Degree)
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
33
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
34 class DigraphTestCase(unittest.TestCase):
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
35 pass
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
36
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
37
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
38 if __name__ == '__main__':
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
39 unittest.main()
046017431c6a Started register allocator
Windel Bouwman
parents:
diff changeset
40