mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
Issue #8188: Introduce a new scheme for computing hashes of numbers
(instances of int, float, complex, decimal.Decimal and fractions.Fraction) that makes it easy to maintain the invariant that hash(x) == hash(y) whenever x and y have equal value.
This commit is contained in:
parent
03721133a6
commit
dc787d2055
14 changed files with 566 additions and 137 deletions
|
@ -426,6 +426,23 @@ class SysModuleTest(unittest.TestCase):
|
|||
self.assertEqual(type(sys.int_info.bits_per_digit), int)
|
||||
self.assertEqual(type(sys.int_info.sizeof_digit), int)
|
||||
self.assertIsInstance(sys.hexversion, int)
|
||||
|
||||
self.assertEqual(len(sys.hash_info), 5)
|
||||
self.assertLess(sys.hash_info.modulus, 2**sys.hash_info.width)
|
||||
# sys.hash_info.modulus should be a prime; we do a quick
|
||||
# probable primality test (doesn't exclude the possibility of
|
||||
# a Carmichael number)
|
||||
for x in range(1, 100):
|
||||
self.assertEqual(
|
||||
pow(x, sys.hash_info.modulus-1, sys.hash_info.modulus),
|
||||
1,
|
||||
"sys.hash_info.modulus {} is a non-prime".format(
|
||||
sys.hash_info.modulus)
|
||||
)
|
||||
self.assertIsInstance(sys.hash_info.inf, int)
|
||||
self.assertIsInstance(sys.hash_info.nan, int)
|
||||
self.assertIsInstance(sys.hash_info.imag, int)
|
||||
|
||||
self.assertIsInstance(sys.maxsize, int)
|
||||
self.assertIsInstance(sys.maxunicode, int)
|
||||
self.assertIsInstance(sys.platform, str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue