Case-based lecture: you attempt, we discuss, then we reveal.
cs-029, cs-030, cs-031, cs-032Classify triangles: scalene, isosceles, equilateral, impossible (degenerate), invalid. Design the test table before the classifier.
Expected: six verdict lines matching the reference
Cost: O(1) per input; the intellectual work is the table, not the branches.
fee(x): 0 below 3, 2 up to 5, 5 above. A buggy version charges 0 at exactly x = 3. Which suite finds it - black box or white box?
def classify(a, b, c):
sides = sorted([a, b, c])
if sides[0] + sides[1] <= sides[2]:
return "invalid"
if a == b == c:
return "equilateral"
if a == b or b == c or a == c:
return "isosceles"
return "scalene"
print(classify(3, 4, 5), classify(5, 5, 5), classify(4, 4, 7), classify(1, 2, 8))Expected: rows ending with a disagreement exactly at x = 3
Cost: Suite size stays small (4-8 rows) because white-box targeting hits the seams instead of sampling blindly.
Classify a triangle from three sides. Design the full test set: equilateral, isosceles, scalene, degenerate, impossible — before looking at any implementation.
**Input:** sides (3,4,5), (5,5,5), (2,2,3), (1,2,3), (1,1,10), (0,4,4)**Output:** scalene; equilateral; isosceles; degenerate (1+2=3); impossible; invalid (zero side)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-029 — not embedded in this deck.
A system admits visitors 12 and older on weekends, 16 and older on weekdays. Derive test cases from the requirement, including the boundary birthdays.
**Input:** ages 11, 12 (Sat), 12 (Mon), 15 (Mon), 16 (Mon)**Output:** refused; admitted; refused; admitted; admitted (weekday boundary is 16)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-030 — not embedded in this deck.
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?
**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 onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-031 — not embedded in this deck.
A function uses randomness; tests pass sometimes. Discuss asserting distributions instead of exact values, seeding, and statistical tests for randomized code.
**Input:** randint-based roller; assert exact output fails intermittently**Output:** seed for tests; assert invariants (range, distribution over 10k trials)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-032 — not embedded in this deck.