annotate Lib/test/test_long.py @ 25135:0f0016632be4 legacy-trunk

_formatparam(), set_param(): RFC 2231 encoding support by Oleg Broytmann in SF patch #600096. Specifically, the former function now encodes the triplets, while the latter adds optional charset and language arguments.
author Barry Warsaw <barry@python.org>
date Fri, 06 Sep 2002 03:55:04 +0000
parents 1c63d3082656
children d31ddc66b1b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 22739
diff changeset
1 from test.test_support import verify, verbose, TestFailed, fcmp
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 from string import join
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 from random import random, randint
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 # SHIFT should match the value in longintrepr.h for best testing.
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 SHIFT = 15
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 BASE = 2 ** SHIFT
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 MASK = BASE - 1
24778
f1d18fcd56e6 Machines-- and Python --are a lot faster in relevant ways since this
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
9 KARATSUBA_CUTOFF = 35 # from longobject.c
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 # Max number of base BASE digits to use in test cases. Doubling
24778
f1d18fcd56e6 Machines-- and Python --are a lot faster in relevant ways since this
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
12 # this will more than double the runtime.
f1d18fcd56e6 Machines-- and Python --are a lot faster in relevant ways since this
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
13 MAXDIGITS = 15
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
15 # build some special values
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
16 special = map(long, [0, 1, 2, BASE, BASE >> 1])
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
17 special.append(0x5555555555555555L)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
18 special.append(0xaaaaaaaaaaaaaaaaL)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
19 # some solid strings of one bits
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
20 p2 = 4L # 0 and 1 already added
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
21 for i in range(2*SHIFT):
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
22 special.append(p2 - 1)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
23 p2 = p2 << 1
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
24 del p2
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
25 # add complements & negations
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
26 special = special + map(lambda x: ~x, special) + \
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
27 map(lambda x: -x, special)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
28
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 # ------------------------------------------------------------ utilities
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 # Use check instead of assert so the test still does something
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 # under -O.
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 def check(ok, *args):
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 if not ok:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 raise TestFailed, join(map(str, args), " ")
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
38 # Get quasi-random long consisting of ndigits digits (in base BASE).
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
39 # quasi == the most-significant digit will not be 0, and the number
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
40 # is constructed to contain long strings of 0 and 1 bits. These are
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
41 # more likely than random bits to provoke digit-boundary errors.
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
42 # The sign of the number is also random.
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
43
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
44 def getran(ndigits):
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15305
diff changeset
45 verify(ndigits > 0)
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
46 nbits_hi = ndigits * SHIFT
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
47 nbits_lo = nbits_hi - SHIFT + 1
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
48 answer = 0L
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
49 nbits = 0
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
50 r = int(random() * (SHIFT * 2)) | 1 # force 1 bits to start
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
51 while nbits < nbits_lo:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
52 bits = (r >> 1) + 1
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
53 bits = min(bits, nbits_hi - nbits)
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15305
diff changeset
54 verify(1 <= bits <= SHIFT)
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
55 nbits = nbits + bits
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
56 answer = answer << bits
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
57 if r & 1:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
58 answer = answer | ((1 << bits) - 1)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
59 r = int(random() * (SHIFT * 2))
15957
c1a8deb15f0e This patch removes all uses of "assert" in the regression test suite
Marc-André Lemburg <mal@egenix.com>
parents: 15305
diff changeset
60 verify(nbits_lo <= nbits <= nbits_hi)
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
61 if random() < 0.5:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
62 answer = -answer
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
63 return answer
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
64
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 # Get random long consisting of ndigits random digits (relative to base
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 # BASE). The sign bit is also random.
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
68 def getran2(ndigits):
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 answer = 0L
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 for i in range(ndigits):
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 answer = (answer << SHIFT) | randint(0, MASK)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 if random() < 0.5:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 answer = -answer
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 return answer
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
75
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 # --------------------------------------------------------------- divmod
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
77
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 def test_division_2(x, y):
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 q, r = divmod(x, y)
19694
3716b116fb31 The first batch of changes recommended by the fixdiv tool. These are
Guido van Rossum <guido@python.org>
parents: 19679
diff changeset
80 q2, r2 = x//y, x%y
12342
aa3b02a038a3 Christian Tismer: added test to ensure that multiplication commutes.
Guido van Rossum <guido@python.org>
parents: 11627
diff changeset
81 pab, pba = x*y, y*x
aa3b02a038a3 Christian Tismer: added test to ensure that multiplication commutes.
Guido van Rossum <guido@python.org>
parents: 11627
diff changeset
82 check(pab == pba, "multiplication does not commute for", x, y)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 check(q == q2, "divmod returns different quotient than / for", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 check(r == r2, "divmod returns different mod than % for", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 check(x == q*y + r, "x != q*y + r after divmod on", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 if y > 0:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 check(0 <= r < y, "bad mod from divmod on", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 else:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 check(y < r <= 0, "bad mod from divmod on", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 def test_division(maxdigits=MAXDIGITS):
19452
10b44e3b3905 Remove test_long's expected-output file.
Tim Peters <tim.peters@gmail.com>
parents: 15957
diff changeset
92 if verbose:
10b44e3b3905 Remove test_long's expected-output file.
Tim Peters <tim.peters@gmail.com>
parents: 15957
diff changeset
93 print "long / * % divmod"
24778
f1d18fcd56e6 Machines-- and Python --are a lot faster in relevant ways since this
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
94 digits = range(1, maxdigits+1) + range(KARATSUBA_CUTOFF,
24779
53cb71638841 test_division(): Added one larger digits value, to ensure that the
Tim Peters <tim.peters@gmail.com>
parents: 24778
diff changeset
95 KARATSUBA_CUTOFF + 14)
53cb71638841 test_division(): Added one larger digits value, to ensure that the
Tim Peters <tim.peters@gmail.com>
parents: 24778
diff changeset
96 digits.append(KARATSUBA_CUTOFF * 3)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 for lenx in digits:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 x = getran(lenx)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 for leny in digits:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 y = getran(leny) or 1L
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 test_division_2(x, y)
24794
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
102 # ------------------------------------------------------------ karatsuba
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
24794
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
104 def test_karatsuba():
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
105
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
106 if verbose:
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
107 print "Karatsuba"
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
108
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
109 digits = range(1, 5) + range(KARATSUBA_CUTOFF, KARATSUBA_CUTOFF + 10)
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
110 digits.extend([KARATSUBA_CUTOFF * 10, KARATSUBA_CUTOFF * 100])
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
111
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
112 bits = [digit * SHIFT for digit in digits]
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
113
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
114 # Test products of long strings of 1 bits -- (2**x-1)*(2**y-1) ==
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
115 # 2**(x+y) - 2**x - 2**y + 1, so the proper result is easy to check.
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
116 for abits in bits:
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
117 a = (1L << abits) - 1
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
118 for bbits in bits:
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
119 if bbits < abits:
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
120 continue
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
121 b = (1L << bbits) - 1
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
122 x = a * b
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
123 y = ((1L << (abits + bbits)) -
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
124 (1L << abits) -
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
125 (1L << bbits) +
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
126 1)
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
127 check(x == y, "bad result for", a, "*", b, x, y)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 # -------------------------------------------------------------- ~ & | ^
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 def test_bitop_identities_1(x):
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
131 check(x & 0 == 0, "x & 0 != 0 for", x)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
132 check(x | 0 == x, "x | 0 != x for", x)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
133 check(x ^ 0 == x, "x ^ 0 != x for", x)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
134 check(x & -1 == x, "x & -1 != x for", x)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
135 check(x | -1 == -1, "x | -1 != -1 for", x)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
136 check(x ^ -1 == ~x, "x ^ -1 != ~x for", x)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 check(x == ~~x, "x != ~~x for", x)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 check(x & x == x, "x & x != x for", x)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 check(x | x == x, "x | x != x for", x)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 check(x ^ x == 0, "x ^ x != 0 for", x)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 check(x & ~x == 0, "x & ~x != 0 for", x)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 check(x | ~x == -1, "x | ~x != -1 for", x)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 check(x ^ ~x == -1, "x ^ ~x != -1 for", x)
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
144 check(-x == 1 + ~x == ~(x-1), "not -x == 1 + ~x == ~(x-1) for", x)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
145 for n in range(2*SHIFT):
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
146 p2 = 2L ** n
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
147 check(x << n >> n == x, "x << n >> n != x for", x, n)
19694
3716b116fb31 The first batch of changes recommended by the fixdiv tool. These are
Guido van Rossum <guido@python.org>
parents: 19679
diff changeset
148 check(x // p2 == x >> n, "x // p2 != x >> n for x n p2", x, n, p2)
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
149 check(x * p2 == x << n, "x * p2 != x << n for x n p2", x, n, p2)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
150 check(x & -p2 == x >> n << n == x & ~(p2 - 1),
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
151 "not x & -p2 == x >> n << n == x & ~(p2 - 1) for x n p2",
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
152 x, n, p2)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
153
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 def test_bitop_identities_2(x, y):
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
155 check(x & y == y & x, "x & y != y & x for", x, y)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
156 check(x | y == y | x, "x | y != y | x for", x, y)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
157 check(x ^ y == y ^ x, "x ^ y != y ^ x for", x, y)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
158 check(x ^ y ^ x == y, "x ^ y ^ x != y for", x, y)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 check(x & y == ~(~x | ~y), "x & y != ~(~x | ~y) for", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 check(x | y == ~(~x & ~y), "x | y != ~(~x & ~y) for", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 check(x ^ y == (x | y) & ~(x & y),
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 "x ^ y != (x | y) & ~(x & y) for", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 check(x ^ y == (x & ~y) | (~x & y),
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 "x ^ y == (x & ~y) | (~x & y) for", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 check(x ^ y == (x | y) & (~x | ~y),
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 "x ^ y == (x | y) & (~x | ~y) for", x, y)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 def test_bitop_identities_3(x, y, z):
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
169 check((x & y) & z == x & (y & z),
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
170 "(x & y) & z != x & (y & z) for", x, y, z)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
171 check((x | y) | z == x | (y | z),
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
172 "(x | y) | z != x | (y | z) for", x, y, z)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
173 check((x ^ y) ^ z == x ^ (y ^ z),
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
174 "(x ^ y) ^ z != x ^ (y ^ z) for", x, y, z)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 check(x & (y | z) == (x & y) | (x & z),
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 "x & (y | z) != (x & y) | (x & z) for", x, y, z)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 check(x | (y & z) == (x | y) & (x | z),
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 "x | (y & z) != (x | y) & (x | z) for", x, y, z)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
179
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 def test_bitop_identities(maxdigits=MAXDIGITS):
19452
10b44e3b3905 Remove test_long's expected-output file.
Tim Peters <tim.peters@gmail.com>
parents: 15957
diff changeset
181 if verbose:
10b44e3b3905 Remove test_long's expected-output file.
Tim Peters <tim.peters@gmail.com>
parents: 15957
diff changeset
182 print "long bit-operation identities"
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
183 for x in special:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
184 test_bitop_identities_1(x)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 digits = range(1, maxdigits+1)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 for lenx in digits:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 x = getran(lenx)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 test_bitop_identities_1(x)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 for leny in digits:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 y = getran(leny)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 test_bitop_identities_2(x, y)
19694
3716b116fb31 The first batch of changes recommended by the fixdiv tool. These are
Guido van Rossum <guido@python.org>
parents: 19679
diff changeset
192 test_bitop_identities_3(x, y, getran((lenx + leny)//2))
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
193
11627
d4ea1361731b Revise tests to support str(<long int object>) not appending "L".
Fred Drake <fdrake@acm.org>
parents: 9209
diff changeset
194 # ------------------------------------------------- hex oct repr str atol
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
195
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 def slow_format(x, base):
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 if (x, base) == (0, 8):
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 # this is an oddball!
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 return "0L"
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 digits = []
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 sign = 0
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 if x < 0:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 sign, x = 1, -x
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 while x:
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 x, r = divmod(x, base)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 digits.append(int(r))
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 digits.reverse()
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 digits = digits or [0]
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
209 return '-'[:sign] + \
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 {8: '0', 10: '', 16: '0x'}[base] + \
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
211 join(map(lambda i: "0123456789ABCDEF"[i], digits), '') + \
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 "L"
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 def test_format_1(x):
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
215 from string import atol
11627
d4ea1361731b Revise tests to support str(<long int object>) not appending "L".
Fred Drake <fdrake@acm.org>
parents: 9209
diff changeset
216 for base, mapper in (8, oct), (10, repr), (16, hex):
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 got = mapper(x)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 expected = slow_format(x, base)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 check(got == expected, mapper.__name__, "returned",
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 got, "but expected", expected, "for", x)
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
221 check(atol(got, 0) == x, 'atol("%s", 0) !=' % got, x)
11627
d4ea1361731b Revise tests to support str(<long int object>) not appending "L".
Fred Drake <fdrake@acm.org>
parents: 9209
diff changeset
222 # str() has to be checked a little differently since there's no
d4ea1361731b Revise tests to support str(<long int object>) not appending "L".
Fred Drake <fdrake@acm.org>
parents: 9209
diff changeset
223 # trailing "L"
d4ea1361731b Revise tests to support str(<long int object>) not appending "L".
Fred Drake <fdrake@acm.org>
parents: 9209
diff changeset
224 got = str(x)
d4ea1361731b Revise tests to support str(<long int object>) not appending "L".
Fred Drake <fdrake@acm.org>
parents: 9209
diff changeset
225 expected = slow_format(x, 10)[:-1]
d4ea1361731b Revise tests to support str(<long int object>) not appending "L".
Fred Drake <fdrake@acm.org>
parents: 9209
diff changeset
226 check(got == expected, mapper.__name__, "returned",
d4ea1361731b Revise tests to support str(<long int object>) not appending "L".
Fred Drake <fdrake@acm.org>
parents: 9209
diff changeset
227 got, "but expected", expected, "for", x)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
228
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 def test_format(maxdigits=MAXDIGITS):
19452
10b44e3b3905 Remove test_long's expected-output file.
Tim Peters <tim.peters@gmail.com>
parents: 15957
diff changeset
230 if verbose:
10b44e3b3905 Remove test_long's expected-output file.
Tim Peters <tim.peters@gmail.com>
parents: 15957
diff changeset
231 print "long str/hex/oct/atol"
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
232 for x in special:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
233 test_format_1(x)
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 for i in range(10):
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 for lenx in range(1, maxdigits+1):
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 x = getran(lenx)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 test_format_1(x)
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
238
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
239 # ----------------------------------------------------------------- misc
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
240
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
241 def test_misc(maxdigits=MAXDIGITS):
19452
10b44e3b3905 Remove test_long's expected-output file.
Tim Peters <tim.peters@gmail.com>
parents: 15957
diff changeset
242 if verbose:
10b44e3b3905 Remove test_long's expected-output file.
Tim Peters <tim.peters@gmail.com>
parents: 15957
diff changeset
243 print "long miscellaneous operations"
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
244 import sys
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
245
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
246 # check the extremes in int<->long conversion
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
247 hugepos = sys.maxint
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
248 hugeneg = -hugepos - 1
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
249 hugepos_aslong = long(hugepos)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
250 hugeneg_aslong = long(hugeneg)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
251 check(hugepos == hugepos_aslong, "long(sys.maxint) != sys.maxint")
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
252 check(hugeneg == hugeneg_aslong,
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
253 "long(-sys.maxint-1) != -sys.maxint-1")
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
254
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
255 # long -> int should not fail for hugepos_aslong or hugeneg_aslong
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
256 try:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
257 check(int(hugepos_aslong) == hugepos,
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
258 "converting sys.maxint to long and back to int fails")
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
259 except OverflowError:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
260 raise TestFailed, "int(long(sys.maxint)) overflowed!"
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
261 try:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
262 check(int(hugeneg_aslong) == hugeneg,
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
263 "converting -sys.maxint-1 to long and back to int fails")
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
264 except OverflowError:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
265 raise TestFailed, "int(long(-sys.maxint-1)) overflowed!"
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
266
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
267 # but long -> int should overflow for hugepos+1 and hugeneg-1
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
268 x = hugepos_aslong + 1
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
269 try:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
270 int(x)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
271 raise ValueError
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
272 except OverflowError:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
273 pass
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
274 except:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
275 raise TestFailed, "int(long(sys.maxint) + 1) didn't overflow"
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
276
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
277 x = hugeneg_aslong - 1
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
278 try:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
279 int(x)
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
280 raise ValueError
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
281 except OverflowError:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
282 pass
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
283 except:
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
284 raise TestFailed, "int(long(-sys.maxint-1) - 1) didn't overflow"
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
285
19458
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
286 # ----------------------------------- tests of auto int->long conversion
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
287
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
288 def test_auto_overflow():
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
289 import math, sys
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
290
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
291 if verbose:
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
292 print "auto-convert int->long on overflow"
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
293
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
294 special = [0, 1, 2, 3, sys.maxint-1, sys.maxint, sys.maxint+1]
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
295 sqrt = int(math.sqrt(sys.maxint))
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
296 special.extend([sqrt-1, sqrt, sqrt+1])
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
297 special.extend([-i for i in special])
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
298
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
299 def checkit(*args):
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
300 # Heavy use of nested scopes here!
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
301 verify(got == expected, "for %r expected %r got %r" %
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
302 (args, expected, got))
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
303
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
304 for x in special:
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
305 longx = long(x)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
306
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
307 expected = -longx
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
308 got = -x
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
309 checkit('-', x)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
310
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
311 for y in special:
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
312 longy = long(y)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
313
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
314 expected = longx + longy
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
315 got = x + y
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
316 checkit(x, '+', y)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
317
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
318 expected = longx - longy
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
319 got = x - y
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
320 checkit(x, '-', y)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
321
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
322 expected = longx * longy
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
323 got = x * y
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
324 checkit(x, '*', y)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
325
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
326 if y:
19698
372d8c1d2b64 Revert one of the "division fixes" in test_long. It intends to try both
Tim Peters <tim.peters@gmail.com>
parents: 19694
diff changeset
327 expected = longx / longy
372d8c1d2b64 Revert one of the "division fixes" in test_long. It intends to try both
Tim Peters <tim.peters@gmail.com>
parents: 19694
diff changeset
328 got = x / y
19458
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
329 checkit(x, '/', y)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
330
19459
50019cb784e0 Add a test for the new // operator too.
Tim Peters <tim.peters@gmail.com>
parents: 19458
diff changeset
331 expected = longx // longy
50019cb784e0 Add a test for the new // operator too.
Tim Peters <tim.peters@gmail.com>
parents: 19458
diff changeset
332 got = x // y
50019cb784e0 Add a test for the new // operator too.
Tim Peters <tim.peters@gmail.com>
parents: 19458
diff changeset
333 checkit(x, '//', y)
50019cb784e0 Add a test for the new // operator too.
Tim Peters <tim.peters@gmail.com>
parents: 19458
diff changeset
334
19458
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
335 expected = divmod(longx, longy)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
336 got = divmod(longx, longy)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
337 checkit(x, 'divmod', y)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
338
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
339 if abs(y) < 5 and not (x == 0 and y < 0):
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
340 expected = longx ** longy
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
341 got = x ** y
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
342 checkit(x, '**', y)
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
343
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
344 for z in special:
19666
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
345 if z != 0 :
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
346 if y >= 0:
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
347 expected = pow(longx, longy, long(z))
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
348 got = pow(x, y, z)
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
349 checkit('pow', x, y, '%', z)
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
350 else:
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
351 try:
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
352 pow(longx, longy, long(z))
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
353 except TypeError:
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
354 pass
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
355 else:
cf65ebf87560 New restriction on pow(x, y, z): If z is not None, x and y must be of
Tim Peters <tim.peters@gmail.com>
parents: 19459
diff changeset
356 raise TestFailed("pow%r should have raised "
22739
e449c81c1c01 Format strings (tuples,) appropriately
Neal Norwitz <nnorwitz@gmail.com>
parents: 19713
diff changeset
357 "TypeError" % ((longx, longy, long(z)),))
19458
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
358
19674
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
359 # ---------------------------------------- tests of long->float overflow
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
360
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
361 def test_float_overflow():
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
362 import math
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
363
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
364 if verbose:
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
365 print "long->float overflow"
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
366
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
367 for x in -2.0, -1.0, 0.0, 1.0, 2.0:
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
368 verify(float(long(x)) == x)
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
369
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
370 huge = 1L << 30000
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
371 mhuge = -huge
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
372 namespace = {'huge': huge, 'mhuge': mhuge, 'math': math}
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
373 for test in ["float(huge)", "float(mhuge)",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
374 "complex(huge)", "complex(mhuge)",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
375 "complex(huge, 1)", "complex(mhuge, 1)",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
376 "complex(1, huge)", "complex(1, mhuge)",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
377 "1. + huge", "huge + 1.", "1. + mhuge", "mhuge + 1.",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
378 "1. - huge", "huge - 1.", "1. - mhuge", "mhuge - 1.",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
379 "1. * huge", "huge * 1.", "1. * mhuge", "mhuge * 1.",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
380 "1. // huge", "huge // 1.", "1. // mhuge", "mhuge // 1.",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
381 "1. / huge", "huge / 1.", "1. / mhuge", "mhuge / 1.",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
382 "1. ** huge", "huge ** 1.", "1. ** mhuge", "mhuge ** 1.",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
383 "math.sin(huge)", "math.sin(mhuge)",
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
384 "math.sqrt(huge)", "math.sqrt(mhuge)", # should do better
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
385 "math.floor(huge)", "math.floor(mhuge)"]:
19679
6958784b1cef Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19674
diff changeset
386
19674
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
387 try:
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
388 eval(test, namespace)
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
389 except OverflowError:
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
390 pass
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
391 else:
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
392 raise TestFailed("expected OverflowError from %s" % test)
19713
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
393
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
394 # ---------------------------------------------- test huge log and log10
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
395
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
396 def test_logs():
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
397 import math
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
398
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
399 if verbose:
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
400 print "log and log10"
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
401
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
402 LOG10E = math.log10(math.e)
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
403
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
404 for exp in range(10) + [100, 1000, 10000]:
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
405 value = 10 ** exp
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
406 log10 = math.log10(value)
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
407 verify(fcmp(log10, exp) == 0)
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
408
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
409 # log10(value) == exp, so log(value) == log10(value)/log10(e) ==
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
410 # exp/LOG10E
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
411 expected = exp / LOG10E
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
412 log = math.log(value)
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
413 verify(fcmp(log, expected) == 0)
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
414
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
415 for bad in -(1L << 10000), -2L, 0L:
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
416 try:
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
417 math.log(bad)
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
418 raise TestFailed("expected ValueError from log(<= 0)")
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
419 except ValueError:
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
420 pass
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
421
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
422 try:
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
423 math.log10(bad)
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
424 raise TestFailed("expected ValueError from log10(<= 0)")
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
425 except ValueError:
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
426 pass
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
427
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 # ---------------------------------------------------------------- do it
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
429
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 test_division()
24794
1c63d3082656 Added a test specifically to tickle Karatsuba; it costs no appreciable
Tim Peters <tim.peters@gmail.com>
parents: 24779
diff changeset
431 test_karatsuba()
8989
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 test_bitop_identities()
5fb3c683e862 Add Tim Peters' test for long ints
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 test_format()
9209
d3af310f230c New test_long.py from Tim Peters.
Guido van Rossum <guido@python.org>
parents: 8989
diff changeset
434 test_misc()
19458
8f90e1f50c11 SF bug [#454456] int overflow code needs tests.
Tim Peters <tim.peters@gmail.com>
parents: 19452
diff changeset
435 test_auto_overflow()
19674
715244108faa Raise OverflowError when appropriate on long->float conversion. Most of
Tim Peters <tim.peters@gmail.com>
parents: 19666
diff changeset
436 test_float_overflow()
19713
9433dd3c197e Return reasonable results for math.log(long) and math.log10(long) (we were
Tim Peters <tim.peters@gmail.com>
parents: 19698
diff changeset
437 test_logs()