changeset 36:54af6d026211

Added tests for secret ifs and secret annotator.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Tue, 26 May 2009 11:35:52 +0200
parents 40c2d04622b8
children d574dfc3470a
files pysmcl/test/unit/test_secret_annotator.py pysmcl/test/unit/test_secret_ifs.py
diffstat 2 files changed, 55 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pysmcl/test/unit/test_secret_annotator.py	Tue May 26 11:35:52 2009 +0200
@@ -0,0 +1,22 @@
+
+
+import unittest
+
+from ast import *
+
+from pysmcl.pretty_print import *
+from pysmcl.ideal_functionality import init_statements
+from pysmcl.secret_ifs import TransformIfs
+from pysmcl.secret_annotator import secret_analysis
+
+class SecretAnnotatorTest(unittest.TestCase):
+
+
+    def test_range_one_range(self):
+        prog = parse("def f(x):\n\tx\n")
+        init_statements(prog)
+        secret_analysis(prog.body[0])
+        self.assertEquals(prog.body[0].body[0].out_values["secret"], set(['x']))
+
+if __name__ == '__main__':
+    unittest.main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pysmcl/test/unit/test_secret_ifs.py	Tue May 26 11:35:52 2009 +0200
@@ -0,0 +1,33 @@
+
+
+import unittest
+import StringIO
+
+from ast import *
+
+from pysmcl.pretty_print import *
+from pysmcl.ideal_functionality import init_statements
+from pysmcl.secret_ifs import TransformIfs
+from pysmcl.secret_annotator import secret_analysis
+
+class SecretIfTest(unittest.TestCase):
+
+
+    def test_ifs(self):
+        expected_result = \
+"""def f(x):
+    cond0 = x
+    a = cond0 * 1 + (1 - cond0) * 2
+"""
+        prog = parse("def f(x):\n\tif(x):\n\t\ta=1\n\telse:\n\t\ta=2")
+        trans = TransformIfs()
+        init_statements(prog)
+        secret_analysis(prog.body[0])
+        prog = trans.visit(prog)
+        output = StringIO.StringIO()
+        pprint(prog, output)
+        print output.getvalue()
+        self.assertEquals(expected_result, output.getvalue())
+
+if __name__ == '__main__':
+    unittest.main()