diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2002-04-01 01:37:14 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2002-04-01 01:37:14 (GMT) |
commit | 02098fa56b49e4770328218fc335d64dc695975d (patch) | |
tree | 9ad6d87c641434c2689c3fe59e2e0fd873c43d08 /Lib | |
parent | 496563a5146e2650dcf6f3595c58ff24f39a9afb (diff) | |
download | cpython-02098fa56b49e4770328218fc335d64dc695975d.zip cpython-02098fa56b49e4770328218fc335d64dc695975d.tar.gz cpython-02098fa56b49e4770328218fc335d64dc695975d.tar.bz2 |
Get rid of all METH_OLDARGS & PyArg_Parse.
Fix floating point exception if mpz.powm(10, 1, 0) (modulus == 0).
Add a test.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_mpz.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/Lib/test/test_mpz.py b/Lib/test/test_mpz.py new file mode 100644 index 0000000..3e0a700 --- /dev/null +++ b/Lib/test/test_mpz.py @@ -0,0 +1,90 @@ + +import mpz +from test_support import vereq + +def check_conversion(num): + mpz_num = mpz.mpz(num) + vereq(int(mpz_num), num) + vereq(long(mpz_num), num) + vereq(str(mpz_num), 'mpz(%s)' % `int(num)`) + +check_conversion(10) +check_conversion(10L) +# FIXME: should check strings, but I'm not sure it works, this seems odd: +# mpz.mpz('10') == mpz(12337) + +vereq(mpz.divm(100, 200, 3), 2) +vereq(mpz.divm(100L, 200, 3), 2) +vereq(mpz.divm(100, 200L, 3), 2) +vereq(mpz.divm(100L, 200L, 3), 2) + +vereq(mpz.gcd(100, 200), 100) +vereq(mpz.gcd(100L, 200), 100) +vereq(mpz.gcd(100, 200L), 100) +vereq(mpz.gcd(100L, 200L), 100) + +vereq(mpz.gcdext(100, 200), (100, 1, 0)) +vereq(mpz.gcdext(100L, 200), (100, 1, 0)) +vereq(mpz.gcdext(100, 200L), (100, 1, 0)) +vereq(mpz.gcdext(100L, 200L), (100, 1, 0)) + +vereq(mpz.powm(100, 0, 3), 1) +vereq(mpz.powm(100L, 0, 3), 1) +vereq(mpz.powm(100, 0L, 3), 1) +vereq(mpz.powm(100L, 0L, 3), 1) + +vereq(mpz.powm(101, 5, 3333), 1616) +vereq(mpz.powm(101L, 5, 3333), 1616) +vereq(mpz.powm(101, 5L, 3333), 1616) +vereq(mpz.powm(101L, 5L, 3333), 1616) + +vereq(mpz.sqrt(100), 10) +vereq(mpz.sqrt(100L), 10) +vereq(mpz.sqrt(200), 14) +vereq(mpz.sqrt(200L), 14) + +vereq(mpz.sqrtrem(100), (10, 0)) +vereq(mpz.sqrtrem(100L), (10, 0)) +vereq(mpz.sqrtrem(200), (14, 4)) +vereq(mpz.sqrtrem(200L), (14, 4)) + +try: mpz.mpz(10.) +except TypeError: pass +else: raise TestFailed, 'mpz(10.) should raise a TypeError' + +try: mpz.powm(10.) +except TypeError: pass +else: raise TestFailed, 'powm(10.) should raise a TypeError' + +try: mpz.powm(100, 1, 0) +except ValueError: pass +else: raise TestFailed, 'powm(100, 1, 0) should raise a ValueError' + +try: mpz.divm(10, 10) +except TypeError: pass +else: raise TestFailed, 'divm(10, 10) should raise a TypeError' + +try: mpz.divm(10, 10, 10.) +except TypeError: pass +else: raise TestFailed, 'divm(10, 10, 10.) should raise a TypeError' + +try: mpz.gcd(10) +except TypeError: pass +else: raise TestFailed, 'gcd(10) should raise a TypeError' + +try: mpz.gcd(10, 10.) +except TypeError: pass +else: raise TestFailed, 'gcd(10, 10.) should raise a TypeError' + +try: mpz.gcdext(10) +except TypeError: pass +else: raise TestFailed, 'gcdext(10) should raise a TypeError' + +try: mpz.gcdext(10, 10.) +except TypeError: pass +else: raise TestFailed, 'gcdext(10, 10.) should raise a TypeError' + +try: mpz.mpz(-10).binary() +except ValueError: pass +else: raise TestFailed, 'mpz(-10).binary() should raise a ValueError' + |