示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 def test_shallow_list(self):
     self.assertEqual([2, 4, 6], nested.map(lambda x: 2 * x, [1, 2, 3]))
示例#4
0
 def test_empty(self):
     self.assertEqual({}, nested.map(lambda x: x, {}))
示例#5
0
 def test_scalar(self):
     self.assertEqual(42, nested.map(lambda x: x, 42))
示例#6
0
 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)
示例#7
0
 def test_mixed_types(self):
     self.assertEqual([14, 'foofoo'], nested.map(lambda x: x * 2,
                                                 [7, 'foo']))
示例#8
0
 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)
示例#9
0
 def test_shallow_dict(self):
     data = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
     self.assertEqual(data, nested.map(lambda x: x, data))
示例#10
0
 def test_shallow_list(self):
   self.assertEqual([2, 4, 6], nested.map(lambda x: 2 * x, [1, 2, 3]))
示例#11
0
 def test_empty(self):
   self.assertEqual({}, nested.map(lambda x: x, {}))
示例#12
0
 def test_scalar(self):
   self.assertEqual(42, nested.map(lambda x: x, 42))
示例#13
0
 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)
示例#14
0
 def test_mixed_types(self):
   self.assertEqual([14, 'foofoo'], nested.map(lambda x: x * 2, [7, 'foo']))
示例#15
0
 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)
示例#16
0
 def test_shallow_dict(self):
   data = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
   self.assertEqual(data, nested.map(lambda x: x, data))