Shipping fee: a decision table
advanced Decision tables Challenge 7 of 10
An online shop calculates the shipping fee for a parcel from its weight, the destination region and whether the customer chose express delivery. Write tests that expose every bug in nine buggy implementations.
Requirements
- Weights above 0 and up to 30 kg are accepted. Anything else is
rejected. - Base fee by region:
domestic5,eu12,world25. - Parcels heavier than 10 kg add a surcharge of 8 to the base fee.
- Express delivery doubles the whole fee (base plus surcharge).
- Express delivery is not available for
world: the result isrejected. - Every test needs an expected fee that agrees with these rules.
Expected output
Tests that match the specification and expose all 9 planted bugs.
Function under test
shippingFee(weightKg, express, region) → fee
weightKga number (kilograms, decimals allowed)expresstrue or falseregionone of domestic, eu, world
How your tests are checked
- ○Every expected value agrees with the specification
- ○Your tests expose all 9 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
| # | weightKgnumberkilograms, decimals allowed | expressboolean | regionchoice | expected fee | 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.