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.
Write
class TestTopCustomers(unittest.TestCase)Rulespend is the sum of a customer's order totals; ties by
customer_id ascendingExampleorders C3: 60, C2: 50, C1: 30, C2: 10 →
top_customers(orders, 2) → ["C2", "C3"] (60 each, tie by ID)