File: test_pack.py

package info (click to toggle)
python-gmpy2 2.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,628 kB
  • ctags: 1,123
  • sloc: ansic: 21,036; python: 5,846; makefile: 163
file content (22 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from __future__ import print_function
import gmpy2

def test_pack_unpack(bits = 200, chunk = 500, terms = 50):
    """Test gmpy2.pack and gmpy2.unpack."""
    for t in range(2, terms):
        for b in range(1, bits):
            # Test with all bits set to 1.
            v = [ 2**b - 1 ] * t
            for c in range(b, chunk):
                temp = gmpy2.pack(v, c)
                u = gmpy2.unpack(temp, c)
                assert u == v, (v, temp, u, (t, b, c))

def main():
    print("Testing pack/unpack for a large number of values.")
    print("This test may take a few minutes.")
    test_pack_unpack()
    print("Test successful.")

if __name__ == "__main__":
    main()