[Python-checkins] r65258 - python/trunk/Lib/test/test_math.py

mark.dickinson python-checkins at python.org
Sun Jul 27 09:15:29 CEST 2008


Author: mark.dickinson
Date: Sun Jul 27 09:15:29 2008
New Revision: 65258

Log:
Remove math.sum tests related to overflow, special values, and behaviour
near the extremes of the floating-point range.  (The behaviour of math.sum
should be regarded as undefined in these cases.)


Modified:
   python/trunk/Lib/test/test_math.py

Modified: python/trunk/Lib/test/test_math.py
==============================================================================
--- python/trunk/Lib/test/test_math.py	(original)
+++ python/trunk/Lib/test/test_math.py	Sun Jul 27 09:15:29 2008
@@ -702,86 +702,31 @@
                     break
             return total
 
-        from sys import float_info
-        maxfloat = float_info.max
-        twopow = 2.**(float_info.max_exp - 1)
-
         test_values = [
             ([], 0.0),
             ([0.0], 0.0),
             ([1e100, 1.0, -1e100, 1e-100, 1e50, -1.0, -1e50], 1e-100),
-            ([1e308, 1e308, -1e308], OverflowError),
-            ([-1e308, 1e308, 1e308], 1e308),
-            ([1e308, -1e308, 1e308], 1e308),
-            ([2.0**1023, 2.0**1023, -2.0**1000], OverflowError),
-            ([twopow, twopow, twopow, twopow, -twopow, -twopow, -twopow],
-             OverflowError),
             ([2.0**53, -0.5, -2.0**-54], 2.0**53-1.0),
             ([2.0**53, 1.0, 2.0**-100], 2.0**53+2.0),
             ([2.0**53+10.0, 1.0, 2.0**-100], 2.0**53+12.0),
-
             ([2.0**53-4.0, 0.5, 2.0**-54], 2.0**53-3.0),
-            ([2.0**1023-2.0**970, -1.0, 2.0**1023], OverflowError),
-            ([maxfloat, maxfloat*2.**-54], maxfloat),
-            ([maxfloat, maxfloat*2.**-53], OverflowError),
             ([1./n for n in range(1, 1001)], 7.4854708605503451),
             ([(-1.)**n/n for n in range(1, 1001)], -0.69264743055982025),
             ([1.7**(i+1)-1.7**i for i in range(1000)] + [-1.7**1000], -1.0),
-            ([INF, -INF, NAN], ValueError),
-            ([NAN, INF, -INF], ValueError),
-            ([INF, NAN, INF], ValueError),
-
-            ([INF, INF], OverflowError),
-            ([INF, -INF], ValueError),
-            ([-INF, 1e308, 1e308, -INF], OverflowError),
-            ([2.0**1023-2.0**970, 0.0, 2.0**1023], OverflowError),
-            ([2.0**1023-2.0**970, 1.0, 2.0**1023], OverflowError),
-            ([2.0**1023, 2.0**1023], OverflowError),
-            ([2.0**1023, 2.0**1023, -1.0], OverflowError),
-            ([twopow, twopow, twopow, twopow, -twopow, -twopow],
-             OverflowError),
-            ([twopow, twopow, twopow, twopow, -twopow, twopow], OverflowError),
-            ([-twopow, -twopow, -twopow, -twopow], OverflowError),
-
-            ([2.**1023, 2.**1023, -2.**971], OverflowError),
-            ([2.**1023, 2.**1023, -2.**970], OverflowError),
-            ([-2.**970,  2.**1023,  2.**1023, -2.**-1074], OverflowError),
-            ([ 2.**1023, 2.**1023, -2.**970,   2.**-1074], OverflowError),
-            ([-2.**1023,  2.**971, -2.**1023], -maxfloat),
-            ([-2.**1023, -2.**1023, 2.**970],   OverflowError),
-            ([-2.**1023,  -2.**1023,  2.**970,  2.**-1074], OverflowError),
-            ([-2.**-1074, -2.**1023, -2.**1023, 2.**970], OverflowError),
-            ([2.**930, -2.**980, 2.**1023, 2.**1023, twopow, -twopow],
-             OverflowError),
-            ([2.**1023, 2.**1023, -1e307], OverflowError),
             ([1e16, 1., 1e-16], 10000000000000002.0),
             ([1e16-2., 1.-2.**-53, -(1e16-2.), -(1.-2.**-53)], 0.0),
         ]
 
-        for i, (vals, s) in enumerate(test_values):
-            if isinstance(s, type) and issubclass(s, Exception):
-                try:
-                    m = math.sum(vals)
-                except s:
-                    pass
-                else:
-                    self.fail("test %d failed: got %r, expected %r "
-                              "for math.sum(%.100r)" %
-                              (i, m, s.__name__, vals))
-            else:
-                try:
-                    self.assertEqual(math.sum(vals), s)
-                except OverflowError:
-                    self.fail("test %d failed: got OverflowError, expected %r "
-                              "for math.sum(%.100r)" % (i, s, vals))
-                except ValueError:
-                    self.fail("test %d failed: got ValueError, expected %r "
-                              "for math.sum(%.100r)" % (i, s, vals))
-
-                # compare with output of msum above, but only when
-                # result isn't an IEEE special or an exception
-                if not math.isinf(s) and not math.isnan(s):
-                    self.assertEqual(msum(vals), s)
+        for i, (vals, expected) in enumerate(test_values):
+            try:
+                actual = math.sum(vals)
+            except OverflowError:
+                self.fail("test %d failed: got OverflowError, expected %r "
+                          "for math.sum(%.100r)" % (i, expected, vals))
+            except ValueError:
+                self.fail("test %d failed: got ValueError, expected %r "
+                          "for math.sum(%.100r)" % (i, expected, vals))
+            self.assertEqual(actual, expected)
 
         from random import random, gauss, shuffle
         for j in xrange(1000):


More information about the Python-checkins mailing list