MCPcopy Index your code
hub / github.com/python/cpython / check_strtod

Method check_strtod

Lib/test/test_strtod.py:87–104  ·  view source on GitHub ↗

Compare the result of Python's builtin correctly rounded string->float conversion (using float) to a pure Python correctly rounded string->float implementation. Fail if the two methods give different results.

(self, s)

Source from the content-addressed store, hash-verified

85
86class StrtodTests(unittest.TestCase):
87 def check_strtod(self, s):
88 """Compare the result of Python's builtin correctly rounded
89 string->float conversion (using float) to a pure Python
90 correctly rounded string->float implementation. Fail if the
91 two methods give different results."""
92
93 try:
94 fs = float(s)
95 except OverflowError:
96 got = '-inf' if s[0] == '-' else 'inf'
97 except MemoryError:
98 got = 'memory error'
99 else:
100 got = fs.hex()
101 expected = strtod(s)
102 self.assertEqual(expected, got,
103 "Incorrectly rounded str->float conversion for {}: "
104 "expected {}, got {}".format(s, expected, got))
105
106 def test_short_halfway_cases(self):
107 # exact halfway cases with a small number of significant digits

Callers 7

test_halfway_casesMethod · 0.95
test_boundariesMethod · 0.95
test_bigcompMethod · 0.95
test_parsingMethod · 0.95
test_particularMethod · 0.95

Calls 4

strtodFunction · 0.85
hexMethod · 0.45
assertEqualMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected