Case-based lecture: you attempt, we discuss, then we reveal.
cs-025, cs-026, cs-027, cs-028Items [2.00, 3.50, 1.25] print a receipt of 4.75 instead of 6.75. Debug it by the method: reproduce, hypothesise, isolate, fix, verify.
Expected: 4.75 6.75
Cost: Debugging cost, not runtime: one repro, one minimal input, one rerun. The method's value is that it terminates.
A task board shows one task list twice after a second edit. Prove the cause and fix it.
lines = ["a", "b"]
echoed = []
for i in range(len(lines)):
echoed.append(lines[i])
print(len(echoed), echoed[0])Expected: duplicated rows with identity True; after the fix the rows differ and the check is False
Cost: O(k) extra per call for the copy - correctness buys the copying cost.
A receipt program prints a total that is too low by exactly one item's price. Form hypotheses, design the minimal reproducing input, and localise the fault.
**Input:** items [2.00, 3.50, 1.25]; receipt printed 5.50**Output:** one item skipped (1.25 missing); repro input: 3 items, expected 6.75Solve 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-025 — not embedded in this deck.
An invoice tool includes one extra row under specific conditions. Use bisection over input shapes to find the boundary condition that triggers the defect.
**Input:** invoice rows; extra row appears only when qty is exactly 10**Output:** boundary bug: condition qty >= 10 should be qty > 10; minimal repro: one row qty=10Solve 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-026 — not embedded in this deck.
A task list occasionally shows one task twice after edits. Reason about shared references / aliasing as the cause and design the experiment that proves it.
**Input:** tasks edited twice; list shows one task twice after edit 2**Output:** aliasing: the same list object referenced twice; is-check (a is b) proves itSolve 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-027 — not embedded in this deck.
A defect that disappears when a debug print is added. Discuss causes (ordering, mutation during iteration, hidden dependency) and design a strategy to catch it.
**Input:** defect vanishes when print(i) is added to the loop**Output:** candidates: loop mutates the list it iterates; set iteration order; time-dependent stateSolve 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-028 — not embedded in this deck.