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 a configured input generator supply for a property-based test?

    • A proof covering every possible allowed input
    • Cases from the property's allowed input domain
    • A corrected implementation of the tested function
  2. Which property checks both ordering and complete element preservation for ascending integer sorting?

    • Output is ordered with exactly the input's values and counts
    • Ordered output preserving input-value counts, but allowing new values
    • Ordered output with repeats collapsed
  3. Shrinking generally guarantees the globally smallest input that can fail a property.

    Circle one:   True   False

  4. A parser/printer contract preserves values and prints canonical text. Which pair follows?

    • Parsing a printed value preserves it; normalizing text twice is stable
    • Parsing a printed value preserves it; printed text keeps the original spacing
    • Parsed values are preserved; a second normalization restores the old spacing
  5. A 900-element list fails a sorting property. What can a shrinking search usefully provide?

    • A shorter input that passes the property
    • A reordered input that hides the failure
    • A simpler case that still exhibits the failure
  6. A property covers lists of at most six integers. Which generator plan stays in that domain while varying useful cases?

    • Generate arbitrary text and lists of any length without checking validity
    • Generate empty lists, repeats and varied orders within the length limit
    • Generate only one fixed six-element list and reuse it on every check
  7. A fee property checks only that fees are nonnegative. An invoice requires a fee of 12, but the function returns 14 and the property passes. Why?

    • Too few generated invoices left this positive fee unchecked
    • Nonnegativity does not check the required amount
    • Shrinking changed the expected fee
  8. A reverse function returns its input unchanged. It passes 'reversing twice returns the original'. What does an example expecting [2, 9] to become [9, 2] add?

    • Another check of the double-reversal rule
    • A check that reversal leaves the input order intact
    • A check that rejects the unchanged-input implementation
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. Cases from the property's allowed input domain · The generator supplies input cases. The property check evaluates them; a finite passing run is not a proof.
  2. Output is ordered with exactly the input's values and counts · Correct sorting orders the output and preserves the complete multiset: the same values with the same counts, with no additions.
  3. False · Shrinking searches for a simpler failing case. Its search need not find the globally smallest counterexample.
  4. Parsing a printed value preserves it; normalizing text twice is stable · The value round trip preserves the allowed value. Canonical text remains the same after another parse-and-print normalization.
  5. A simpler case that still exhibits the failure · A simpler failing case can reduce the material you need to inspect. It is not itself a diagnosis or repair.
  6. Generate empty lists, repeats and varied orders within the length limit · Empty lists, repeats and varied orders fit the stated domain when the length limit is respected.
  7. Nonnegativity does not check the required amount · Both 12 and 14 are nonnegative. The property does not distinguish the required amount from this incorrect amount.
  8. A check that rejects the unchanged-input implementation · The weak property permits doing nothing. The stated example distinguishes reversing from returning the input unchanged.
Worksheet · LightMySky