Coupons take off too much and tax is calculated wrongly
Done- Plan (done)
- Code (done)
- Test (done)
- Review (done)
- Finish (done)
Cost
$0.0046
Tests
Passed
Iterations
1
Re-plans
0
LLM calls
12
Prompt read from cache
76%
Usage by agent
- Cache read
- Cache write
- Input
- Output
View as table
| Agent | Cost | Cache read | Cache write | Input | Output |
|---|---|---|---|---|---|
| planner | $0.0011 | 6,056 | 1,385 | 8 | 1,819 |
| coder | $0.0013 | 13,821 | 3,002 | 10 | 1,551 |
| tester | $0.0012 | 11,253 | 3,563 | 8 | 1,269 |
| reviewer | $0.0009 | 5,498 | 3,519 | 6 | 887 |
Timeline
-
planner iteration 1 Finished 3 calls · 9,268 tokens · $0.0011 · 11.0s
Loading…
-
coder iteration 1 Finished 4 calls · 18.4K tokens · $0.0013 · 9.5s
Loading…
-
tester iteration 1 Finished 3 calls · 16.1K tokens · $0.0012 · 9.9s
Loading…
-
verify iteration 1 Passed 0.5s
...... [100%] 6 passed in 0.01s
-
reviewer iteration 1 Finished 2 calls · 9,910 tokens · $0.0009 · 5.4s
Loading…
Final diff
diff --git a/checkout.py b/checkout.py index 2094fb6..0dcbbbd 100644 --- a/checkout.py +++ b/checkout.py @@ -3,7 +3,6 @@ from pricing import apply_discount def order_total(prices: list[float], coupon_percent: float = 0) -> float: - undiscounted = sum(prices) - subtotal = sum(apply_discount(price, coupon_percent) for price in prices) - subtotal = apply_discount(subtotal, coupon_percent) - return round(subtotal + undiscounted * TAX_RATE, 2) + subtotal = round(apply_discount(sum(prices), coupon_percent), 2) + tax = subtotal * TAX_RATE + return round(subtotal + tax, 2) diff --git a/test_checkout.py b/test_checkout.py index ea5239f..d617191 100644 --- a/test_checkout.py +++ b/test_checkout.py @@ -6,5 +6,23 @@ def test_no_coupon(): assert order_total([10, 20]) == 33.0 +def test_coupon_applied_once_and_tax_on_discounted_subtotal(): + assert order_total([10, 20], 10) == 29.70 + + +def test_coupon_not_applied_twice_and_tax_on_discounted_subtotal(): + subtotal = apply_discount(30, 10) + assert round(subtotal, 2) == 27.00 + assert round(order_total([10, 20], 10) - subtotal, 2) == 2.70 + + +def test_zero_coupon_equals_no_coupon(): + assert order_total([10, 20], 0) == order_total([10, 20]) + + +def test_empty_order(): + assert order_total([]) == 0.0 + + def test_apply_discount(): assert apply_discount(100, 25) == 75