An extraction that passed the tests

In Python, a developer refactors this checkout function:


Python
def checkout(items, coupon):
    total = 0
    for item in items:
        total += item.price
    if coupon:
        total -= 5
    tax = total * 0.13
    return total + tax


into this version:


Python
def apply_coupon(total, coupon):
    if coupon:
        total -= 5

def checkout(items, coupon):
    total = 0
    for item in items:
        total += item.price
    apply_coupon(total, coupon)
    tax = total * 0.13
    return total + tax


Every existing test calls checkout with coupon=False, and all of them pass. Consider a customer whose item prices sum to 40.00 dollars and who uses a coupon. Ignoring floating-point rounding, which statement is accurate?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Refactoring Questions: