Write tests for a function you already have

code & data

// what it does

Paste the function and name the framework (pytest, Jest, JUnit) and ChatGPT drafts a test suite, usually including edge cases you did not list — empty input, boundaries, error paths. Asking it to explain what each test covers surfaces assumptions about the code's behavior worth confirming.

// prompt

> Write pytest tests for the function below. Cover normal cases, empty and boundary inputs, and invalid types. Add a one-line comment on what each test verifies. Function: [paste function]

// gotcha

Generated tests can assert the code's current behavior, bugs included, rather than the correct behavior. Review each assertion against what the function should do, and add the domain-specific edge cases the model cannot know about.

// resources