PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/test3/test_pack.py

http://gmpy.googlecode.com/
Python | 22 lines | 17 code | 3 blank | 2 comment | 7 complexity | 28d1253ed3a79ae371f3180c449ae4ff MD5 | raw file
 1from __future__ import print_function
 2import gmpy2
 3
 4def test_pack_unpack(bits = 200, chunk = 500, terms = 50):
 5    """Test gmpy2.pack and gmpy2.unpack."""
 6    for t in range(2, terms):
 7        for b in range(1, bits):
 8            # Test with all bits set to 1.
 9            v = [ 2**b - 1 ] * t
10            for c in range(b, chunk):
11                temp = gmpy2.pack(v, c)
12                u = gmpy2.unpack(temp, c)
13                assert u == v, (v, temp, u, (t, b, c))
14
15def main():
16    print("Testing pack/unpack for a large number of values.")
17    print("This test may take a few minutes.")
18    test_pack_unpack()
19    print("Test successful.")
20
21if __name__ == "__main__":
22    main()