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 (25 lines) | stat: -rw-r--r-- 730 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
23
24
25
from __future__ import print_function
import gmpy2

def test_pack_unpack(repeat):
    """Test gmpy2.pack and gmpy2.unpack."""
    r = gmpy2.random_state(42)
    for counter in range(repeat):
        for t in (10, 1000, 2000, 10000, 100000):
            v = gmpy2.mpz_rrandomb(r, t)
            for b in range(1, max(1001,t)):
                temp = gmpy2.unpack(v, b)
                u = gmpy2.pack(temp, b)
                assert u == v


if __name__ == "__main__":
    import sys
    try:
        repeat = abs(int(sys.argv[1]))
    except:
        repeat = 1
    print("Testing pack/unpack for a large number of values.")
    print("This test may take a few minutes.")
    test_pack_unpack(repeat)
    print("Test successful.")