Property-Based Testing · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

State the rule, let the machine attack it

Computing · Software Engineering · ages 20-22
Name ______________________   Date ____________
  1. What does the machine generate in property-based testing?

    • The final release notes
    • Hundreds of inputs trying to break the rule
    • The fixed version of your code
  2. Which of these is a property a sorting function must satisfy for any list?

    • The output is ordered and holds the same elements
    • The output of [3, 1, 2] is [1, 2, 3]
    • The function runs in under a second
  3. Shrinking turns a failing input into the smallest one that still fails.

    Circle one:   True   False

  4. Which pair of properties should a parser and its printer satisfy together?

    • Parsing printed output returns the original, and printing parsed input is stable
    • The parser is fast and the printer is short
    • Both handle the same file extension
  5. A 900-element list breaks your sorting property. Why is shrinking useful here?

    • It makes the sort run faster
    • It adds more random elements
    • It trims the failure to a tiny case that shows the cause
  6. What would a generator try in order to break a round-trip property?

    • Only the inputs from your documentation
    • Empty inputs, odd symbols, and deeply nested cases
    • Inputs that are already known to pass
  7. Your property holds for 10,000 generated inputs, yet users hit a wrong fee on one real invoice. What does this teach?

    • Generators replace all business-rule examples
    • Properties hunt surprises, but concrete rules still need example tests
    • Shrinking caused the wrong fee
  8. A property says reversed twice returns the original, and it passes. A reviewer still asks for one example test with an exact output. Why?

    • Properties cannot run without examples beside them
    • Shrinking only works on hand-written cases
    • Exact outputs and concrete rules need pinning down
LightMySky · lightmysky.comW1-mt_QqCNKT06IY-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

State the rule, let the machine attack it W1-mt_QqCNKT06IY-s1

  1. Hundreds of inputs trying to break the rule · Generated inputs attack the rule instead of you hand-writing cases.
  2. The output is ordered and holds the same elements · A property talks about every input, not one fixed example.
  3. True · The trimmed case points straight at the cause.
  4. Parsing printed output returns the original, and printing parsed input is stable · The two directions must round-trip, like encoding and decoding.
  5. It trims the failure to a tiny case that shows the cause · A tiny failing case reveals the bug that a monster input hides.
  6. Empty inputs, odd symbols, and deeply nested cases · Generators hunt edges and surprises, not the happy path.
  7. Properties hunt surprises, but concrete rules still need example tests · The missed fee was a concrete rule nobody pinned with an example.
  8. Exact outputs and concrete rules need pinning down · General rules cannot lock specific outputs, so examples keep that job.
Worksheet · LightMySky