float, rounded to 2 decimal placesYYYY-MM-DD)The following specs define the contracts for the order processing module.
SIGNATURE: def calculate_order_total(items: list[dict], tax_rate: float) -> float
INTENT: Calculates the total cost of an order including tax. Each item has a price and quantity. Returns the final total rounded to 2 decimal places.
BEHAVIOR:
TESTS:
calculate_order_total([{'price': 15.99, 'quantity': 2}, {'price': 24.50, 'quantity': 1}], 8.5) == 61.28calculate_order_total([], 8.5) == 0.00calculate_order_total([{'price': 100.0, 'quantity': 1}], 0) == 100.00calculate_order_total([{'price': -5.0, 'quantity': 1}], 8.5) raises ValueErrorcalculate_order_total([{'price': 10.0, 'quantity': 0}], 8.5) raises ValueErrorEDGE_CASES:
SIGNATURE: def validate_coupon(code: str, active_coupons: list[dict], current_date: str) -> tuple[bool, dict | str]
INTENT: Validates a coupon code against active coupons. Case-insensitive matching. Returns (True, coupon_data) if valid, (False, error_message) if not.
BEHAVIOR:
TESTS:
validate_coupon('SAVE10', [coupon_save10], '2025-01-15')[0] == Truevalidate_coupon('save10', [coupon_save10], '2025-01-15')[0] == True (case-insensitive)validate_coupon('INVALID', [coupon_save10], '2025-01-15')[0] == Falsevalidate_coupon('OLD', [expired_coupon], '2025-01-15')[0] == Falsevalidate_coupon('', [], '2025-01-15')[0] == FalseEDGE_CASES:
SIGNATURE: def check_free_shipping(subtotal: float, is_loyalty_member: bool, is_promo_period: bool = False) -> tuple[bool, str]
INTENT: Determines if an order qualifies for free shipping based on subtotal, loyalty status, and promotional period.
BEHAVIOR:
TESTS:
check_free_shipping(10.00, True) == (True, "Loyalty program member")check_free_shipping(50.00, False) == (True, "Order over $50")check_free_shipping(49.99, False) == (False, "Minimum not met")check_free_shipping(30.00, False, True) == (True, "Promotional free shipping")check_free_shipping(-1.00, False) raises ValueErrorEDGE_CASES: