| 1 |
class AppTestZip: |
| 2 |
|
| 3 |
def test_zip_no_arguments(self): |
| 4 |
import sys |
| 5 |
if sys.version_info < (2,4): |
| 6 |
|
| 7 |
raises(TypeError, zip) |
| 8 |
else: |
| 9 |
|
| 10 |
assert list(zip()) == [] |
| 11 |
assert list(zip(*[])) == [] |
| 12 |
|
| 13 |
def test_one_list(self): |
| 14 |
assert list(zip([1, 2, 3])) == [(1,), (2,), (3,)] |
| 15 |
|
| 16 |
def test_two_lists(self): |
| 17 |
|
| 18 |
assert list(zip([1, 2, 3], [3, 4, 5])) == [(1, 3), (2, 4), (3, 5)] |
| 19 |
assert list(zip([1, 2, 3], [3, 4])) == [(1, 3), (2, 4)] |
| 20 |
assert list(zip([1, 2], [3, 4, 5])) == [(1, 3), (2, 4)] |
| 21 |
|
| 22 |
def test_three_lists_same_size(self): |
| 23 |
assert list(zip([1, 2, 3], [3, 4, 5], [6, 7, 8])) == ( |
| 24 |
[(1, 3, 6), (2, 4, 7), (3, 5, 8)]) |
| 25 |
|
| 26 |
def test_three_lists_different_sizes(self): |
| 27 |
assert list(zip([1, 2], [3, 4, 5, 6], [6, 7, 8])) == ( |
| 28 |
[(1, 3, 6), (2, 4, 7)]) |
| 29 |
|
| 30 |
def test_tuples(self): |
| 31 |
assert list(zip((1, 2, 3))) == [(1,), (2,), (3,)] |
| 32 |
|
| 33 |
def test_string(self): |
| 34 |
assert list(zip('hello')) == [('h',), ('e',), ('l',), ('l',), ('o',)] |
| 35 |
|
| 36 |
def test_strings(self): |
| 37 |
assert list(zip('hello', 'bye')) == ( |
| 38 |
[('h', 'b'), ('e', 'y'), ('l', 'e')]) |
| 39 |
|
| 40 |
def test_mixed_types(self): |
| 41 |
assert list(zip('hello', [1,2,3,4], (7,8,9,10))) == ( |
| 42 |
[('h', 1, 7), ('e', 2, 8), ('l', 3, 9), ('l', 4, 10)]) |
| 43 |
|
| 44 |
class AppTestZip2: |
| 45 |
def test_zip(self): |
| 46 |
it = zip() |
| 47 |
raises(StopIteration, next, it) |
| 48 |
|
| 49 |
obj_list = [object(), object(), object()] |
| 50 |
it = zip(obj_list) |
| 51 |
for x in obj_list: |
| 52 |
assert next(it) == (x, ) |
| 53 |
raises(StopIteration, next, it) |
| 54 |
|
| 55 |
it = zip([1, 2, 3], [4], [5, 6]) |
| 56 |
assert next(it) == (1, 4, 5) |
| 57 |
raises(StopIteration, next, it) |
| 58 |
|
| 59 |
it = zip([], [], [1], []) |
| 60 |
raises(StopIteration, next, it) |
| 61 |
|
| 62 |
|
| 63 |
it1 = iter([1, 2, 3, 4, 5, 6]) |
| 64 |
it2 = iter([5, 6]) |
| 65 |
it = zip(it1, it2) |
| 66 |
for x in [(1, 5), (2, 6)]: |
| 67 |
assert next(it) == x |
| 68 |
raises(StopIteration, next, it) |
| 69 |
assert next(it1) in [3, 4] |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
def test_zip_wrongargs(self): |
| 75 |
raises(TypeError, zip, None, 0) |