What distinguishes property-based testing from example-based testing?
Property-based testing: instead of expect(add(2,3)).toBe(5), you assert a property like "add(a,b) === add(b,a) for all integers". The framework (fast-check, QuickCheck) generates counterexamples automatically.
2 / 5
What is a generator in the context of fast-check?
Arbitrary / generator:fc.integer(), fc.string(), or composed arbitraries define the domain of values to explore. The library samples from them and shrinks on failure to find the minimal counterexample.
3 / 5
What is shrinking in property-based testing?
Shrinking: a failing input of a 1000-character string is hard to debug. The framework iteratively simplifies it (fewer chars, smaller numbers) until the minimal failing case is found, making the bug obvious.
4 / 5
What is a good example of a property to test for a sort function?
Sort property: instead of fixed examples, you assert invariants: output length equals input length, output is a permutation of the input, and adjacent elements are non-decreasing — for any random array.
5 / 5
What is the model-based testing approach in property-based frameworks?
Model-based testing: you implement a trivial reference (e.g., a plain array as a model for a complex cache) and apply random sequences of operations to both. Any divergence reveals bugs in the real implementation.