division by zero crashes.
Done- Plan (done)
- Code (done)
- Test (done)
- Review (done)
- Finish (done)
Cost
$0.0042
Tests
Passed
Iterations
1
Re-plans
0
LLM calls
13
Prompt read from cache
79%
Usage by agent
- Cache read
- Cache write
- Input
- Output
View as table
| Agent | Cost | Cache read | Cache write | Input | Output |
|---|---|---|---|---|---|
| planner | $0.0010 | 5,779 | 1,510 | 8 | 1,469 |
| coder | $0.0010 | 14,491 | 2,731 | 10 | 1,067 |
| tester | $0.0016 | 17,272 | 4,358 | 10 | 1,676 |
| reviewer | $0.0007 | 5,342 | 2,507 | 6 | 601 |
Timeline
-
planner iteration 1 Finished 3 calls · 8,766 tokens · $0.0010 · 11.9s
Loading…
-
coder iteration 1 Finished 4 calls · 18.3K tokens · $0.0010 · 7.5s
Loading…
-
tester iteration 1 Finished 4 calls · 23.3K tokens · $0.0016 · 12.7s
Loading…
-
verify iteration 1 Passed 0.5s
............... [100%] 15 passed in 0.03s
-
reviewer iteration 1 Finished 2 calls · 8,456 tokens · $0.0007 · 9.0s
Loading…
Final diff
diff --git a/calc.py b/calc.py index f16c6ca..b7d522d 100644 --- a/calc.py +++ b/calc.py @@ -15,6 +15,8 @@ def calculate(left: float, operator: str, right: float) -> float: if operator == "*": return left * right if operator == "/": + if right == 0: + raise CalculatorError("division by zero") return left / right raise CalculatorError(f"unknown operator: {operator}") diff --git a/test_calc.py b/test_calc.py index 856b0c9..4bfea70 100644 --- a/test_calc.py +++ b/test_calc.py @@ -15,6 +15,32 @@ def test_unknown_operator(): calculate(1, "%", 2) +@pytest.mark.parametrize("right", [0, 0.0, -0.0]) +def test_division_by_zero(right): + with pytest.raises(CalculatorError, match="division by zero"): + calculate(8, "/", right) + + +def test_main_reports_division_by_zero(capsys): + assert main(["1", "/", "0"]) == 1 + captured = capsys.readouterr() + assert captured.out == "" + assert "division by zero" in captured.err + assert "Traceback" not in captured.err + + +def test_main_division_by_zero_exact_message(capsys): + assert main(["8", "/", "0.0"]) == 1 + assert capsys.readouterr().err == "error: division by zero\n" + + +@pytest.mark.parametrize( + ("operator", "expected"), [("+", 1), ("-", 1), ("*", 0)] +) +def test_zero_right_operand_ok_for_other_operators(operator, expected): + assert calculate(1, operator, 0) == expected + + def test_main_prints_result(capsys): assert main(["8", "/", "2"]) == 0 assert capsys.readouterr().out.strip() == "4.0"