runtime
249 / 500
question 249 Testing & Code Quality · medium

Edge cases for the top customers

top_customers(orders, n) returns the IDs of the n customers who spent the most, highest first; customers with equal spend are listed by ID; asking for more customers than exist returns all of them; n of 0 gives []; a negative n is a ValueError; and the orders list must not change. The function is correct. Write TestTopCustomers to catch broken versions.

Writeclass TestTopCustomers(unittest.TestCase)
Rulespend is the sum of a customer's order totals; ties by customer_id ascending
Exampleorders C3: 60, C2: 50, C1: 30, C2: 10 → top_customers(orders, 2) → ["C2", "C3"] (60 each, tie by ID)

Loading your progress…

Edge cases for the top customers — Python practice · Runtime