changeset 51:709a931db194

Added a more tests.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 26 May 2009 16:47:39 +0200
parents a192b4becf2e
children add1aa244d26 9b17819287ce
files pysmcl/test/unit/test_rangeanalysis.py
diffstat 1 files changed, 64 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/test/unit/test_rangeanalysis.py	Tue May 26 16:36:36 2009 +0200
+++ b/pysmcl/test/unit/test_rangeanalysis.py	Tue May 26 16:47:39 2009 +0200
@@ -146,5 +146,69 @@
         r = prog.body[0].body[0].out_values["range"]
         self.assertEquals(r, {'_': (0, p)})
 
+#     def test_range_if(self):
+#         p = 7
+#         prog = parse("def f(x):\n\ty=1\n\tif(x>1):\n\t\ty=2\n\telse:\n\t\ty=3")
+#         init_statements(prog)
+#         range_analysis = RangeAnalysis(p)
+#         range_analysis.apply(prog.body[0])
+#         r = prog.body[0].body[1].out_values["range"]
+#         self.assertEquals(r, {'y': (1, 3)})
+
+#     def test_range_while(self):
+#         p = 7
+#         prog = parse("def f(x):\n\tx=3\n\ty=1\n\twhile(x>0):\n\t\ty+=1\n\t\tx-=1")
+#         init_statements(prog)
+#         range_analysis = RangeAnalysis(p)
+#         range_analysis.apply(prog.body[0])
+#         r = prog.body[0].body[4].out_values["range"]
+#         self.assertEquals(r, {'y': (1, 3)})
+
+#     def test_range_multiple_assign_and_tuples(self):
+#         p = 7
+#         prog = parse("def f():\n\tx,y = (1, 2)")
+#         init_statements(prog)
+#         range_analysis = RangeAnalysis(p)
+#         range_analysis.apply(prog.body[0])
+#         r = prog.body[0].body[0].out_values["range"]
+#         self.assertEquals(r, {'x': (1, 1), 'y': (2, 2)})
+
+#     def test_range_multiple_assign(self):
+#         p = 7
+#         prog = parse("def f():\n\tx,y = 1, 2")
+#         init_statements(prog)
+#         range_analysis = RangeAnalysis(p)
+#         range_analysis.apply(prog.body[0])
+#         r = prog.body[0].body[0].out_values["range"]
+#         self.assertEquals(r, {'x': (1, 1), 'y': (2, 2)})
+
+#     def test_range_list(self):
+#         p = 7
+#         prog = parse("def f():\n\tz=4\n\tx = [1, z]")
+#         init_statements(prog)
+#         range_analysis = RangeAnalysis(p)
+#         range_analysis.apply(prog.body[0])
+#         r = prog.body[0].body[0].out_values["range"]
+#         self.assertEquals(r, {'x': (1, 1), 'y': (2, 2), 'z':(4, 4)})
+
+#     def test_range_dict(self):
+#         p = 7
+#         prog = parse("def f():\n\tz=4\n\tx = {1, z}")
+#         init_statements(prog)
+#         range_analysis = RangeAnalysis(p)
+#         range_analysis.apply(prog.body[0])
+#         r = prog.body[0].body[0].out_values["range"]
+#         self.assertEquals(r, {'x': (1, 1), 'y': (2, 2), 'z':(4, 4)})
+
+#     def test_range_unop_not(self):
+#         # Todo: unaryop = Invert | Not | UAdd | USub
+#         p = 7
+#         prog = parse("def f():\n\tz=4\n\tx = not (x == 1)")
+#         init_statements(prog)
+#         range_analysis = RangeAnalysis(p)
+#         range_analysis.apply(prog.body[0])
+#         r = prog.body[0].body[0].out_values["range"]
+#         self.assertEquals(r, {'x': (1, 1), 'y': (2, 2), 'z':(4, 4)})
+
 if __name__ == '__main__':
     unittest.main()