Coupons take off too much and tax is calculated wrongly
Done- Plan (done)
- Code (done)
- Test (done)
- Review (done)
- Finish (done)
Cost
$0.0037
Tests
Passed
Iterations
1
Re-plans
0
LLM calls
11
Prompt read from cache
82%
Usage by agent
- Cache read
- Cache write
- Input
- Output
View as table
| Agent | Cost | Cache read | Cache write | Input | Output |
|---|---|---|---|---|---|
| planner | $0.0010 | 6,052 | 1,383 | 8 | 1,583 |
| coder | $0.0009 | 9,562 | 2,600 | 8 | 990 |
| tester | $0.0018 | 22,456 | 4,354 | 12 | 2,071 |
Timeline
-
planner iteration 1 Finished 3 calls · 9,026 tokens · $0.0010 · 10.2s
Loading…
-
coder iteration 1 Finished 3 calls · 13.2K tokens · $0.0009 · 7.6s
Loading…
-
tester iteration 1 Finished 5 calls · 28.9K tokens · $0.0018 · 18.8s
Loading…
-
verify iteration 1 Passed 0.5s
....... [100%] 7 passed in 0.02s
Final diff
diff --git a/checkout.py b/checkout.py index 2094fb6..b87dbc6 100644 --- a/checkout.py +++ b/checkout.py @@ -3,7 +3,5 @@ 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 = apply_discount(sum(prices), coupon_percent) + return round(subtotal + subtotal * TAX_RATE, 2) diff --git a/test_checkout.py b/test_checkout.py index ea5239f..314afa2 100644 --- a/test_checkout.py +++ b/test_checkout.py @@ -6,5 +6,29 @@ 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_full_coupon(): + assert order_total([10, 20], 100) == 0.0 + + +def test_discounted_subtotal_is_27_and_tax_is_2_70(): + total = order_total([10, 20], 10) + assert round(apply_discount(sum([10, 20]), 10), 2) == 27.00 + assert round(total - 27.00, 2) == 2.70 + + +def test_total_rounded_to_two_decimals(): + total = order_total([9.99], 15) + assert total == round(total, 2) + assert total == 9.34 + + +def test_zero_coupon_matches_no_coupon(): + assert order_total([10, 20], 0) == order_total([10, 20]) == 33.0 + + def test_apply_discount(): assert apply_discount(100, 25) == 75