Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint โ€” Refactor Under Guard

โญโญ intermediateโณ 25 min read๐Ÿ“ Lesson 140 of 265

Rebuild a smelly pricing method as clean code that provably behaves identically โ€” then extend it, with Legacy standing in for the frozen test suite.

The gate (mini-build)

Legacy.Price (provided, do not modify) is the behavior contract:

| tier | qty โ‰ฅ 10 | qty < 10 | |---|---|---| | gold | 20% off | 10% off | | silver | 10% off | 5% off | | anything else | no discount | no discount |

Any tier with qty > 100 gains an extra 2% off, stacked.

Implement Solution.Price(qty, unit, tier) with identical behavior, plus one new requirement: tier "vip" gets a flat 25% off (the >100 bulk extra still stacks on top). Structure it the clean way โ€” named constants or a switch expression over the tier, one rule per line, no magic numbers.

Your safety net is the legacy code itself: the tests compare your Solution against Legacy across a matrix, then pin the boundaries and the new vip behavior exactly.