def test_atomic(self): s = {'a': [1, 2, 3], 'b': [4, 5, 6], 'c': ([7, 8, 9], [10, 11, 12])} m = {'a': 1, 'b': 4, 'c': (7, 10)} mapped = nest.map(lambda x: x[0], s, is_atomic=lambda x: isinstance(x, list))
def test_nested(self): s = {'a': 1, 'b': 2, 'c': [3, 4, {5, 6}], 'd': Point(7, 8), 'e': Coordinates(9, 10)} m = {'a': 2, 'b': 4, 'c': [6, 8, {10, 12}], 'd': Point(14, 16), 'e': Coordinates(18, 20)} mapped = nest.map(lambda x: 2*x, s) self.assertEqual(mapped, m)
def test_none(self): s = None m = nest.map(lambda x: 2*x, s) self.assertEqual(m, None)
def test_single_element(self): s = 4 m = nest.map(lambda x: 2*x, s) self.assertEqual(m, 8)
def test_has_max_depth_with_lists(self): l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] f = nest.map(lambda x: max(x), l, is_atomic=nest.has_max_depth(1)) self.assertEqual(f, [3, 6, 9])