Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
92cb4a8c
Kaydet (Commit)
92cb4a8c
authored
Şub 21, 2010
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Reduce number of random tests in test_strtod, to avoid hogging buildbot time.
üst
45ad801e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
36 deletions
+30
-36
test_strtod.py
Lib/test/test_strtod.py
+30
-36
No files found.
Lib/test/test_strtod.py
Dosyayı görüntüle @
92cb4a8c
...
...
@@ -80,7 +80,7 @@ def strtod(s, mant_dig=53, min_exp = -1021, max_exp = 1024):
hexdigs
,
e
+
4
*
hexdigs
)
TEST_SIZE
=
1
6
TEST_SIZE
=
1
0
class
StrtodTests
(
unittest
.
TestCase
):
def
check_strtod
(
self
,
s
):
...
...
@@ -111,7 +111,7 @@ class StrtodTests(unittest.TestCase):
lower
=
-
(
-
2
**
53
//
5
**
k
)
if
lower
%
2
==
0
:
lower
+=
1
for
i
in
xrange
(
10
*
TEST_SIZE
):
for
i
in
xrange
(
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.
...
...
@@ -147,34 +147,29 @@ class StrtodTests(unittest.TestCase):
def
test_halfway_cases
(
self
):
# test halfway cases for the round-half-to-even rule
for
i
in
xrange
(
1000
):
for
j
in
xrange
(
TEST_SIZE
):
# bit pattern for a random finite positive (or +0.0) float
bits
=
random
.
randrange
(
2047
*
2
**
52
)
# convert bit pattern to a number of the form m * 2**e
e
,
m
=
divmod
(
bits
,
2
**
52
)
if
e
:
m
,
e
=
m
+
2
**
52
,
e
-
1
e
-=
1074
# add 0.5 ulps
m
,
e
=
2
*
m
+
1
,
e
-
1
# convert to a decimal string
if
e
>=
0
:
digits
=
m
<<
e
exponent
=
0
else
:
# m * 2**e = (m * 5**-e) * 10**e
digits
=
m
*
5
**-
e
exponent
=
e
s
=
'{}e{}'
.
format
(
digits
,
exponent
)
self
.
check_strtod
(
s
)
# get expected answer via struct, to triple check
#fs = struct.unpack('<d', struct.pack('<Q', bits + (bits&1)))[0]
#self.assertEqual(fs, float(s))
for
i
in
xrange
(
100
*
TEST_SIZE
):
# bit pattern for a random finite positive (or +0.0) float
bits
=
random
.
randrange
(
2047
*
2
**
52
)
# convert bit pattern to a number of the form m * 2**e
e
,
m
=
divmod
(
bits
,
2
**
52
)
if
e
:
m
,
e
=
m
+
2
**
52
,
e
-
1
e
-=
1074
# add 0.5 ulps
m
,
e
=
2
*
m
+
1
,
e
-
1
# convert to a decimal string
if
e
>=
0
:
digits
=
m
<<
e
exponent
=
0
else
:
# m * 2**e = (m * 5**-e) * 10**e
digits
=
m
*
5
**-
e
exponent
=
e
s
=
'{}e{}'
.
format
(
digits
,
exponent
)
self
.
check_strtod
(
s
)
def
test_boundaries
(
self
):
# boundaries expressed as triples (n, e, u), where
...
...
@@ -188,11 +183,10 @@ class StrtodTests(unittest.TestCase):
]
for
n
,
e
,
u
in
boundaries
:
for
j
in
xrange
(
1000
):
for
i
in
xrange
(
TEST_SIZE
):
digits
=
n
+
random
.
randrange
(
-
3
*
u
,
3
*
u
)
exponent
=
e
s
=
'{}e{}'
.
format
(
digits
,
exponent
)
self
.
check_strtod
(
s
)
digits
=
n
+
random
.
randrange
(
-
3
*
u
,
3
*
u
)
exponent
=
e
s
=
'{}e{}'
.
format
(
digits
,
exponent
)
self
.
check_strtod
(
s
)
n
*=
10
u
*=
10
e
-=
1
...
...
@@ -211,7 +205,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
0
*
TEST_SIZE
):
for
i
in
xrange
(
10
*
TEST_SIZE
):
digits
=
random
.
randrange
(
dig10
)
exponent
=
random
.
randrange
(
-
400
,
400
)
s
=
'{}e{}'
.
format
(
digits
,
exponent
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment