Generate focused unit tests for a function's observable contract and important boundaries.
Generate unit tests for the single function or small code unit supplied. Focus on its externally observable contract, not a line-by-line copy of its implementation. ## Inputs Code: [CODE] Language, test framework and existing test style (paste one existing test if available): [FRAMEWORK] Expected behavior, including any known bug or reported failure: [CONTRACT] Command the project uses to run tests: [TEST_COMMAND] ## Instructions 1. List the behaviors the contract promises, then derive cases: normal inputs, boundaries (empty, zero, one, maximum, off-by-one), invalid inputs and errors, and async behavior when relevant. 2. If a known bug is described, write a test that fails on the current code and passes once the bug is fixed, and say which test that is. 3. Use Arrange-Act-Assert and names that state the condition and expected result. 4. Mock only true external dependencies (network, clock, filesystem, database). Do not mock the unit's own internals. 5. Where behavior is unspecified, write the case as a question or a clearly labeled assumption instead of asserting a guess. ## Return 1. A case list: case, input, expected result, contract clause it checks. 2. The test file, runnable with the stated command. 3. Required fixtures or setup. 4. Which tests you expect to fail against the current code and why. ## Acceptance checks Avoid unnecessary mocks of implementation details. State assumptions about unspecified behavior. Do not invent a passing test run or impose an arbitrary coverage percentage.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Code: `splitEvenly(totalCents, parts)` returns an array of `parts` integers; it throws RangeError for non-integer or negative totals and for parts < 1. Current implementation uses Math.floor(totalCents / parts) for every element. Framework: Node.js built-in `node:test` with `assert/strict` Contract: parts must sum exactly to totalCents and differ by at most one cent. Known bug: invoices split three ways lose a cent. Command: node --test
A case list including 1000 split 3 ways (must sum to 1000), 7 split 4 ways (max-min <= 1), zero total, parts = 0 (RangeError) and fractional cents (RangeError); a `node:test` file; and an explicit note that the sum test is the one expected to fail on the current floor-only implementation. Illustrative expectation, not a recorded model run. A reference test file with these five cases was executed locally against a buggy and a fixed implementation (see report).
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts:
Author-supplied tool and model tags; confirm behavior with your own examples.
IDEs
Models