def test_namedtuple(self): Foo = collections.namedtuple('Foo', 'value') foo, bar = [Foo(42)], [Foo(13)] function = nested.map(lambda x, y: (y, x), foo, bar) self.assertEqual([Foo((13, 42))], function) function = nested.map(lambda x, y: x + y, foo, bar) self.assertEqual([Foo(55)], function)
def test_shallow_list(self): self.assertEqual([2, 4, 6], nested.map(lambda x: 2 * x, [1, 2, 3]))
def test_empty(self): self.assertEqual({}, nested.map(lambda x: x, {}))
def test_scalar(self): self.assertEqual(42, nested.map(lambda x: x, 42))
def test_multiple_lists(self): a = [1, 2, 3] b = [4, 5, 6] c = [7, 8, 9] result = nested.map(lambda x, y, z: x + y + z, a, b, c) self.assertEqual([12, 15, 18], result)
def test_mixed_types(self): self.assertEqual([14, 'foofoo'], nested.map(lambda x: x * 2, [7, 'foo']))
def test_mixed_structure(self): structure = [(1, 2), 3, {'foo': [4]}] result = nested.map(lambda x: 2 * x, structure) self.assertEqual([(2, 4), 6, {'foo': [8]}], result)
def test_shallow_dict(self): data = {'a': 1, 'b': 2, 'c': 3, 'd': 4} self.assertEqual(data, nested.map(lambda x: x, data))