Fill in these first
- Language: [e.g. TypeScript, Python, Java, PHP]
- Test framework: [e.g. Jest, Vitest, pytest, JUnit, PHPUnit]
- Function to test: [paste the function here]
- Dependencies it calls: [database, API, clock, file system, or none]
- Known business rules: [rules the function must follow]
Task
Write unit tests that would catch a real regression in this function, not only confirm the happy path.
Output format
- Test plan table:
| # | Behaviour tested | Input | Expected result | Type (normal, edge, error) |
Include at least four normal cases, four edge cases and two error cases.
- The complete test file, ready to run, with imports and any mocks or fixtures.
- Notes: anything in the function that is hard to test, and one small change that would make it easier.
Edge cases to consider
- Empty, null or missing values
- Zero, negative and very large numbers
- Boundary values at and around each limit
- Unusual strings: whitespace, Unicode, very long input
- Duplicate entries and unsorted input
- Time zones and date boundaries where dates are involved
Quality rules
- Test names describe the behaviour, e.g. returns zero when the cart is empty.
- One behaviour per test, arranged as setup, action, assertion.
- Mock external dependencies; never call real networks or databases.
- Freeze the clock for any time-based logic.
- Do not change the function under test.
- If a case reveals a likely bug, write the test for correct behaviour and flag it in the notes.






