Write tests for this function
Table-driven tests covering the boundaries, not just the happy path.
Write tests for the function below using [TEST FRAMEWORK]. Cover: - The ordinary case. - Every boundary in the input domain (empty, one, many, maximum). - Each error path, asserting the error, not just that it threw. Prefer one table-driven test over many near-identical ones. Do not test the language. ``` [PASTE FUNCTION HERE] ```
Highlighted parts are placeholders. Replace them before you send.
Worked example
The input is invented for this page. The output shows what the prompt asks for with that input.
Example input (invented)
Test framework: pytest
Function
def chunk(items, size):
"""Split a list into consecutive lists of at most `size` items."""
if size < 1:
raise ValueError("size must be at least 1")
return [items[i:i + size] for i in range(0, len(items), size)]
Example output
import pytest
from chunking import chunk
@pytest.mark.parametrize(
"items, size, expected",
[
pytest.param([1, 2, 3, 4, 5], 2, [[1, 2], [3, 4], [5]], id="uneven tail"),
pytest.param([1, 2, 3, 4], 2, [[1, 2], [3, 4]], id="exact multiple"),
pytest.param([], 3, [], id="empty list"),
pytest.param([1], 3, [[1]], id="one item"),
pytest.param([1, 2, 3], 1, [[1], [2], [3]], id="smallest size"),
pytest.param([1, 2, 3], 3, [[1, 2, 3]], id="size equals length"),
pytest.param([1, 2, 3], 10, [[1, 2, 3]], id="size above length"),
],
)
def test_chunk_splits_in_order(items, size, expected):
assert chunk(items, size) == expected
@pytest.mark.parametrize("size", [0, -1])
def test_chunk_rejects_size_below_one(size):
with pytest.raises(ValueError, match="size must be at least 1"):
chunk([1, 2, 3], size)
def test_chunk_leaves_the_input_unchanged():
items = [1, 2, 3]
chunk(items, 2)
assert items == [1, 2, 3]
The import assumes the function lives in chunking.py. The table covers the ordinary case and the boundaries: an empty list, one item, the smallest size, and a size equal to and above the length. The error test asserts the message, so a different ValueError would not pass it. There is no test for a size that is not a whole number, because the function does not say what should happen then.
More Coding prompts
3 of the 7 other prompts filed under Coding.
Write the tests that would have caught this
Turns a bug you just fixed into the regression test you should have had.
Explain this code to me at the depth I ask for
Paste the code and pick one paragraph or a full walkthrough. You get what it does, why it might be written that way and what to watch for.
Find the bug from a stack trace
Works backwards from an error to a specific line and a specific cause.
Coding tools and skills
3 of the 9 tools and 3 of the 7 skills filed under Coding, the same category as this prompt.
Aider
Pair programming with an LLM in the terminal, wired directly to git.
Claude Code
Anthropic's agentic coding tool for the terminal and IDE.
Cline
An open-source coding agent that runs inside VS Code with your own API key.
Pull request description writer
Writes the PR description from the branch diff, aimed at the reviewer.
Release notes writer
Writes release notes and a changelog from a commit range, leaving out the commits users never notice.
Test writer
Writes tests that fail for the right reason and refuse to test the framework.
Guides that use this prompt
2 guides list this prompt under "Used in this tutorial".
Reviewing code an AI wrote
It compiles, the tests pass, and it reads well. That combination is exactly why it needs a different kind of review.
Claude Code guide: setup, CLAUDE.md, permissions and skills
Install Claude Code, write a short CLAUDE.md, choose a permission mode, then add hooks, skills and MCP servers. Each step comes from Anthropic's docs and links to the page.
Coding guides
1 of the 6 guides filed under Coding, the same category as this prompt.
Claude Code alternatives: agentic coding tools compared
What Claude Code needs from you today, which agents replace it in the terminal, in an editor, on your own models or in the cloud, and which of them read your SKILL.md files.