]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-136599: Add tests for long_hash (GH-138335) (#138391)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 2 Sep 2025 17:04:13 +0000 (19:04 +0200)
committerGitHub <noreply@github.com>
Tue, 2 Sep 2025 17:04:13 +0000 (17:04 +0000)
gh-136599: Add tests for long_hash (GH-138335)
(cherry picked from commit 2d3711dc06657e072a83b580636cbb0009658636)

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Lib/test/test_long.py

index 41b973da2c7df09c728a3f5c8d6abd3536d2b04b..b247f3322c2b08c8fc0aa4bc6e6b8cdb13ae9a37 100644 (file)
@@ -1642,5 +1642,21 @@ class LongTest(unittest.TestCase):
         # GH-117195 -- This shouldn't crash
         object.__sizeof__(1)
 
+    def test_hash(self):
+        # gh-136599
+        self.assertEqual(hash(-1), -2)
+        self.assertEqual(hash(0), 0)
+        self.assertEqual(hash(10), 10)
+
+        self.assertEqual(hash(sys.hash_info.modulus - 2), sys.hash_info.modulus - 2)
+        self.assertEqual(hash(sys.hash_info.modulus - 1), sys.hash_info.modulus - 1)
+        self.assertEqual(hash(sys.hash_info.modulus), 0)
+        self.assertEqual(hash(sys.hash_info.modulus + 1), 1)
+
+        self.assertEqual(hash(-sys.hash_info.modulus - 2), -2)
+        self.assertEqual(hash(-sys.hash_info.modulus - 1), -2)
+        self.assertEqual(hash(-sys.hash_info.modulus), 0)
+        self.assertEqual(hash(-sys.hash_info.modulus + 1), -sys.hash_info.modulus + 1)
+
 if __name__ == "__main__":
     unittest.main()