Study guide: Build Evidence for Small Functions
Test a function’s contract, boundaries and list structure, then retain regression cases.
Ideas to explain in your own words
- Use ordinary and boundary inputs to check a small function.
- Turn a function contract into representative tests and boundary tests.
- Expose a skipped last element with empty, one-item and ordinary lists.
- Verify a correction against ordinary, boundary and previously failing cases.
Watch your reasoning
- Only the boundary input 12 has a different result under those two comparisons. Both rules classify the other supplied ages the same way.
- 8 is the included highest allowed integer, so it is valid and large. 9 is above the contract, and fractional/text values are rejected.
- One item is enough when it is nonzero. The faulty loop visits no positions and returns 0, while the expected sum is 5. Empty and single-zero lists pass accidentally.
- The original error was including 7 in mid. Keeping 7 → high detects that same error if it reappears.
A worked review example
Choose tests that catch a rule error: Correct rule: 11 → child, 12 → standard, 13 → standard. The mistaken ≤ rule labels 12 as child, so the test 12 → standard exposes the boundary error. Test Valid and Invalid Inputs Separately: −1 → invalid; 0 → small; 3 → small; 4 → large; 8 → large; 9 → invalid; 2.5 → invalid; text "4" → invalid; Boolean true → invalid. Validity and classification are tested separately. Use a Small Test to Find a Loop Error: Faulty results: [] → 0; [5] → 0 because no positions are visited; [2,4,1] visits positions 0,1 and returns 6 instead of 7. Repaired endpoint n returns 0, 5 and 7 respectively. Repair a Function and Keep Its Test: Faulty outputs for 2,3,6,7,8: low, mid, mid, mid, high. Only 7 fails its expected high label. Repaired outputs: low, mid, mid, high, high; all five supplied tests pass.
Make a practice plan
- Try the supplied lesson problems without looking at the answers.
- Compare your method with the worked examples and explain any correction.
- Use the new review cases, then complete the transfer task on paper or in your own document.