From: Pieter Eendebak Date: Tue, 2 Sep 2025 16:42:12 +0000 (+0200) Subject: gh-136599: Add tests for long_hash (#138335) X-Git-Tag: v3.15.0a1~533 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2d3711dc06657e072a83b580636cbb0009658636;p=thirdparty%2FPython%2Fcpython.git gh-136599: Add tests for long_hash (#138335) Co-authored-by: Sergey B Kirpichev --- diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index f336d49fa4f0..d63bc19ed9c9 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -1693,5 +1693,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()