Property-Based Tests for a Function

3 Views
0 Uses

Prompt

ChatGPT
Claude
Grok
OpenRouter
Act as a senior engineer experienced with property-based testing (Hypothesis for Python, fast-check for JavaScript and TypeScript, or the equivalent for {{LANGUAGE}}). Write property tests that check rules which must hold for every valid input, not just a few examples.

Language and property-testing library: {{LANGUAGE}} / {{PBT_LIBRARY}}
Code under test: {{CODE}}
What the function guarantees, in my words: {{GUARANTEES}}

Do this:
1. Identify candidate properties and explain each: round-trips (decode(encode(x)) == x), invariants (output is sorted, length preserved, total unchanged), idempotence (f(f(x)) == f(x)), comparison with a simpler but slower reference implementation, and "never crashes on valid input".
2. Pick the three to five strongest. Avoid properties that merely re-implement the function.
3. Write input generators that cover the real input space, including the awkward parts (empty, duplicates, extreme values, Unicode), with any constraints the function requires.
4. Write the property tests, runnable as-is with the stated library.
5. Explain how the library shrinks a failure to a minimal counterexample, and how to save it as a regular regression test.

If a property you'd expect doesn't hold for this code, say so and show the counterexample you suspect.

Customize this prompt

Fill in the variables below to personalize this prompt:

ChatGPT
Claude
Grok
OpenRouter

Model Settings

Recommended Models

ChatGPT Claude Gemini

Temperature

0.7

Max Tokens

2000

Additional Notes

Best for: Catching edge cases no one thought to write down

About this prompt

“Property-Based Tests for a Function” is a free prompt for ChatGPT in the Coding & Software category, 188 words long, added to The Prompt Index on October 28, 2026 by The Prompt Index. Copy it with the button above, paste it into ChatGPT or any other AI chat assistant, and send it.

It has 4 placeholders to fill in first: {{LANGUAGE}}, {{PBT_LIBRARY}}, {{CODE}}, {{GUARANTEES}}. Use the “Customize this prompt” fields to personalise it before you copy.

Recommended models: ChatGPT, Claude, Gemini.

0 upvotes, sent to an AI tool 0 times, viewed 3 times.

Browse all Coding & Software prompts, the AI prompt database or use the AI prompt finder to search every prompt.