Reduce, Repair, and Verify

Record a failure baseline, remove one unrelated part at a time while preserving the same failure, repair the boundary, and retain the original case as a regression check.

A large failing program can contain too much to inspect at once. Reduction removes details that are not needed to reproduce the failure. It is not a repair: the same failure must remain.

Record a Baseline

Begin with the input and symptom. This program stops while converting east:

This is more precise than “the parser is broken”:

EvidenceBaseline
Inputthe four records shown above
SymptomValueError
Failing expressionfloat(text)
Relevant valuetext == "not recorded"

Keep this record while reducing. A different exception, failing expression, or successful run does not preserve the baseline.

Q1. Identify complete baseline evidence

Which note gives enough evidence to compare later reductions?

Choose one

Select one choice, then check.

HintKeep comparison evidence

A useful baseline answers what input ran, what happened, where it happened, and which value reached that operation.

SolutionRecord input, symptom, location, and value

Keep the records, ValueError, the failing float(text) expression, and text == "not recorded". Together they identify what each smaller case must preserve.

Not attempted
Review

Not marked done.

Remove One Thing at a Time

Remove one record, then run the program again. If the same ValueError still comes from float(text) with the same invalid text, keep the smaller case. If the failure disappears or changes, restore what was removed.

Removing the south record keeps the failure. Removing west keeps it again. Removing north also keeps it. We reach:

This one-record input still raises the same exception at the same expression. It exposes the boundary without the valid records around it.

Now compare two tempting changes:

ChangeResultKeep as a reduction?
Remove ("north", "18.0")same ValueError at float(text)Yes
Replace "not recorded" with "0"program succeedsNo

Changing the invalid text to "0" makes the program run, but changes the case. During reduction, make one change, run again, and compare with the baseline.

Q2. Keep the same failure

Starting from the four-record baseline, which change is a valid first reduction?

Choose one

Select one choice, then check.

HintChange one detail, then compare

Do not make the program succeed yet. Preserve the original symptom while removing irrelevant input.

SolutionRemove one valid record

Remove the south record and run the program. If the east record still causes the same ValueError at float(text), the smaller input is a valid reduction. Only then remove another detail.

Not attempted
Review

Not marked done.

Repair the Boundary

Once the small case explains the failure, switch from reduction to repair. The policy is to report invalid numeric text and skip that row:

First run the one-record case. It should report east and return an empty list. Then restore the four records. It should report east and return all three valid readings. This checks the repair in the larger program.

Retain the Original Failure as a Check

The corrupt record should not become forgotten evidence. Keep a small check that runs whenever the parser changes:

This regression check protects behavior that once failed. It does not prove the parser correct for every input; other boundary tests provide other evidence.

Q3. Repair and retain the failing case

Complete the specific handler and the regression assertion. The full input must keep its three valid readings, while the original corrupt record returns an empty list.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintVerify both sizes of evidence

Add except ValueError as error, report and continue, then assert that parse_readings(corrupt_record) equals [].

SolutionHandle the boundary and keep the regression

The full run retains north, west, and south. The one-record check preserves the input that originally exposed the failure.

Not attempted
Review

Not marked done.

Record the baseline before changing the program. Reduce one detail at a time and keep a change only when the same failure remains. Then repair the boundary, rerun the full data, and retain the original corrupt record as a regression check. Chapter 8 can now move an expanded labelled measurement dataset into durable file input without losing this debugging method.

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

0 of 3 exercises marked done

Review

Not marked done.