1–3. Partitions (traced by hand)
| Partition | Input (subtotal, kg, country, express) | Output |
|---|---|---|
| Free-shipping threshold, exact | 999, 1, "IN" | 0 |
| Just below threshold | 998.99, 1, "IN" | 49 |
| International, below threshold | 500, 1, "US" | 499 |
| International, above threshold | 1500, 1, "US" | 0 SUSPECT: free international shipping may be meant for India only |
| Lowercase country | 500, 1, "in" | 499 SUSPECT: "in" is charged as international |
| Weight exactly 5 | 500, 5, "IN" | 49 |
| Weight 5.9 | 500, 5.9, "IN" | 49 SUSPECT: int() floors the extra 0.9 kg, so no surcharge |
| Weight 7.5 | 500, 7.5, "IN" | 89 |
| Free order, heavy | 1200, 8, "IN" | 60 |
| Express, paid order | 500, 1, "IN", True | 98 |
| Express, free order | 1200, 1, "IN", True | 99 SUSPECT: costs more than express on a paid order |
| Express, free and heavy | 1200, 8, "IN", True | 120 |
4. Test file
`python
tests/test_shipping_fee.py
import pytest
from checkout.fees import shipping_fee
@pytest.mark.parametrize("subtotal, expected", [(999, 0), (998.99, 49)])
def test_free_shipping_starts_at_999(subtotal, expected):
assert shipping_fee(subtotal, 1, "IN") == expected
def test_international_orders_below_threshold_pay_499():
assert shipping_fee(500, 1, "US") == 499
def test_international_orders_above_threshold_ship_free():
# SUSPECT: free-shipping rule ignores country
assert shipping_fee(1500, 1, "US") == 0
def test_lowercase_country_is_treated_as_international():
# SUSPECT: no normalization of country code
assert shipping_fee(500, 1, "in") == 499
@pytest.mark.parametrize("kg, expected", [(5, 49), (5.9, 49), (7.5, 89)])
def test_weight_surcharge_is_20_per_whole_kg_over_5(kg, expected):
# SUSPECT at 5.9: partial kilograms are floored
assert shipping_fee(500, kg, "IN") == expected
def test_free_orders_still_pay_weight_surcharge():
assert shipping_fee(1200, 8, "IN") == 60
def test_express_doubles_a_paid_fee():
assert shipping_fee(500, 1, "IN", express=True) == 98
def test_express_on_a_free_order_costs_flat_99():
# SUSPECT: more than express on a paid domestic order (98)
assert shipping_fee(1200, 1, "IN", express=True) == 99
def test_express_doubles_the_surcharge_on_free_heavy_orders():
assert shipping_fee(1200, 8, "IN", express=True) == 120
`
5. Coverage
Every branch is exercised. Nothing covers invalid input: negative weights, None for country, or a string subtotal. The function has no validation, so decide whether that belongs here or at the caller before adding tests for it.