[Python-checkins] r56930 - python/branches/decimal-branch/Lib/test/test_decimal.py
facundo.batista
python-checkins at python.org
Sat Aug 11 19:31:52 CEST 2007
Author: facundo.batista
Date: Sat Aug 11 19:31:52 2007
New Revision: 56930
Modified:
python/branches/decimal-branch/Lib/test/test_decimal.py
Log:
Support in the tests cases for 1ulp error in some specific
functions. This is needed because in the Cowlishaw's files
are test that give erroneus results, but still allowwd, to
test that very specific detail. Thanks Mike Dickinson.
Modified: python/branches/decimal-branch/Lib/test/test_decimal.py
==============================================================================
--- python/branches/decimal-branch/Lib/test/test_decimal.py (original)
+++ python/branches/decimal-branch/Lib/test/test_decimal.py Sat Aug 11 19:31:52 2007
@@ -65,6 +65,9 @@
# Slower, since it runs some things several times.
EXTENDEDERRORTEST = False
+# These are the decimal functions where is allowed to have an error of
+# 1 in the last position
+F1ULP = ('exp', 'ln', 'log10', 'power')
#Map the test cases' error names to the actual errors
@@ -296,11 +299,26 @@
myexceptions.sort()
theirexceptions.sort()
- self.assertEqual(result, ans,
+ if result != ans and fname in F1ULP and Inexact in theirexceptions:
+ # For transcendental functions we're allowed an error of
+ # up to 1ulp in an inexact result, so either ans+1ulp or
+ # ans-1ulp (but never both) may also be an acceptable
+ # result. Unfortunately there's no way of telling which
+ # one of these two numbers is the one that's within 1ulp,
+ # so we have to compare with both.
+ # We need specifically to support this, as in the Cowlishaw's
+ # files are tests that try not for the exact result, but
+ # with the error considered.
+ ans_as_decimal = Decimal(ans)
+ ans_plus_1ulp = str(ans_as_decimal.next_plus(self.context))
+ ans_minus_1ulp = str(ans_as_decimal.next_minus(self.context))
+ self.assert_(result in (ans_plus_1ulp, ans_minus_1ulp),
+ 'Incorrect answer for ' + s + ' -- got ' + result)
+ else:
+ self.assertEqual(result, ans,
'Incorrect answer for ' + s + ' -- got ' + result)
self.assertEqual(myexceptions, theirexceptions,
- 'Incorrect flags set in ' + s + ' -- got ' \
- + str(myexceptions))
+ 'Incorrect flags set in ' + s + ' -- got ' + str(myexceptions))
return
def getexceptions(self):
More information about the Python-checkins
mailing list