cs-031 — Black Box vs White Box
| Field | Value |
|---|---|
| id | cs-031 |
| difficulty | Intermediate |
| topics | testing, coverage |
| lecture | lecture-08 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | loops, lists, and tracing from lectures 1-6 |
| objective | choose the technique, trace it faithfully, and defend the boundary behaviour |
| solution | held by the instructor; discussed after the attempt |
Problem
Given a small function with tricky internal branches, compare the tests a black-box tester writes with the tests the code's structure demands. Which defect escapes which suite?
Your deliverable is the complete test table with expected outputs, the boundary rationale, and the automated run result. If the problem is ambiguous anywhere, state the assumption you are making and carry on — a stated assumption is part of a good answer.
Examples
- Input: def fee(x): if x < 3: return 0; elif x <= 5: return 2; else: return 5
- Output: black-box misses x=3 exactly (0 vs 2 boundary) and negative x; white-box adds both; the escaped defect is 'x < 3' vs 'x <= 3'
Solve for the worked instance first. Then ask what would change if one number, name, or condition were replaced by something stranger.
What to notice
- Enumerate branch outcomes first, then ask which inputs force each branch.
- A test case is a falsifiable claim about the requirement.
- Boundaries are where specifications and implementations disagree.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "What would a 'suite' that can never fail tell you about its tests?"
Constraints and assumptions
- Difficulty: Intermediate (loops and lists assumed).
- Topics: testing, coverage.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for the plan and trace; finishing the details is a bonus, defending the method is the target.
- Optional stretch (not required): describe an alternative approach and say when it beats the obvious one.
Hints and extension
- First nudge: identify the pattern the worked instance uses before computing anything.
- If stuck after three minutes, write the input/output line you expect and trace the smallest example by hand.
- After the reveal, attempt the extension below before the next lecture.
- Extension challenge: Add two boundary rows to your test table and justify each.