viff

changeset 1044:ce92e62e21a8

Test case for fake decorator.
author Martin Geisler <mg@daimi.au.dk>
date Wed, 10 Dec 2008 12:35:12 +0100
parents d3c6163f5dc0
children 3625745e618a
files viff/test/test_util.py
diffstat 1 files changed, 36 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/viff/test/test_util.py	Mon Dec 08 12:59:29 2008 +0100
     1.2 +++ b/viff/test/test_util.py	Wed Dec 10 12:35:12 2008 +0100
     1.3 @@ -17,7 +17,11 @@
     1.4  
     1.5  """Tests for viff.util."""
     1.6  
     1.7 +import os
     1.8 +
     1.9  from viff.util import deep_wait
    1.10 +from viff.field import GF
    1.11 +import viff.shamir
    1.12  
    1.13  from twisted.trial.unittest import TestCase
    1.14  from twisted.internet.defer import Deferred
    1.15 @@ -26,6 +30,38 @@
    1.16  __doctests__ = ['viff.util']
    1.17  
    1.18  
    1.19 +class FakeTest(TestCase):
    1.20 +    """Tests for :func:`viff.util.fake`."""
    1.21 +
    1.22 +    # Modules which will be reloaded with and without VIFF_FAKE set in
    1.23 +    # the environment.
    1.24 +    _modules = [viff.shamir]
    1.25 +
    1.26 +    def setUp(self):
    1.27 +        self.field = GF(1031)
    1.28 +
    1.29 +        os.environ['VIFF_FAKE'] = "*"
    1.30 +        for module in self._modules:
    1.31 +            reload(module)        
    1.32 +
    1.33 +    def tearDown(self):
    1.34 +        del os.environ['VIFF_FAKE']
    1.35 +        for module in self._modules:
    1.36 +            reload(module)        
    1.37 +
    1.38 +    def test_shamir_share(self):
    1.39 +        from viff.shamir import share
    1.40 +        secret = self.field(17)
    1.41 +        shares = share(secret, 1, 3)
    1.42 +        self.assertEquals(shares[0][1], secret)
    1.43 +        self.assertEquals(shares[1][1], secret)
    1.44 +        self.assertEquals(shares[2][1], secret)
    1.45 +
    1.46 +    def test_shamir_recombine(self):
    1.47 +        from viff.shamir import recombine
    1.48 +        shares = [(1, 1), (2, 10), (3, 1)]
    1.49 +        self.assertEquals(recombine(shares), 1)
    1.50 +
    1.51  class DeepWaitTest(TestCase):
    1.52      """Tests for :func:`viff.util.deep_wait`."""
    1.53