summaryrefslogtreecommitdiff
path: root/Lib/test/test_decimal.py
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2007-09-19 17:53:25 +0000
committerFacundo Batista <facundobatista@gmail.com>2007-09-19 17:53:25 +0000
commit640b70d1b68c5519eef0516757506969468212f8 (patch)
treed2d4fecbf76ccaf79334bc956b9eca49df323ed4 /Lib/test/test_decimal.py
parent7b3e61708c44fc2045a671d90af25f67c5c9adce (diff)
downloadcpython-640b70d1b68c5519eef0516757506969468212f8.tar.gz
Issue #1772851. Optimization of __hash__ to behave better for big big
numbers.
Diffstat (limited to 'Lib/test/test_decimal.py')
-rw-r--r--Lib/test/test_decimal.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 9281abc1d6..1647212fa9 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -910,6 +910,38 @@ class DecimalUsabilityTest(unittest.TestCase):
def test_hash_method(self):
#just that it's hashable
hash(Decimal(23))
+
+ test_values = [Decimal(sign*(2**m + n))
+ for m in [0, 14, 15, 16, 17, 30, 31,
+ 32, 33, 62, 63, 64, 65, 66]
+ for n in range(-10, 10)
+ for sign in [-1, 1]]
+ test_values.extend([
+ Decimal("-0"), # zeros
+ Decimal("0.00"),
+ Decimal("-0.000"),
+ Decimal("0E10"),
+ Decimal("-0E12"),
+ Decimal("10.0"), # negative exponent
+ Decimal("-23.00000"),
+ Decimal("1230E100"), # positive exponent
+ Decimal("-4.5678E50"),
+ # a value for which hash(n) != hash(n % (2**64-1))
+ # in Python pre-2.6
+ Decimal(2**64 + 2**32 - 1),
+ # selection of values which fail with the old (before
+ # version 2.6) long.__hash__
+ Decimal("1.634E100"),
+ Decimal("90.697E100"),
+ Decimal("188.83E100"),
+ Decimal("1652.9E100"),
+ Decimal("56531E100"),
+ ])
+
+ # check that hash(d) == hash(int(d)) for integral values
+ for value in test_values:
+ self.assertEqual(hash(value), hash(int(value)))
+
#the same hash that to an int
self.assertEqual(hash(Decimal(23)), hash(23))
self.assertRaises(TypeError, hash, Decimal('NaN'))