Write a check that catches broken code
shipping_fee(order_total) follows this rule: orders of 500 or more ship free (fee 0), smaller orders pay a fee of 40.
Write check_shipping_fee(fn). It receives any function fn that claims to follow the rule and uses assert to check it with several inputs, including the values on and next to the boundary. It must pass silently for a correct function and **raise AssertionError** for a wrong one.
Each assert looks like assert fn(500) == 0: call fn with an order total and compare the result with the fee the rule demands. Write a message after a comma if you like.
Your check will be run against the correct function and against three broken ones: one that starts free shipping one unit too late, one with the wrong fee, and one that stops giving free shipping for very large orders. The last two lines of the starter run your check on the correct function and print shipping_fee passed all checks.
What Check tests
- The correct
shipping_feepasses your check - A function with
>instead of>=is caught - A function with the wrong fee is caught
- A function that fails for very large orders is caught
- Your check uses
assert
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Output
Press Run to see what your program prints.