From 309f2991557673c67c3d8fae995c8b23cc0d4d7c Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 19 Nov 2018 12:35:02 -0500 Subject: Implement Map.mutate() method --- tests/test_map.py | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) (limited to 'tests/test_map.py') diff --git a/tests/test_map.py b/tests/test_map.py index fe2a131..e2ba2b4 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -906,6 +906,133 @@ class BaseMapTest: def test_abc_1(self): self.assertTrue(issubclass(self.Map, collections.abc.Mapping)) + def test_map_mut_1(self): + h = self.Map() + h = h.set('a', 1) + + hm1 = h.mutate() + hm2 = h.mutate() + + self.assertFalse(isinstance(hm1, self.Map)) + + self.assertIsNot(hm1, hm2) + self.assertEqual(hm1['a'], 1) + self.assertEqual(hm2['a'], 1) + + hm1.set('b', 2) + hm1.set('c', 3) + + hm2.set('x', 100) + hm2.set('a', 1000) + + self.assertEqual(hm1['a'], 1) + self.assertEqual(hm1.get('x', -1), -1) + + self.assertEqual(hm2['a'], 1000) + self.assertTrue('x' in hm2) + + h1 = hm1.finalize() + h2 = hm2.finalize() + + self.assertTrue(isinstance(h1, self.Map)) + + self.assertEqual(dict(h.items()), {'a': 1}) + self.assertEqual(dict(h1.items()), {'a': 1, 'b': 2, 'c': 3}) + self.assertEqual(dict(h2.items()), {'a': 1000, 'x': 100}) + + def test_map_mut_2(self): + h = self.Map() + h = h.set('a', 1) + + hm1 = h.mutate() + hm1.set('a', 2) + hm1.set('a', 3) + hm1.set('a', 4) + h2 = hm1.finalize() + + self.assertEqual(dict(h.items()), {'a': 1}) + self.assertEqual(dict(h2.items()), {'a': 4}) + + def test_map_mut_3(self): + h = self.Map() + h = h.set('a', 1) + hm1 = h.mutate() + + self.assertTrue(repr(hm1).startswith( + "