Lecture 08 — Testing Before Trusting

Position in the course

This is lecture 8 of 32. It belongs to the course arc described in the course outline and uses the standard interactive case method: display, attempt (5 minutes), discuss, reveal, name the technique.

Learning objectives

By the end of this lecture students can do all three under time pressure, which is what the four cases exercise.

Prerequisite knowledge

Before this lecture: Lectures 06–07 — Tracing and debugging method

Assumed fluencies:

Preparation task: Bring one bug you met this week (any course, any language).

Detailed topic outline

Core (mandatory):

  1. test cases as specifications
  2. normal / boundary / adversarial classes
  3. black-box versus white-box design
  4. coverage without obsession

Extension (optional enrichment):

  1. testing randomness honestly
  2. the flaky test problem

Case sequence

CaseTitleDifficulty
cs-029Triangle ClassifierBeginner
cs-030The Age GateFoundational
cs-031Black Box vs White BoxIntermediate
cs-032The Flaky FunctionAdvanced

Display each case full-screen from the student page (cases cs-029–cs-032); instructor pages cs-029–cs-032 under case-studies/instructor/ hold the full solutions, reveal guides, and discussion prompts.

Timing plan (120 minutes)

MinutesSegment
0–10Framing: where this fits; recall of the previous lecture
10–30Case 1 (cs-029): 5-minute attempt, then discussion and reveal
30–50Case 2 (cs-030): same rhythm
50–70Case 3 (cs-031): same rhythm, harder case
70–75Break
75–100Case 4 (cs-032): same rhythm, hardest case
100–115Synthesis: name the techniques; misconceptions check
115–120Exit questions, homework, next-lecture preview

Timing flexes with the room: if a case ignites the class, let the discussion run and compress the synthesis; if the attempts stall, harvest partial attempts rather than extending the clock.

Worked examples

Instructor demonstration to open the lecture: Build the triangle classifier test table (cs-029) with the class: normal rows first, then boundaries, then the adversarial row that kills naive code.

Classroom activities

#ActivityMinutesFormat and prompt
1Test-table duel8Two teams design test tables for cs-030 age gate; the table that finds a planted bug wins.
2Boundary sprint590 seconds: list every boundary of 'valid age is 0–120 inclusive'; then count them together.
3Coverage map discussion6A small function and its branches are mapped; the class marks which tests actually reach each branch.

Board plan

Instructor explanation notes

Reading the room. Testing is reframed from chore to specification: the test table is the requirement, written executable. The flaky-function case (cs-032) ends the lecture on honesty about randomness.

Running the reveal. Keep coverage light: branches reached, not percentages. The goal is a habit, not a metric.

Lecture focus. One sentence to repeat verbatim: The test table is the specification, executable.

Common misconceptions

Each case's instructor page lists the specific wrong turn to expect; the reveal should address it by name.

Student practice exercises

Core:

  1. Build a complete test table for the age gate (cs-030): normal, boundary, adversarial.
  2. Convert your cs-029 table into executable asserts.
  3. Design a fair test for a function that behaves differently on different runs (cs-032 family).

Enrichment (optional):

Formative assessment

Exit questions (choose one; answer on a card in 60 seconds):

  1. Name the three test-case classes and one example of each. Expected: normal (typical use), boundary (edges: 0, 120), adversarial (empty, negatives, junk)
  1. Black-box vs white-box in one sentence each. Expected: black-box: from the spec only; white-box: from the code's known branches
  1. What makes a randomness test fair? Expected: control the seed or test the distribution over many runs, never a single outcome

Cards are skimmed before the next lecture; three answers become the framing. Persistent wrong answers route students to the review stations of lecture 16 or to office hours.

Homework and preparation

Learning-outcome mapping

Differentiation