Unit Test a Delivery Fee Calculator Around Its Boundaries
Last updated: November 29, 2026
Quick Overview
Given a delivery fee function with a base fee, a per-mile charge beyond three miles, a capped surge multiplier, a DashPass-style member waiver above a subtotal threshold and a small-order fee, write a focused unit test suite and fix any ambiguities you find.
DoorDash
November 29, 20260
0
0 solved
Given a delivery fee function with a base fee, a per-mile charge beyond three miles, a capped surge multiplier, a DashPass-style member waiver above a subtotal threshold and a small-order fee, write a focused unit test suite and fix any ambiguities you find.
DoorDash pricing logic changes often and bugs show up directly on customer receipts, so engineers are expected to test boundaries rigorously. This question checks whether you test thresholds on both sides, pin down rounding behavior, and treat ambiguous requirements as questions rather than guesses.
What the Interviewer Expects
- List each rule and test both sides of every threshold
- Pin down rounding with an explicit half-cent case
- Test invalid inputs and decide whether they raise
- Keep each test focused on one behavior with a descriptive name
- Point out ambiguities, such as whether members still pay the small-order fee
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you test this if surge came from a live service?
- Would you add property-based tests, and what property would you check?
- How would you catch a pricing regression before it reaches production?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- Base fee 299 cents; plus 50 cents per mile beyond 3 miles; times surge, capped at 2.0.
- Members pay no delivery fee when subtotal is at least 3500 cents.
- Subtotal under 1000 cents adds 200 cents....
High-Level Design
Write tests rule by rule. For each threshold (3 miles, 3500 cents for members, 1000 cents for the small-order fee, surge cap 2.0) test the exact boundary and one unit on the other side, because off-by...