changeset 644:cc58a62d507c

Test case for double_share_random.
author Martin Geisler <mg@daimi.au.dk>
date Sat, 05 Apr 2008 00:00:24 +0200
parents 84d720a9ed4b
children ed0992a4915d
files viff/test/test_active_runtime.py
diffstat 1 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/viff/test/test_active_runtime.py	Sat Apr 05 00:00:24 2008 +0200
+++ b/viff/test/test_active_runtime.py	Sat Apr 05 00:00:24 2008 +0200
@@ -18,7 +18,7 @@
 from twisted.internet.defer import gatherResults
 
 from viff.test.util import RuntimeTestCase, protocol
-from viff.runtime import ActiveRuntime
+from viff.runtime import ActiveRuntime, Share
 
 
 class ActiveRuntimeTest(RuntimeTestCase):
@@ -53,3 +53,34 @@
         y.addCallback(self.assertEquals, "Hello two!")
         z.addCallback(self.assertEquals, "Hello three!")
         return gatherResults([x, y, z])
+
+    @protocol
+    def test_double_share_random(self, runtime):
+        """Test double-share random numbers."""
+        T = runtime.num_players - 2 * runtime.threshold
+        from viff.field import GF
+        self.Zp = GF(11)
+
+        r_t, r_2t = runtime.double_share_random(T,
+                                                runtime.threshold,
+                                                2*runtime.threshold,
+                                                self.Zp)
+
+        # Check that we got the expected number of shares.
+        self.assertEquals(len(r_t), T)
+        self.assertEquals(len(r_2t), T)
+
+        def verify(shares):
+            """Verify that the list contains two equal shares."""
+            self.assertEquals(shares[0], shares[1])
+
+        results = []
+        for a, b in zip(r_t, r_2t):
+            self.assert_type(a, Share)
+            self.assert_type(b, Share)
+            open_a = runtime.open(a)
+            open_b = runtime.open(b, threshold=2*runtime.threshold)
+            result = gatherResults([open_a, open_b])
+            result.addCallback(verify)
+            results.append(result)
+        return gatherResults(results)