viff

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 diff
     1.1 --- a/viff/test/test_active_runtime.py	Sat Apr 05 00:00:24 2008 +0200
     1.2 +++ b/viff/test/test_active_runtime.py	Sat Apr 05 00:00:24 2008 +0200
     1.3 @@ -18,7 +18,7 @@
     1.4  from twisted.internet.defer import gatherResults
     1.5  
     1.6  from viff.test.util import RuntimeTestCase, protocol
     1.7 -from viff.runtime import ActiveRuntime
     1.8 +from viff.runtime import ActiveRuntime, Share
     1.9  
    1.10  
    1.11  class ActiveRuntimeTest(RuntimeTestCase):
    1.12 @@ -53,3 +53,34 @@
    1.13          y.addCallback(self.assertEquals, "Hello two!")
    1.14          z.addCallback(self.assertEquals, "Hello three!")
    1.15          return gatherResults([x, y, z])
    1.16 +
    1.17 +    @protocol
    1.18 +    def test_double_share_random(self, runtime):
    1.19 +        """Test double-share random numbers."""
    1.20 +        T = runtime.num_players - 2 * runtime.threshold
    1.21 +        from viff.field import GF
    1.22 +        self.Zp = GF(11)
    1.23 +
    1.24 +        r_t, r_2t = runtime.double_share_random(T,
    1.25 +                                                runtime.threshold,
    1.26 +                                                2*runtime.threshold,
    1.27 +                                                self.Zp)
    1.28 +
    1.29 +        # Check that we got the expected number of shares.
    1.30 +        self.assertEquals(len(r_t), T)
    1.31 +        self.assertEquals(len(r_2t), T)
    1.32 +
    1.33 +        def verify(shares):
    1.34 +            """Verify that the list contains two equal shares."""
    1.35 +            self.assertEquals(shares[0], shares[1])
    1.36 +
    1.37 +        results = []
    1.38 +        for a, b in zip(r_t, r_2t):
    1.39 +            self.assert_type(a, Share)
    1.40 +            self.assert_type(b, Share)
    1.41 +            open_a = runtime.open(a)
    1.42 +            open_b = runtime.open(b, threshold=2*runtime.threshold)
    1.43 +            result = gatherResults([open_a, open_b])
    1.44 +            result.addCallback(verify)
    1.45 +            results.append(result)
    1.46 +        return gatherResults(results)