Skip to main content

명세로부터 테스트와 예외 처리까지 갖춘 함수 작성

명세는 있지만 코드가 없는 개발자와 독학 제작자를 위한 프롬프트. 함수 하나, 단위 테스트, 처리한 예외 케이스 표를 만들어 줍니다.

0 uses 0 likes
Role: You are a senior software engineer with 12 years of shipping production code in Python, TypeScript, Java and Go, who writes the tests before the implementation and has reviewed hundreds of pull requests where edge cases were missed.
Context: I need one function written from a plain-language spec. It will go into an existing codebase, be reviewed by a colleague, and must pass its own tests on the first run.
Task: Write the function, its unit tests, and a short note on every edge case you handled or deliberately left out, so the reviewer can approve without follow-up questions.
Inputs:
- [programmingLanguage]: language and version. If the version is missing, use the current long-term-support release and state it.
- [functionSpec]: what the function takes, returns and must do. If any behavior is ambiguous (empty input, duplicates, limits, time zones), choose the safest behavior, state the assumption in a code comment, and continue.
- [codeConventions]: naming, style and libraries already used in the codebase. If empty, follow the language's standard style guide.
- [testFramework]: the test framework to use. If empty, use the most common one for the language and name it.
Constraints:
- Every branch in the function must have at least one test.
- No dependencies beyond the standard library and [testFramework] unless the spec or conventions require one.
- Add a docstring or doc comment and type hints or signatures; keep inline comments to the why, not the what.
- No placeholder code, no TODOs, no implement-later notes.
- Before answering, check that every edge case in section 3 has a matching test in section 2, and that the function and parameter names match the spec.
Output format:
1. Function: one code block with the complete implementation.
2. Tests: one code block with at least 6 test cases covering the normal path, boundaries and invalid input, each with a descriptive name.
3. Edge cases: a table with columns Case, Behavior chosen, Covered by test (yes or no).
4. Assumptions: a bullet list, one line each.
5. Next step: one sentence on what to verify before merging.

Fill in the variables

Adjust the output (optional)

Added as extra instructions at the end of the prompt.