aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-04-01 18:01:18 -0400
committerYury Selivanov <yury@magic.io>2018-04-01 18:02:48 -0400
commitfea3466093936116d57606b0e5083f5d1121f146 (patch)
treed141afaf58f296adfb175af11dce96c827326f87 /tests
parent4e8a40d0635dc8e9a8d89af2651f892cdf3d5aa3 (diff)
downloadimmutables-fea3466093936116d57606b0e5083f5d1121f146.tar.gz
immutables-fea3466093936116d57606b0e5083f5d1121f146.zip
Implement Map.__hash__
Diffstat (limited to 'tests')
-rw-r--r--tests/test_map.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_map.py b/tests/test_map.py
index 06c82b9..91050a2 100644
--- a/tests/test_map.py
+++ b/tests/test_map.py
@@ -757,6 +757,33 @@ class MapTest(unittest.TestCase):
self.assertTrue(repr(h).startswith(
'<immutables.Map({{...}: 1}) at 0x'))
+ def test_hash_1(self):
+ h = Map()
+ self.assertNotEqual(hash(h), -1)
+ self.assertEqual(hash(h), hash(h))
+
+ h = h.set(1, 2).set('a', 'b')
+ self.assertNotEqual(hash(h), -1)
+ self.assertEqual(hash(h), hash(h))
+
+ self.assertEqual(
+ hash(h.set(1, 2).set('a', 'b')),
+ hash(h.set('a', 'b').set(1, 2)))
+
+ def test_hash_2(self):
+ h = Map()
+ A = HashKey(100, 'A')
+
+ m = h.set(1, 2).set(A, 3).set(3, 4)
+ with self.assertRaises(HashingError):
+ with HaskKeyCrasher(error_on_hash=True):
+ hash(m)
+
+ m = h.set(1, 2).set(2, A).set(3, 4)
+ with self.assertRaises(HashingError):
+ with HaskKeyCrasher(error_on_hash=True):
+ hash(m)
+
if __name__ == "__main__":
unittest.main()