mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
This commit is contained in:
parent
55b8c3e26f
commit
2fc9263df5
4 changed files with 145 additions and 40 deletions
|
@ -838,6 +838,19 @@ class DecimalArithmeticOperatorsTest(unittest.TestCase):
|
|||
self.assertEqual(-Decimal(45), Decimal(-45)) # -
|
||||
self.assertEqual(abs(Decimal(45)), abs(Decimal(-45))) # abs
|
||||
|
||||
def test_nan_comparisons(self):
|
||||
n = Decimal('NaN')
|
||||
s = Decimal('sNaN')
|
||||
i = Decimal('Inf')
|
||||
f = Decimal('2')
|
||||
for x, y in [(n, n), (n, i), (i, n), (n, f), (f, n),
|
||||
(s, n), (n, s), (s, i), (i, s), (s, f), (f, s), (s, s)]:
|
||||
self.assert_(x != y)
|
||||
self.assert_(not (x == y))
|
||||
self.assert_(not (x < y))
|
||||
self.assert_(not (x <= y))
|
||||
self.assert_(not (x > y))
|
||||
self.assert_(not (x >= y))
|
||||
|
||||
# The following are two functions used to test threading in the next class
|
||||
|
||||
|
@ -1147,7 +1160,12 @@ class DecimalUsabilityTest(unittest.TestCase):
|
|||
checkSameDec("__add__", True)
|
||||
checkSameDec("__div__", True)
|
||||
checkSameDec("__divmod__", True)
|
||||
checkSameDec("__cmp__", True)
|
||||
checkSameDec("__eq__", True)
|
||||
checkSameDec("__ne__", True)
|
||||
checkSameDec("__le__", True)
|
||||
checkSameDec("__lt__", True)
|
||||
checkSameDec("__ge__", True)
|
||||
checkSameDec("__gt__", True)
|
||||
checkSameDec("__float__")
|
||||
checkSameDec("__floordiv__", True)
|
||||
checkSameDec("__hash__")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue