Build the following using strict Test-Driven Development:
Feature: $ARGUMENTS
The TDD Cycle
Repeat this cycle for each behavior. Never skip steps.
Red: Write a Failing Test
- Write ONE test for the smallest next behavior (not the whole feature)
- The test must:
- Describe the behavior in its name:
should return 0 for empty cart
- Use Arrange-Act-Assert structure
- Assert specific values, not vague truths
- Run the test. It MUST fail. If it passes, either:
- The behavior already exists (skip to the next behavior)
- The test is wrong (it's not testing what you think. Fix it)
- Verify the failure message makes sense. It should tell you what's missing
Green: Write the Minimum Code to Pass
- Write the simplest, most obvious code that makes the failing test pass
- Don't generalize. Don't make it elegant. Don't handle cases the test doesn't cover.
- Hardcoding is fine if only one test exists for that path. The next test will force generalization
- Run the test. It MUST pass. If it doesn't, fix the code (not the test. The test defined the behavior)
- Run ALL tests. Nothing previously passing should break.
Refactor: Clean Up Without Changing Behavior
- Look for: duplication, unclear names, functions doing too much, magic values
- Make ONE improvement at a time
- Run ALL tests after each change. If anything breaks, undo immediately.
- Stop refactoring when the code is clean enough. Don't gold-plate
Choosing What to Test Next
Work from simple to complex:
- Degenerate cases. Null input, empty collection, zero
- Happy path. The simplest valid input
- Variations. Different valid inputs that exercise different branches
- Edge cases. Boundary values, max sizes, special characters
- Error cases. Invalid input, failures, exceptions
- Integration. How this connects to the rest of the system
Each test should require a small code change. If you need to write more than ~10 lines of production code to pass a test, the test is too big. Split it.
Rules
- Never write production code without a failing test that demands it.
- Never write more than one failing test at a time. One red → green → refactor cycle at a time.
- The test drives the design. If the code is hard to test, the design is wrong. Change the design, not the test approach.
- Don't mock what you own. If you need to mock your own code to test it, the code needs restructuring.
- Commit after each green+refactor cycle. Small, passing, meaningful commits.
Output
After each cycle, briefly state:
- Test: what behavior was added
- Code: what changed to make it pass
- Refactor: what was cleaned up (or "none needed")
When the feature is complete, provide a summary of all behaviors covered and any gaps that would need integration or manual testing.
1---2name: tdd3description: Test-Driven Development loop. Write a failing test first, then the minimum code to pass it, then refactor. Repeat.4---56Build the following using strict Test-Driven Development:78**Feature**: $ARGUMENTS910## The TDD Cycle1112Repeat this cycle for each behavior. Never skip steps.1314### Red: Write a Failing Test15161. Write ONE test for the smallest next behavior (not the whole feature)172. The test must:18 - Describe the behavior in its name: `should return 0 for empty cart`19 - Use Arrange-Act-Assert structure20 - Assert specific values, not vague truths213. **Run the test. It MUST fail.** If it passes, either:22 - The behavior already exists (skip to the next behavior)23 - The test is wrong (it's not testing what you think. Fix it)244. Verify the failure message makes sense. It should tell you what's missing2526### Green: Write the Minimum Code to Pass27281. Write the **simplest, most obvious code** that makes the failing test pass292. Don't generalize. Don't make it elegant. Don't handle cases the test doesn't cover.303. Hardcoding is fine if only one test exists for that path. The next test will force generalization314. **Run the test. It MUST pass.** If it doesn't, fix the code (not the test. The test defined the behavior)325. Run ALL tests. Nothing previously passing should break.3334### Refactor: Clean Up Without Changing Behavior35361. Look for: duplication, unclear names, functions doing too much, magic values372. Make ONE improvement at a time383. **Run ALL tests after each change.** If anything breaks, undo immediately.394. Stop refactoring when the code is clean enough. Don't gold-plate4041## Choosing What to Test Next4243Work from simple to complex:441. **Degenerate cases**. Null input, empty collection, zero452. **Happy path**. The simplest valid input463. **Variations**. Different valid inputs that exercise different branches474. **Edge cases**. Boundary values, max sizes, special characters485. **Error cases**. Invalid input, failures, exceptions496. **Integration**. How this connects to the rest of the system5051Each test should require a small code change. If you need to write more than ~10 lines of production code to pass a test, the test is too big. Split it.5253## Rules5455- **Never write production code without a failing test that demands it.**56- **Never write more than one failing test at a time.** One red → green → refactor cycle at a time.57- **The test drives the design.** If the code is hard to test, the design is wrong. Change the design, not the test approach.58- **Don't mock what you own.** If you need to mock your own code to test it, the code needs restructuring.59- **Commit after each green+refactor cycle.** Small, passing, meaningful commits.6061## Output6263After each cycle, briefly state:64- **Test**: what behavior was added65- **Code**: what changed to make it pass66- **Refactor**: what was cleaned up (or "none needed")6768When the feature is complete, provide a summary of all behaviors covered and any gaps that would need integration or manual testing.