/test3/test_pack.py

http://gmpy.googlecode.com/ · Python · 22 lines · 17 code · 3 blank · 2 comment · 4 complexity · 28d1253ed3a79ae371f3180c449ae4ff MD5 · raw file

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