aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_strtod.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_strtod.py')
-rw-r--r--Lib/test/test_strtod.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/Lib/test/test_strtod.py b/Lib/test/test_strtod.py
index 7bc595daf3a..7a42a893b17 100644
--- a/Lib/test/test_strtod.py
+++ b/Lib/test/test_strtod.py
@@ -2,11 +2,10 @@
# introduced in Python 2.7 and 3.1.
import random
-import struct
import unittest
import re
import sys
-from test import test_support
+import test.support
if getattr(sys, 'float_repr_style', '') != 'short':
raise unittest.SkipTest('correctly-rounded string->float conversions '
@@ -113,7 +112,7 @@ class StrtodTests(unittest.TestCase):
lower = -(-2**53//5**k)
if lower % 2 == 0:
lower += 1
- for i in xrange(TEST_SIZE):
+ for i in range(TEST_SIZE):
# Select a random odd n in [2**53/5**k,
# 2**54/5**k). Then n * 10**k gives a halfway case
# with small number of significant digits.
@@ -149,7 +148,7 @@ class StrtodTests(unittest.TestCase):
def test_halfway_cases(self):
# test halfway cases for the round-half-to-even rule
- for i in xrange(100 * TEST_SIZE):
+ for i in range(100 * TEST_SIZE):
# bit pattern for a random finite positive (or +0.0) float
bits = random.randrange(2047*2**52)
@@ -184,7 +183,7 @@ class StrtodTests(unittest.TestCase):
(0, -327, 4941), # zero
]
for n, e, u in boundaries:
- for j in xrange(1000):
+ for j in range(1000):
digits = n + random.randrange(-3*u, 3*u)
exponent = e
s = '{}e{}'.format(digits, exponent)
@@ -197,9 +196,9 @@ class StrtodTests(unittest.TestCase):
# test values close to 2**-1075, the underflow boundary; similar
# to boundary_tests, except that the random error doesn't scale
# with n
- for exponent in xrange(-400, -320):
+ for exponent in range(-400, -320):
base = 10**-exponent // 2**1075
- for j in xrange(TEST_SIZE):
+ for j in range(TEST_SIZE):
digits = base + random.randrange(-1000, 1000)
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)
@@ -207,7 +206,7 @@ class StrtodTests(unittest.TestCase):
def test_bigcomp(self):
for ndigs in 5, 10, 14, 15, 16, 17, 18, 19, 20, 40, 41, 50:
dig10 = 10**ndigs
- for i in xrange(10 * TEST_SIZE):
+ for i in range(10 * TEST_SIZE):
digits = random.randrange(dig10)
exponent = random.randrange(-400, 400)
s = '{}e{}'.format(digits, exponent)
@@ -220,16 +219,16 @@ class StrtodTests(unittest.TestCase):
# put together random short valid strings
# \d*[.\d*]?e
- for i in xrange(1000):
- for j in xrange(TEST_SIZE):
+ for i in range(1000):
+ for j in range(TEST_SIZE):
s = random.choice(signs)
intpart_len = random.randrange(5)
- s += ''.join(random.choice(digits) for _ in xrange(intpart_len))
+ s += ''.join(random.choice(digits) for _ in range(intpart_len))
if random.choice([True, False]):
s += '.'
fracpart_len = random.randrange(5)
s += ''.join(random.choice(digits)
- for _ in xrange(fracpart_len))
+ for _ in range(fracpart_len))
else:
fracpart_len = 0
if random.choice([True, False]):
@@ -237,7 +236,7 @@ class StrtodTests(unittest.TestCase):
s += random.choice(signs)
exponent_len = random.randrange(1, 4)
s += ''.join(random.choice(digits)
- for _ in xrange(exponent_len))
+ for _ in range(exponent_len))
if intpart_len + fracpart_len:
self.check_strtod(s)
@@ -388,12 +387,19 @@ class StrtodTests(unittest.TestCase):
'999999999999999944488848768742172978818416595458984375e-54',
'9999999999999999444888487687421729788184165954589843749999999e-54',
'9999999999999999444888487687421729788184165954589843750000001e-54',
+ # Value found by Rick Regan that gives a result of 2**-968
+ # under Gay's dtoa.c (as of Nov 04, 2010); since fixed.
+ # (Fixed some time ago in Python's dtoa.c.)
+ '0.0000000000000000000000000000000000000000100000000' #...
+ '000000000576129113423785429971690421191214034235435' #...
+ '087147763178149762956868991692289869941246658073194' #...
+ '51982237978882039897143840789794921875',
]
for s in test_strings:
self.check_strtod(s)
def test_main():
- test_support.run_unittest(StrtodTests)
+ test.support.run_unittest(StrtodTests)
if __name__ == "__main__":
test_main()