comparison test/testgraph.py @ 284:05184b95fa16

Moved tests to seperate folder
author Windel Bouwman
date Fri, 15 Nov 2013 13:43:22 +0100
parents python/testgraph.py@02385f62f250
children 7b38782ed496
comparison
equal deleted inserted replaced
283:c9781c73e7e2 284:05184b95fa16
1 #!/usr/bin/python
2
3 import unittest
4 import graph
5 import interferencegraph
6 import flowgraph
7 import ir
8 from irmach import AbstractInstruction as AI
9 from target import Nop
10
11
12 class GraphTestCase(unittest.TestCase):
13 def testEdge(self):
14 g = graph.Graph()
15 n1 = graph.Node(g)
16 g.addNode(n1)
17 n2 = graph.Node(g)
18 g.addNode(n2)
19 g.addEdge(n1, n2)
20 self.assertTrue(g.hasEdge(n2, n1))
21 self.assertTrue(g.hasEdge(n1, n2))
22 g.delNode(n1)
23 g.delNode(n2)
24
25 def testDegree(self):
26 g = graph.Graph()
27 n1 = graph.Node(g)
28 g.addNode(n1)
29 n2 = graph.Node(g)
30 g.addNode(n2)
31 n3 = graph.Node(g)
32 g.addNode(n3)
33 g.addEdge(n1, n2)
34 g.addEdge(n1, n3)
35 self.assertEqual(2, n1.Degree)
36 self.assertEqual(1, n2.Degree)
37 g.delNode(n2)
38 self.assertEqual(1, n1.Degree)
39
40
41 class DigraphTestCase(unittest.TestCase):
42 pass
43
44
45 class InterferenceGraphTestCase(unittest.TestCase):
46 def testNormalUse(self):
47 t1 = ir.Temp('t1')
48 t2 = ir.Temp('t2')
49 t3 = ir.Temp('t3')
50 t4 = ir.Temp('t4')
51 t5 = ir.Temp('t5')
52 t6 = ir.Temp('t6')
53 instrs = []
54 instrs.append(AI(Nop, dst=[t1]))
55 instrs.append(AI(Nop, dst=[t2]))
56 instrs.append(AI(Nop, dst=[t3]))
57 cfg = flowgraph.FlowGraph(instrs)
58 ig = interferencegraph.InterferenceGraph(cfg)
59
60 def testCombine(self):
61 t1 = ir.Temp('t1')
62 t2 = ir.Temp('t2')
63 t3 = ir.Temp('t3')
64 t4 = ir.Temp('t4')
65 instrs = []
66 instrs.append(AI(Nop, dst=[t1]))
67 instrs.append(AI(Nop, dst=[t2]))
68 instrs.append(AI(Nop, dst=[t3]))
69 instrs.append(AI(Nop, dst=[t4], src=[t3]))
70 instrs.append(AI(Nop, src=[t4]))
71 instrs.append(AI(Nop, src=[t1]))
72 instrs.append(AI(Nop, src=[t2]))
73 cfg = flowgraph.FlowGraph(instrs)
74 ig = interferencegraph.InterferenceGraph(cfg)
75 ig.Combine(ig.getNode(t4), ig.getNode(t3))
76 self.assertIs(ig.getNode(t4), ig.getNode(t3))
77
78
79 if __name__ == '__main__':
80 unittest.main()
81