Search RU
Tasks / pytest / Parametrized tests for chunking
Statement medium

Parametrized tests for chunking

`chunked(items, size)` splits a list into chunks of `size` elements.

```
chunked([1, 2, 3, 4, 5], 2)
→ [[1, 2], [3, 4], [5]]
```

Rules:

- `size` is an integer greater than zero, otherwise `ValueError`;
- the order of elements is preserved;
- every chunk except the last one holds exactly `size` elements;
- the last chunk may be shorter, but there are no empty chunks;
- an empty list gives `[]`;
- if `size` is larger than the list, one chunk with all elements is returned.

Write the tests with `@pytest.mark.parametrize`. Cover at least: empty input,
`size` larger than the list, a list that is an exact multiple of `size`, and a
list with a remainder. Check an invalid `size` separately.

pytestparametrizeboundaryedge cases
test_solution.py Python 3.14
AI mentor

The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.

Log in and ask
Hints 1 of 3 unlocked · attempts: 0
Hint 1

What do lists of length 0, exactly `size`, and `size + 1` have in common? Which
of them break a naive implementation?

Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts