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