diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-06-12 12:15:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-12 12:15:17 (GMT) |
commit | 9f1c5f6e8af6ba3f659b2aea1e221ac9695828ba (patch) | |
tree | 178272613398d4b75696f439134094b135a08f2a /Lib/test/test_float.py | |
parent | 4a42cebf6dd769e2fa4e234a9e91093b3ad1cb63 (diff) | |
download | cpython-9f1c5f6e8af6ba3f659b2aea1e221ac9695828ba.zip cpython-9f1c5f6e8af6ba3f659b2aea1e221ac9695828ba.tar.gz cpython-9f1c5f6e8af6ba3f659b2aea1e221ac9695828ba.tar.bz2 |
bpo-43475: Fix the Python implementation of hash of Decimal NaN (GH-26679)
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r-- | Lib/test/test_float.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py index ff4f387..f0ed40f 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -564,6 +564,25 @@ class GeneralFloatCases(unittest.TestCase): #self.assertTrue(0.0 < pow_op(2.0, -1047) < 1e-315) #self.assertTrue(0.0 > pow_op(-2.0, -1047) > -1e-315) + def test_hash(self): + for x in range(-30, 30): + self.assertEqual(hash(float(x)), hash(x)) + self.assertEqual(hash(float(sys.float_info.max)), + hash(int(sys.float_info.max))) + self.assertEqual(hash(float('inf')), sys.hash_info.inf) + self.assertEqual(hash(float('-inf')), -sys.hash_info.inf) + + def test_hash_nan(self): + value = float('nan') + self.assertEqual(hash(value), object.__hash__(value)) + class H: + def __hash__(self): + return 42 + class F(float, H): + pass + value = F('nan') + self.assertEqual(hash(value), object.__hash__(value)) + @requires_setformat class FormatFunctionsTestCase(unittest.TestCase): |