diff options
author | Christian Heimes <christian@cheimes.de> | 2007-12-10 22:19:17 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-12-10 22:19:17 (GMT) |
commit | 827b35c9fed9e842c96b41198b26cee96a3e679b (patch) | |
tree | 14eb9fb523b002aab63bc4b99fbbd1bae16f56c2 /Lib/test/test_float.py | |
parent | b9f7f24c2537e40e06de6f12c29f786215b64912 (diff) | |
download | cpython-827b35c9fed9e842c96b41198b26cee96a3e679b.zip cpython-827b35c9fed9e842c96b41198b26cee96a3e679b.tar.gz cpython-827b35c9fed9e842c96b41198b26cee96a3e679b.tar.bz2 |
Issue #1580: New free format floating point representation based on "Floating-Point Printer Sample Code", by Robert G. Burger. For example repr(11./5) now returns '2.2' instead of '2.2000000000000002'.
Thanks to noam for the patch! I had to modify doubledigits.c slightly to support X64 and IA64 machines on Windows. I also added the new file to the three project files.
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r-- | Lib/test/test_float.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index 4360c54..2ba6dbc 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -1,5 +1,6 @@ import unittest, struct +import os from test import test_support class FormatFunctionsTestCase(unittest.TestCase): @@ -146,12 +147,26 @@ class FormatTestCase(unittest.TestCase): self.assertRaises(ValueError, format, 3.0, "s") +class ReprTestCase(unittest.TestCase): + def test_repr(self): + floats_file = open(os.path.join(os.path.split(__file__)[0], + 'floating_points.txt')) + for line in floats_file: + line = line.strip() + if not line or line.startswith('#'): + continue + v = eval(line) + self.assertEqual(v, eval(repr(v))) + floats_file.close() + + def test_main(): test_support.run_unittest( FormatFunctionsTestCase, UnknownFormatTestCase, IEEEFormatTestCase, - FormatTestCase) + FormatTestCase, + ReprTestCase) if __name__ == '__main__': test_main() |