DebugMidBackendAuto-graded
Reproduce a pricing bug with a test, then fix it
A customer was charged the wrong price. Prove it with a failing test first, then fix the code.A Spring Boot service prices shopping baskets: a subtotal, a discount for large baskets, a discount for members and a coupon. A customer reports that they paid more than the published rules say, and gives their exact basket. Work test first. Write a new JUnit test that reproduces their case and fails on the current code. Then fix the code so your test and all the existing tests pass. The pricing rules and worked examples are in the brief.35 min
java, spring-boot, maven
You're done when
- Your new test class fails when it runs against the original code.
- After your fix, your new test passes, on your code and on any other correct fix.
- The customer's basket (2 x 60.00, member, SAVE5) costs 97.60.
- SAVE5 comes off after the 10% discount, for any basket (for example 150.00 with SAVE5 costs 130.00).
- SAVE5 comes off after the member discount, for any basket (for example 40.00 for a member with SAVE5 costs 33.00).
- The existing tests still pass.
- A subtotal of exactly 100.00 gets the 10% discount; 99.99 does not.
- The total is never below 0.00.
- The total is rounded once, at the end, half up to 2 decimals.
- The last four (existing tests, 100.00 threshold, never below 0.00, rounding once) already hold on the starting code, so they count only once SAVE5 comes off after the percentage discounts.
What it measures
Test-first bug fixingTurning a customer report into a JUnit test that fails for the right reason before touching the code.
Fixing the root causeChanging the pricing code so the reported case is right and every other rule still holds.
Money in JavaApplying discounts in the right order with BigDecimal and rounding only once.
Your environment
Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish
Start this lab
35 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo