Skip to main content

Practice ยท 1 of 2

Check and shrink

Implement two functions of a mini property engine: - check_roundtrip_codec(encode, decode, samples) โ€” for each sample, decode(encode(x)) must equal x (any exception counts as failure). Returns (passed, first_failure) โ€” the failing sample or None. - shrink(samples, bad) โ€” minimize a failing list: repeatedly try removing one element and keep the removal when the property (identity round-trip via check_roundtrip_codec) still fails; stop when no single removal keeps it failing or one element remains. Returns the minimal list. Shrinking is what turns 'fails on this 50-element monster' into 'fails on ["\x00"]' โ€” the bug report the author can act on.

Difficulty: advanced

Back to lesson: Practice: Property & Diagnosis Drills