def test_map_keys_uq_fail(self): u = DictionaryCollection(None, { 19: "Alice", 20: "Bob", 21: "Eve" }).map_values(lambda x: [x]) with self.assertRaises(ValueError): u.map_keys_uq(lambda x: (x % 2))
def test_map_keys(self): u = DictionaryCollection(None, {19: "Alice", 20: "Bob", 21: "Eve"}) \ .map_values(lambda x : [x]) \ .map_keys(lambda x : (x%2), lambda y,z: (y+z)) self.assertEqual(u.all(), {1: ["Alice", "Eve"], 0: ["Bob"]})
def test_map_keys_uq(self): u = DictionaryCollection(None, { 19: "Alice", 20: "Bob" }).map_keys_uq(lambda x: 3 * x) self.assertEqual(u.all(), {57: "Alice", 60: "Bob"})
def test_map_values(self): u = DictionaryCollection(None, { 19: "Alice", 20: "Bob" }).map_values(lambda x: (len(x), x)) self.assertEqual(u.all(), {19: (5, "Alice"), 20: (3, "Bob")})
def test_getitem(self): u = DictionaryCollection(None, {5: "Ala", 7: "Ela"}) self.assertEqual(u[5], "Ala") self.assertEqual(u[7], "Ela")
def test_double(self): u = DictionaryCollection(None, {5: "Ala", 7: "Ela"}) self.assertEqual(u.all(), {5: "Ala", 7: "Ela"})
def test_singleton(self): u = DictionaryCollection(None, {"A": 5}) self.assertEqual(u.all(), {"A": 5})
def test_empty(self): u = DictionaryCollection(None, {}) self.assertEqual(u.all(), {})