changeset 80:d3456f9174f5

Added test for while-stmts.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Fri, 29 May 2009 10:53:33 +0200
parents 8462026d1e19
children 7333e5dead5a
files pysmcl/range_analysis.py pysmcl/test/unit/test_rangeanalysis.py
diffstat 2 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/range_analysis.py	Fri May 29 10:49:28 2009 +0200
+++ b/pysmcl/range_analysis.py	Fri May 29 10:53:33 2009 +0200
@@ -98,6 +98,9 @@
                 env['_'] = range(self.prime, node.value, env)
                 return env
 
+            def visit_While(self, node):
+                return env
+
         r = Visitor(self.prime).visit(node)
         if debug:
             print "Result of combination", r
--- a/pysmcl/test/unit/test_rangeanalysis.py	Fri May 29 10:49:28 2009 +0200
+++ b/pysmcl/test/unit/test_rangeanalysis.py	Fri May 29 10:53:33 2009 +0200
@@ -1,10 +1,13 @@
 
-
+import sys
 import unittest
 
 from ast import *
 from pysmcl.range_analysis import RangeAnalysis, Bottom
 
+from pysmcl.flow import Flow
+from pysmcl.graph import Graph
+
 class RangeAnalysisTest(unittest.TestCase):
 
 
@@ -246,13 +249,22 @@
         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
-#         prog = parse("def f(x):\n\tx=3\n\ty=1\n\twhile(x>0):\n\t\ty+=1\n\t\tx-=1")
-#         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_while(self):
+        p = 7
+        prog = parse(
+"""
+def f(x):
+    x=3
+    y=1
+    while(x>0):
+        y=y+1
+        x=x-1
+    y
+""")
+        range_analysis = RangeAnalysis(p)
+        range_analysis.apply(prog.body[0])
+        r = prog.body[0].body[-1].out_values["range"]
+        self.assertEquals(r, {'y': (1, Bottom()), 'x': (Bottom(), 3), '_': (1, Bottom())})
 
 #     def test_range_multiple_assign_and_tuples(self):
 #         p = 7