Knowledge Sprint SeriesMT24 Learning

Phase 4 · Sprint 12/90 · Mathematical & Logical FoundationsProperties · Tolerance · Shrinking

Testing & Phase Review

Every claim in this phase, checked by running it.

In short. What a test can and cannot show, property-based testing, why floats need a tolerance, and a review of the phase.

Sprint 12 of 90 infographic: Testing & Phase Review. Every claim in this phase, checked by running it. The full text of the image is on this page.
Full resolution2160 × 2700 PNGPhase summary

The part of the image you are reading lights up. Tap a part to jump to its text.

Fig. 1 in words

How a property-based test runs. Floats broke the associativity rule; the tool reported a failing case.

  1. one property · many inputs

    • 1 · Generate: a, b, c in [0, 10] → 2 · Check: (a+b)+c == a+(b+c)
    • Check is joined by a dashed line to a dashed box: Property · for ALL inputs
    • pass · next input: a dashed arrow from Check back to Generate
    • fail: an arrow from Check down to 3 · Shrink: a simpler failure, with a dashed loop: repeat
    • Shrink → 4 · Report: 3.03…, 0.99999, 1.0

01 What a Test Is

  • A claim, checked by running the code
  • Example test: one input, one answer

Dijkstra (1969): "Program testing can be used to show the presence of bugs, but never to show their absence!"

02 Property Tests

  • State a rule for all inputs, not one
  • The tool generates cases and shrinks failures

QuickCheck (Claessen & Hughes, 2000) popularised the idea; Hypothesis brings it to Python.

03 Floats Need Tolerance

  • 0.1 + 0.2 == 0.3 is False
  • Compare with math.isclose, not ==

Floats round at every step, so the order of operations can change the result (Goldberg, 1991).

04 Phase 4 Review

  • Sprint 9: gradient vs finite differences
  • Sprint 10: every row of the truth table
  • Sprint 11: angle excess vs area

Three checks: numerical, exhaustive, and against a known answer.

05 Try It Yourself

sprint12_testing_phase_review.py

import math
import hypothesis as h
x = h.strategies.floats(0, 10)
@h.settings(derandomize=True)
@h.given(x, x, x)
def test_exact(a, b, c):
    assert (a+b)+c == a+(b+c)
@h.given(x, x, x)
def test_close(a, b, c):
    assert math.isclose((a+b)+c,
        a+(b+c), abs_tol=1e-9)

Output, as printed on the image

pytest: 1 failed, 1 passed
a=3.0338…, b=0.99999, c=1.0

Run it. sprint12_testing_phase_review.py · versions, data and steps

06 General Notes

  • Test the rule, not one example
  • Keep each failure as a test
  • Floats: a tolerance, never ==
  • A green run is evidence, not proof

07 Mini Project

  • Write 3 properties for Sprint 9's code
  • Run Hypothesis; keep each failure
  • Swap == for isclose where needed
  • Run every test in CI (Sprint 3)

R Trusted Sources

  1. Dijkstra (1969). Notes on Structured Programming (EWD 249)
  2. Claessen & Hughes (2000). QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs. ICFP
  3. Goldberg (1991). What Every Computer Scientist Should Know About Floating-Point Arithmetic
  4. Hypothesis documentation
  5. Python documentation, math.isclose (PEP 485)

Cite this phase

Tahri, M. (2026). MT24 Learning — Knowledge Sprint Series, Phase 4: Mathematical & Logical Foundations (Version 1.0) [Educational resource]. Zenodo. https://doi.org/10.5281/zenodo.22999436

Version DOI 10.5281/zenodo.22999436 · all versions 10.5281/zenodo.22999435 · first published 25 September 2026