Neal Norwitz | 02098fa | 2002-04-01 01:37:14 +0000 | [diff] [blame] | 1 | |
| 2 | import mpz |
Barry Warsaw | 04f357c | 2002-07-23 19:04:11 +0000 | [diff] [blame] | 3 | from test.test_support import vereq, TestFailed |
Neal Norwitz | 02098fa | 2002-04-01 01:37:14 +0000 | [diff] [blame] | 4 | |
| 5 | def check_conversion(num): |
| 6 | mpz_num = mpz.mpz(num) |
| 7 | vereq(int(mpz_num), num) |
| 8 | vereq(long(mpz_num), num) |
| 9 | vereq(str(mpz_num), 'mpz(%s)' % `int(num)`) |
| 10 | |
| 11 | check_conversion(10) |
| 12 | check_conversion(10L) |
| 13 | # FIXME: should check strings, but I'm not sure it works, this seems odd: |
| 14 | # mpz.mpz('10') == mpz(12337) |
| 15 | |
| 16 | vereq(mpz.divm(100, 200, 3), 2) |
| 17 | vereq(mpz.divm(100L, 200, 3), 2) |
| 18 | vereq(mpz.divm(100, 200L, 3), 2) |
| 19 | vereq(mpz.divm(100L, 200L, 3), 2) |
| 20 | |
| 21 | vereq(mpz.gcd(100, 200), 100) |
| 22 | vereq(mpz.gcd(100L, 200), 100) |
| 23 | vereq(mpz.gcd(100, 200L), 100) |
| 24 | vereq(mpz.gcd(100L, 200L), 100) |
| 25 | |
| 26 | vereq(mpz.gcdext(100, 200), (100, 1, 0)) |
| 27 | vereq(mpz.gcdext(100L, 200), (100, 1, 0)) |
| 28 | vereq(mpz.gcdext(100, 200L), (100, 1, 0)) |
| 29 | vereq(mpz.gcdext(100L, 200L), (100, 1, 0)) |
| 30 | |
| 31 | vereq(mpz.powm(100, 0, 3), 1) |
| 32 | vereq(mpz.powm(100L, 0, 3), 1) |
| 33 | vereq(mpz.powm(100, 0L, 3), 1) |
| 34 | vereq(mpz.powm(100L, 0L, 3), 1) |
| 35 | |
| 36 | vereq(mpz.powm(101, 5, 3333), 1616) |
| 37 | vereq(mpz.powm(101L, 5, 3333), 1616) |
| 38 | vereq(mpz.powm(101, 5L, 3333), 1616) |
| 39 | vereq(mpz.powm(101L, 5L, 3333), 1616) |
| 40 | |
| 41 | vereq(mpz.sqrt(100), 10) |
| 42 | vereq(mpz.sqrt(100L), 10) |
| 43 | vereq(mpz.sqrt(200), 14) |
| 44 | vereq(mpz.sqrt(200L), 14) |
| 45 | |
| 46 | vereq(mpz.sqrtrem(100), (10, 0)) |
| 47 | vereq(mpz.sqrtrem(100L), (10, 0)) |
| 48 | vereq(mpz.sqrtrem(200), (14, 4)) |
| 49 | vereq(mpz.sqrtrem(200L), (14, 4)) |
| 50 | |
| 51 | try: mpz.mpz(10.) |
| 52 | except TypeError: pass |
| 53 | else: raise TestFailed, 'mpz(10.) should raise a TypeError' |
| 54 | |
| 55 | try: mpz.powm(10.) |
| 56 | except TypeError: pass |
| 57 | else: raise TestFailed, 'powm(10.) should raise a TypeError' |
| 58 | |
| 59 | try: mpz.powm(100, 1, 0) |
| 60 | except ValueError: pass |
| 61 | else: raise TestFailed, 'powm(100, 1, 0) should raise a ValueError' |
| 62 | |
| 63 | try: mpz.divm(10, 10) |
| 64 | except TypeError: pass |
| 65 | else: raise TestFailed, 'divm(10, 10) should raise a TypeError' |
| 66 | |
| 67 | try: mpz.divm(10, 10, 10.) |
| 68 | except TypeError: pass |
| 69 | else: raise TestFailed, 'divm(10, 10, 10.) should raise a TypeError' |
| 70 | |
| 71 | try: mpz.gcd(10) |
| 72 | except TypeError: pass |
| 73 | else: raise TestFailed, 'gcd(10) should raise a TypeError' |
| 74 | |
| 75 | try: mpz.gcd(10, 10.) |
| 76 | except TypeError: pass |
| 77 | else: raise TestFailed, 'gcd(10, 10.) should raise a TypeError' |
| 78 | |
| 79 | try: mpz.gcdext(10) |
| 80 | except TypeError: pass |
| 81 | else: raise TestFailed, 'gcdext(10) should raise a TypeError' |
| 82 | |
| 83 | try: mpz.gcdext(10, 10.) |
| 84 | except TypeError: pass |
| 85 | else: raise TestFailed, 'gcdext(10, 10.) should raise a TypeError' |
| 86 | |
| 87 | try: mpz.mpz(-10).binary() |
| 88 | except ValueError: pass |
| 89 | else: raise TestFailed, 'mpz(-10).binary() should raise a ValueError' |