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)
| 85 | |
| 86 | class 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 |
no test coverage detected