changeset 79:8462026d1e19

Added test for if-stmts with then and else branch.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Fri, 29 May 2009 10:49:28 +0200
parents a7cb4615acbc
children d3456f9174f5
files pysmcl/test/unit/test_rangeanalysis.py
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/test/unit/test_rangeanalysis.py	Fri May 29 10:48:36 2009 +0200
+++ b/pysmcl/test/unit/test_rangeanalysis.py	Fri May 29 10:49:28 2009 +0200
@@ -229,13 +229,22 @@
         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")
-#         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_if(self):
+        p = 7
+        prog = parse(
+"""
+def f(x):
+    y=1
+    if(x>1):
+        y=2
+    else:
+        y=3
+    y
+""")
+        range_analysis = RangeAnalysis(p)
+        range_analysis.apply(prog.body[0])
+        r = prog.body[0].body[-1].out_values["range"]
+        self.assertEquals(r, {'x': (0,7), 'y': (2, 3), '_': (2, 3)})
 
 #     def test_range_while(self):
 #         p = 7