0
Generate property-based tests that find edge cases, not happy-path duplicates
⁂auto-checked, 4 days oldAauraNovice
The prompt
Write property-based tests (using {{framework, e.g. Hypothesis / fast-check / QuickCheck}}) for the function below. Do not write example-based tests that just restate the happy path; instead:
1. Identify the invariants the function should always satisfy (e.g. idempotence, round-trip, monotonicity, commutativity where applicable) and encode each as a property.
2. Identify the input domain's edge cases (empty, single-element, max/min values, unicode, negative numbers, duplicates) and make sure the generator can produce them, don't hand-pick a few examples.
3. For any invariant you're not confident actually holds, say so explicitly and mark the test with a comment explaining what you'd expect to see if it fails, rather than silently writing a weak assertion.
4. Keep generators realistic to the function's actual input contract, not maximally adversarial if that's outside the documented contract.
Function:
code
Language: language
Known contract/docstring: contract
Where it has been run
| Model | Version | People | Broke | Auto | Last |
|---|---|---|---|---|---|
| Claude | Haiku 4.5 | 0 | 0 | 1/1 | 4 days ago |
Example output
Properties written for `normalize_whitespace(s: str) -> str`:
1. Idempotence: `normalize(normalize(s)) == normalize(s)` for all strings, using `st.text()`.
2. Length invariant: output length never exceeds input length.
3. No leading/trailing whitespace in output, for any generated string including ones that are all whitespace.
4. Round-trip on already-normalized strings: `normalize(s) == s` when `s` has single internal spaces and no edges.
Flagged uncertain: I'm not confident the function preserves non-breaking spaces (U+00A0) as visible whitespace versus collapsing them, since the docstring only mentions ASCII whitespace. Added a property test with a comment: 'if this fails, decide whether NBSP should be treated as whitespace or preserved, then update the docstring accordingly, this is a spec question not a test bug.' Generator uses `st.text(alphabet=st.characters(whitelist_categories=('Zs','Cc')))` mixed with printable text to hit whitespace-heavy edge cases realistically.
0 comments
Sign in to comment or report what this prompt did for you.
Sign inNo comments yet. Run the prompt and report what you got.