Test What It Should Do
Asking an assistant for tests is easy, and it will write them quickly. But if it looks at the code it just wrote and writes tests to match, the tests simply repeat the code's assumptions, bugs included. A test suite that agrees with a bug is worse than none, because it makes the bug look approved.
The rule
You pick the test cases from the spec; the assistant may type them.
A test is a small piece of code that runs part of your program and checks the result against what you expected. The important decision in any test is not the syntax but the case: which input, and which expected result. Those come from your spec and your understanding of the rules, not from the code under test.
Here are three tests for Kitty's split function, using pytest, a widely used Python testing library:
import pytest
from kitty.money import split_evenly
def test_even_split():
assert split_evenly(90000, ["Asha", "Ravi", "Meera"]) == {
"Asha": 30000, "Ravi": 30000, "Meera": 30000,
}
def test_leftover_paise_are_not_lost():
shares = split_evenly(100000, ["Asha", "Ravi", "Meera"])
assert sum(shares.values()) == 100000
def test_empty_flat_is_refused():
with pytest.raises(ValueError):
split_evenly(5000, [])Each one encodes a decision you made: even amounts split exactly, no paisa ever vanishes, and an empty flat is an error rather than a crash.
One more rule: watch every new test fail at least once. Break the code on purpose, or write the test before the fix, and check that it turns red. A test you have never seen fail may not be testing anything at all.
The shortcut
For each behaviour, list three cases: normal, edge, wrong. Normal is the everyday case. Edge sits on a boundary: a leftover, zero, empty, exactly at a limit. Wrong is input that must be refused. Write the expected result for each before running anything.
Normal
Ravi owes Asha 30000 paise and pays 30000. Expected: both balances become 0.
The trap is letting the assistant choose the cases and write the code. Then the only thing being tested is whether the assistant agrees with itself.
Drills
Answer fast — trust the rule.
Why should you, rather than the assistant, choose the test cases?
For split_evenly, which of these is an edge case?
What does sum(shares.values()) == 100000 protect against?
A new test passed the first time you ran it, and you have never seen it fail. What is the risk?
Remember
- Rule: you pick the test cases from the spec; the assistant may type them.
- Shortcut: normal, edge, wrong, with expected results written first.
- Trap: tests that only confirm the code agrees with itself. Watch every test fail once.
