Skip to content

Commit 048ec3e

Browse files
author
j30ng
committed
Add Testcases
1 parent 301e5a9 commit 048ec3e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/snippets/stdlib_itertools.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,34 @@ def assert_matches_seq(it, seq):
243243
assert list(itertools.compress("ABCDEF", [1,0,1])) == list("AC")
244244
assert list(itertools.compress("ABC", [0,1,1,1,1,1])) == list("BC")
245245
assert list(itertools.compress("ABCDEF", [True,False,"t","",1,9])) == list("ACEF")
246+
247+
248+
# itertools.tee
249+
t = itertools.tee([])
250+
assert len(t) == 2
251+
assert t[0] is not t[1]
252+
assert list(t[0]) == list(t[1]) == []
253+
254+
with assert_raises(TypeError):
255+
itertools.tee()
256+
257+
t = itertools.tee(range(1000))
258+
assert list(t[0]) == list(t[1]) == list(range(1000))
259+
260+
t = itertools.tee([1,22,333], 3)
261+
assert len(t) == 3
262+
assert 1 == next(t[0])
263+
assert 1 == next(t[1])
264+
assert 22 == next(t[0])
265+
assert 333 == next(t[0])
266+
assert 1 == next(t[2])
267+
assert 22 == next(t[1])
268+
assert 333 == next(t[1])
269+
assert 22 == next(t[2])
270+
with assert_raises(StopIteration):
271+
next(t[0])
272+
assert 333 == next(t[2])
273+
with assert_raises(StopIteration):
274+
next(t[2])
275+
with assert_raises(StopIteration):
276+
next(t[1])

0 commit comments

Comments
 (0)