diff options
author | Raymond Hettinger <python@rcn.com> | 2008-06-22 11:39:13 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-06-22 11:39:13 (GMT) |
commit | d11a44312f2e80a9c4979063ce94233f924dcc5b (patch) | |
tree | 0b3e22010b4d0850aa80d32dcdb4ac3929dcbe03 /Lib/test/test_builtin.py | |
parent | dd811a4da785119089344f6de5735264f0ca5ec6 (diff) | |
download | cpython-d11a44312f2e80a9c4979063ce94233f924dcc5b.zip cpython-d11a44312f2e80a9c4979063ce94233f924dcc5b.tar.gz cpython-d11a44312f2e80a9c4979063ce94233f924dcc5b.tar.bz2 |
Merge 64438: hex/oct/bin can show floats exactly.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r-- | Lib/test/test_builtin.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 7a898b2..29c536a 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -553,6 +553,15 @@ class BuiltinTest(unittest.TestCase): self.assertEqual(hex(-16), '-0x10') self.assertEqual(hex(-16), '-0x10') self.assertRaises(TypeError, hex, {}) + self.assertEqual(hex(3.125), '0x19 * 2.0 ** -3') + self.assertEqual(hex(0.0), '0x0 * 2.0 ** 0') + for sv in float('nan'), float('inf'), float('-inf'): + self.assertEqual(hex(sv), repr(sv)) + for i in range(100): + x = random.expovariate(.05) + self.assertEqual(eval(hex(x)), x, (x, hex(x), eval(hex(x)))) + self.assertEqual(eval(hex(-x)), -x) + self.assertEqual(hex(-x), ('-' + hex(x))) def test_id(self): id(None) @@ -796,6 +805,15 @@ class BuiltinTest(unittest.TestCase): self.assertEqual(oct(-100), '-0o144') self.assertEqual(oct(-100), '-0o144') self.assertRaises(TypeError, oct, ()) + self.assertEqual(oct(3.125), '0o31 * 2.0 ** -3') + self.assertEqual(oct(0.0), '0o0 * 2.0 ** 0') + for sv in float('nan'), float('inf'), float('-inf'): + self.assertEqual(oct(sv), repr(sv)) + for i in range(100): + x = random.expovariate(.05) + self.assertEqual(eval(oct(x)), x) + self.assertEqual(eval(oct(-x)), -x) + self.assertEqual(oct(-x), ('-' + oct(x))) def write_testfile(self): # NB the first 4 lines are also used to test input, below @@ -1213,6 +1231,15 @@ class BuiltinTest(unittest.TestCase): self.assertEqual(bin(2**65-1), '0b' + '1' * 65) self.assertEqual(bin(-(2**65)), '-0b1' + '0' * 65) self.assertEqual(bin(-(2**65-1)), '-0b' + '1' * 65) + self.assertEqual(bin(3.125), '0b11001 * 2.0 ** -3') + self.assertEqual(bin(0.0), '0b0 * 2.0 ** 0') + for sv in float('nan'), float('inf'), float('-inf'): + self.assertEqual(bin(sv), repr(sv)) + for i in range(100): + x = random.expovariate(.05) + self.assertEqual(eval(bin(x)), x) + self.assertEqual(eval(bin(-x)), -x) + self.assertEqual(bin(-x), ('-' + bin(x))) class TestSorted(unittest.TestCase): |