def test_shallow_dict(self): a = {'a': 1, 'b': 2, 'c': 3} b = {'a': 4, 'b': 5, 'c': 6} c = {'a': 7, 'b': 8, 'c': 9} result = nested.zip(a, b, c) self.assertEqual({ 'a': (1, 4, 7), 'b': (2, 5, 8), 'c': (3, 6, 9) }, result)
def test_namedtuple(self): Foo = collections.namedtuple('Foo', 'value') foo, bar = Foo(42), Foo(13) self.assertEqual(Foo((42, 13)), nested.zip(foo, bar))
def test_use_type_of_first(self): a = (1, 2, 3) b = [4, 5, 6] c = [7, 8, 9] result = nested.zip(a, b, c) self.assertEqual(((1, 4, 7), (2, 5, 8), (3, 6, 9)), result)
def test_different_types(self): a = [1, 2, 3] b = 'a b c'.split() result = nested.zip(a, b) self.assertEqual([(1, 'a'), (2, 'b'), (3, 'c')], result)
def test_mixed_structures(self): a = [(1, 2), 3, {'foo': [4]}] b = [(5, 6), 7, {'foo': [8]}] result = nested.zip(a, b) self.assertEqual([((1, 5), (2, 6)), (3, 7), {'foo': [(4, 8)]}], result)
def test_single(self): a = [[1, 2], 3] result = nested.zip(a) self.assertEqual(a, result)
def test_shallow_tuple(self): a = (1, 2, 3) b = (4, 5, 6) c = (7, 8, 9) result = nested.zip(a, b, c) self.assertEqual(((1, 4, 7), (2, 5, 8), (3, 6, 9)), result)
def test_shallow_list(self): a = [1, 2, 3] b = [4, 5, 6] c = [7, 8, 9] result = nested.zip(a, b, c) self.assertEqual([(1, 4, 7), (2, 5, 8), (3, 6, 9)], result)
def test_base_case(self): self.assertEqual((1, 2, 3), nested.zip(1, 2, 3))
def test_empty(self): self.assertEqual({}, nested.zip({}, {}))
def test_scalar(self): self.assertEqual(42, nested.zip(42)) self.assertEqual((13, 42), nested.zip(13, 42))