changeset 159:4aba2a1b340e

secret_ifs: updated tests.
author Sigurd Meldgaard <stm@daimi.au.dk>
date Mon, 07 Dec 2009 14:20:56 +0100
parents db7a0ad210df
children 8e7d7e891b00
files pysmcl/test/unit/test_secret_ifs.py
diffstat 1 files changed, 48 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/test/unit/test_secret_ifs.py	Mon Dec 07 14:20:15 2009 +0100
+++ b/pysmcl/test/unit/test_secret_ifs.py	Mon Dec 07 14:20:56 2009 +0100
@@ -7,26 +7,57 @@
 
 class SecretIfTest(unittest.TestCase):
 
-    def test_if(self):
-        expected_result = \
-"""def f(x):
-    cond0 = x
-    a = cond0 * 1 + (1 - cond0) * 2
-    x = cond0 * a + (1 - cond0) * x
-"""
-        prog = parse(
-"""def f(x):
+    def test_if1(self):
+        program = """
+def f(x):
     if(x):
-        a=1
-        x=a
+        a = 1
     else:
-        a=2
-""")
+        a = 2
+"""
+        expected = """\
+def f(x):
+    a_then0 = 1
+    a_else0 = 2
+    cond0 = x
+    a = a_then0 + (a_else0 - a_then0) * cond0
+"""
+        self.make_test(program, expected)
+
+    def test_if2(self):
+        expected = """\
+def f(x, y):
+    a_then0 = 1
+    a_else0 = 2
+    cond0 = y
+    a_then1 = a_then0 + (a_else0 - a_then0) * cond0
+    a_else1 = 3
+    cond1 = x
+    a = a_then1 + (a_else1 - a_then1) * cond1
+"""
+        program = """\
+def f(x, y):
+    if(x):
+        if(y):
+            a = 1
+        else:
+            a = 2
+    else:
+        a = 3
+"""
+        self.make_test(program, expected)
+
+
+    def make_test(self, program, expected):
+        parsed = parse(program)
         trans = TransformIfs()
-        secret_analysis(prog.body[0])
-        prog = trans.visit(prog)
-        result = pprint_string(prog)
-        self.assertEquals(expected_result, result)
+        secret_analysis(parsed.body[0])
+        prog = trans.visit(parsed)
+        result = pprint_string(parsed)
+        print
+        print expected
+        print result
+        self.assertEquals(expected, result)
 
 if __name__ == '__main__':
     unittest.main()