changeset 212:ab8d20c4309d

test_flow: test of flow graph for for loops
author Sigurd Meldgaard <stm@daimi.au.dk>
date Tue, 22 Dec 2009 17:10:04 +0100
parents 84b397ddef2e
children a507d8d0c6ab
files pysmcl/test/unit/test_flow.py
diffstat 1 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/test/unit/test_flow.py	Tue Dec 22 14:04:32 2009 +0100
+++ b/pysmcl/test/unit/test_flow.py	Tue Dec 22 17:10:04 2009 +0100
@@ -79,6 +79,46 @@
 """
         self.assertEquals(result, expected_result)
 
+    def test_for(self):
+        p = 7
+        prog = parse(
+"""
+def f(x):
+    x=3
+    y=1
+    for i in range(10):
+        y=y+1
+        x=x-1
+    y
+""")
+        flow = Flow()
+        flow.flow(prog.body[0])
+        entry = flow.to_dot(prog.body[0])
+        result = Graph(entry).to_dot_string()
+        expected_result = \
+"""digraph G {
+  in -> 6
+  in [shape = plaintext, label=""]
+    6 [label="def f(x):    x = 3    y = 1    for(x > 0):        y = y + 1        x = x - 1    y"]
+    6->7;
+    7 [label="x = 3"]
+    7->8;
+    8 [label="y = 1"]
+    8->9;
+    8->10;
+    10 [label="for(x > 0):    y = y + 1    x = x - 1"]
+    10->11;
+    11 [label="y = y + 1"]
+    11->12;
+    12 [label="x = x - 1"]
+    12->9;
+    12->10;
+    9 [label="y"]
+}
+"""
+        print result
+        self.assertEquals(result, expected_result)
+
 
 if __name__ == '__main__':
     unittest.main()