Tests as Discriminating Evidence

This original unit-5 laboratory asks what a passing test actually establishes. It joins a small specification oracle, four plausible defective implementations, a deterministic case generator, a failure shrinker and a real SQLite transaction boundary. All records are synthetic and local. Practice is optional; the complete explanations remain available whether or not a learner attempts the exercises.

Start with a claim, not a coverage percentage

A test result is an argument with a limited conclusion. The requirement defines the claim; the test supplies an observation; the oracle says what observation would count as success. Line coverage answers whether execution visited particular lines. It does not tell whether the asserted result was independently derived, whether an omitted requirement matters, or whether a requirement itself is defensible. A suite can execute every line and still accept a function that collapses two distinct equal-value events.

The laboratory contract is deliberately narrow. An Event has a nonempty identifier of at most 80 code points and integer cents in the closed range ±100,000,000; booleans are not cents. Identifiers must be unique within the supplied sequence. summarize returns both event count and exact integer-cent total. Equal amounts with different identifiers are different events, zero is present rather than missing, and a negative amount is a refund rather than an absolute-valued charge. These choices are the test oracle's premises, not universal accounting rules.

Design evidence that can distinguish plausible errors

Plausible defectWeak case that survivesDiscriminating caseIndependent result
Deduplicate by amount[100, 200]events A100 and B100count 2, total 200
Drop falsey amountspositive values onlyevent Z0count 1, total 0
Keep only the first eventone eventA40 and B2count 2, total 42
Turn refunds positivecharges onlysale100 and refund−40count 2, total 60

Each expected result above is computed from the contract, outside the implementation under test. In contrast, assigning mirrored_expected = mutant_deduplicate_amount(rows) and comparing the same function with that value passes even when the contract requires 200 and the mutant returns 100. This is a false oracle: the test repeats the defect instead of challenging it.

Reduce a failure without reducing its meaning

When A100, B100 and C50 expose amount deduplication, the deletion shrinker removes one event at a time only while disagreement with the independent oracle remains. Removing A or B leaves distinct values and the defect disappears; removing C leaves A100 and B100 and preserves the disagreement. The minimal observed counterexample is therefore two different identifiers with the same value. That result identifies the mechanism—loss of multiplicity—more clearly than a large random fixture. The greedy shrinker does not prove global minimality for every failure or data type; it proves only that none of its remaining records can be deleted without losing this observed disagreement.

Properties need domains and boundary conditions

For validated raw event sequences a and b with disjoint identifiers, summarizing their concatenation should add both counts and integer-cent totals. The test generator records seed 20261026 and gives each generated event a unique case-local identifier. Forty replayable cases include emptiness, zero, negative values and repeated amounts. Re-running the seed produces identical cases, so a failure can be reproduced. A fixed seed is not evidence that all possible sequences were sampled, and it does not excuse missing targeted boundary examples.

The same additivity claim is false after invoice-level rounding. With half-up rounding at 50%, one combined two-cent invoice pays one cent. Two independently rounded one-cent invoices each pay one cent, for a partitioned total of two. The failed property identifies a mismatched premise: rounding occurs at a different boundary. It does not by itself identify a defect in the discount function. A corrected test must state whether the policy rounds once per combined invoice or once per separately issued invoice.

Unit evidence and integration evidence answer different questions

Pure tests can establish the summary contract without storage. They cannot establish that a coordinator commits the summary and its audit together. The SQLite exercise creates separate batch_summary and batch_audit tables, starts BEGIN IMMEDIATE, inserts both rows, and commits only after both operations succeed. A successful fixture with events 500, −200 and 0 must store count 3 and total 300 plus one audit message. An injected failure after the summary insert but before the audit forces rollback; querying both tables must return no rows. Checking only the raised exception would miss a partial summary.

This demonstrates one local transaction mechanism under the tested SQLite conditions. It does not establish production authentication, multi-process fairness, distributed transactions, crash durability under every filesystem mode, or performance on an unbounded dataset. Those require distinct specifications and experiments.

Worked investigation

Suppose a total function is tested only with A100 and B−100. A constant-zero implementation passes because the correct total happens to be zero. Add A100 alone to reject constant zero; add R−20 to reject discarded refunds; add A100 and B100 to reject amount deduplication; add Z0 and assert both count and total to reject falsey filtering; add the empty sequence to establish the identity. The expected values should be written from the event contract before invoking the implementation.

Now generate forty cases with seed 20261026. Comparing each candidate implementation with summarize finds a counterexample when one exists in those cases. Record the seed and failing case, then shrink it. If no generated case fails, the warranted conclusion is only “no disagreement in this generated sample,” not “the implementation is correct.” Targeted examples remain necessary because generation probabilities may be poor at policy boundaries.

Independent progression

  1. For A100, B100 and C0, predict count and total for the specification and all four mutants. Identify which one case cannot kill every mutant and add the fewest additional cases you can justify.
  2. A learner uses the candidate function itself to compute expected values for 500 generated cases. Explain precisely why more cases do not repair the oracle dependence. Replace the oracle without copying implementation steps.
  3. The generator discovers A40, B40, C−5 against the amount-deduplication mutant. Trace deletion shrinking in at least two valid orders. Explain why greedy one-record deletion may return a locally irreducible case without proving a globally smallest input for a different failure predicate.
  4. State a valid concatenation property for raw summaries, including the identifier precondition. Then evaluate the analogous property for separately rounded 50% discounts on one-cent partitions and revise the property rather than changing an observed result.
  5. Add an injected failure after the audit insert but before commit. Specify every database observation required to show atomic rollback. Then design a separate concurrent-writer experiment and explain why the current serial test cannot answer its scheduling question.
Compare complete reasoning

The specification returns count3,total200. Amount deduplication returns count2,total100; falsey filtering returns count2,total200; first-only returns count1,total100; absolute-refund is unchanged here because there is no negative value. Therefore this case cannot expose the refund defect. Add sale100 and refund−40, whose total60 differs from140. If each mutant must be killed by at least one test rather than by one universal fixture, these two cases suffice alongside validation tests.

Five hundred circular comparisons remain circular: each expected value inherits the candidate's rule. Derive small expectations by hand from the contract or write a structurally independent oracle, such as a straightforward count and integer sum over already validated events. Independence is not guaranteed merely because code lives in a different function; shared wrong assumptions must be examined.

From A40,B40,C−5, deleting C leaves the two equal values and still exposes multiplicity loss. Deleting either equal-value event from that result removes the disagreement. Another deletion order may first remove A or B, leaving 40 and−5, which does not fail and therefore is rejected by the shrinker; it then removes C and reaches the other two-equal-event pair. Greedy deletion establishes one-record irreducibility under its predicate. A failure requiring coordinated changes can have a smaller counterexample unreachable through individually preserving deletions.

For disjoint valid identifiers, summarize(a+b) equals the pairwise sum of summarize(a) and summarize(b). The disjointness condition matters because the contract rejects duplicate identifiers. Discounting a combined two cents at50% produces one; discounting two separate one-cent invoices produces one plus one. The correct property must retain the same rounding boundary on both sides, or account explicitly for a bounded rounding discrepancy.

A failure after both inserts but before commit must leave both tables unchanged; verify exact row sets, not only counts or an exception. A concurrency experiment needs two independent connections, declared timeout/locking expectations, synchronized start points and observations of the winning commit, waiting or rejection. The serial injected failure establishes rollback, not writer ordering.

Run and inspect the complete implementation

Save the following as python_test_evidence.py and test_python_test_evidence.py, then run python -m unittest -v test_python_test_evidence.py with Python 3.10 or newer. Nine groups should pass. Source SHA-256: 09eba0d3d34195f89eec2640b368129dd84eb52cddbd49e988db4ea7973aa0a0. Test SHA-256: 106478c0f647912a27156f6966a9210e463b58f89eaf1126de03faff6d5bc832.

Complete Python source
Complete executable tests

Expected independent results: A100,B100,C50 has specification Summary(3,250) while amount deduplication gives Summary(2,150); shrinking preserves two distinct 100-cent events; a combined two-cent 50% invoice yields1 while separately rounded partitions yield2; the injected audit failure leaves both SQLite tables empty.

Source map and limits

The complete mapped sources supply far broader language and testing reference than this laboratory. The laboratory's role is to connect them through one inspectable evidence argument. Passing these nine groups is not a formal proof, exhaustive input search, production reliability certification or whole-course acceptance.