Division by zero crashes
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
75%
Usage by agent
- Cache read
- Cache write
- Input
- Output
View as table
| Agent | Cost | Cache read | Cache write | Input | Output |
|---|---|---|---|---|---|
| planner | $0.0009 | 6,019 | 1,440 | 8 | 1,249 |
| coder | $0.0009 | 9,379 | 2,634 | 8 | 1,026 |
| tester | $0.0012 | 11,083 | 3,737 | 8 | 1,309 |
| reviewer | $0.0007 | 5,295 | 2,761 | 6 | 584 |
Timeline
-
planner iteration 1 Finished 3 calls · 8,716 tokens · $0.0009 · 7.7s
Loading…
-
coder iteration 1 Finished 3 calls · 13.0K tokens · $0.0009 · 8.2s
Loading…
-
tester iteration 1 Finished 3 calls · 16.1K tokens · $0.0012 · 8.4s
Loading…
-
verify iteration 1 Passed 0.6s
............ [100%] 12 passed in 0.07s
-
reviewer iteration 1 Finished 2 calls · 8,646 tokens · $0.0007 · 4.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..e1a274e 100644 --- a/test_calc.py +++ b/test_calc.py @@ -23,3 +23,35 @@ def test_main_prints_result(capsys): def test_main_reports_unknown_operator(capsys): assert main(["1", "%", "2"]) == 1 assert "unknown operator" in capsys.readouterr().err + + +@pytest.mark.parametrize("right", [0, 0.0, -0.0]) +def test_division_by_zero_raises(right): + with pytest.raises(CalculatorError, match="division by zero"): + calculate(1, "/", right) + + +def test_main_reports_division_by_zero(capsys): + assert main(["1", "/", "0"]) == 1 + captured = capsys.readouterr() + assert "division by zero" in captured.err + assert "Traceback" not in captured.err + assert captured.out == "" + + +def test_cli_division_by_zero_exits_with_status_1(): + import subprocess + import sys + from pathlib import Path + + script = Path(__file__).parent / "calc.py" + proc = subprocess.run( + [sys.executable, str(script), "1", "/", "0"], + capture_output=True, + text=True, + check=False, + ) + assert proc.returncode == 1 + assert "division by zero" in proc.stderr + assert "Traceback" not in proc.stderr + assert proc.stdout == ""