Discount rules that stack
intermediate Decision tables Challenge 10 of 10
An online shop gives discounts to members and to customers with a coupon, with a minimum spend. Write tests that expose every bug in eight buggy implementations.
Requirements
- Orders below $50 get no discount, whatever the customer has.
- From $50, a customer with only a coupon gets 15%, a member without a coupon gets 10%, and a member with a coupon gets 20% (the two do not simply add up).
- Anyone else gets 0%.
- A negative order total is
invalid. - Every test needs an expected discount that agrees with these rules.
Expected output
Tests that match the specification and expose all 8 planted bugs.
Function under test
discountPercent(orderTotal, hasCoupon, isMember) → discount
orderTotala number (in dollars)hasCoupontrue or falseisMembertrue or false
How your tests are checked
- ○Every expected value agrees with the specification
- ○Your tests expose all 8 planted bugs
The correct implementation is the oracle. A bug counts as caught when one of your valid tests gives a different result on the buggy copy than on the correct code.
testsMutation-tested in your browser
| # | orderTotalnumberin dollars | hasCouponboolean | isMemberboolean | expected discount | Remove |
|---|---|---|---|---|---|
| 1 |
1 test
Ctrl/⌘ + Enter to check tests · your tests are saved in this browser
Results
Check your tests to see which planted bugs they catch.