from main import take
def test_first_two():
"""take(['a', 'b', 'c'], 2) is ['a', 'b']"""
got = take(["a", "b", "c"], 2)
assert got == ["a", "b"], f"take(['a', 'b', 'c'], 2) returned {got!r}"
def test_runs_out():
"""Asking for more items than there are gives them all"""
got = take("xyz", 5)
assert got == ["x", "y", "z"], f"take('xyz', 5) returned {got!r}, expected ['x', 'y', 'z']"
def test_leaves_the_rest():
"""take(it, 2) leaves the third item in the iterator"""
it = iter(["a", "b", "c", "d"])
take(it, 2)
got = next(it, None)
assert got == "c", f"after take(it, 2), next(it) gave {got!r}, expected 'c': take used up too many items"
def test_zero():
"""take(..., 0) is an empty list"""
got = take(["a"], 0)
assert got == [], f"take(['a'], 0) returned {got!r}, expected []"