division by zero crashes
Done- Plan (done)
- Code (done)
- Test (done)
- Review (done)
- Finish (done)
Cost
$0.0011
Tests
Not run
Iterations
0
Re-plans
0
LLM calls
4
Prompt read from cache
66%
Usage by agent
- Cache read
- Cache write
- Input
- Output
View as table
| Agent | Cost | Cache read | Cache write | Input | Output |
|---|---|---|---|---|---|
| coder | $0.0011 | 8,444 | 4,267 | 10 | 1,029 |
Timeline
-
coder iteration 0 Finished 4 calls · 13.8K tokens · $0.0011 · 10.8s
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..d48acb7 100644 --- a/test_calc.py +++ b/test_calc.py @@ -15,6 +15,16 @@ def test_unknown_operator(): calculate(1, "%", 2) +def test_division_by_zero(): + with pytest.raises(CalculatorError, match="division by zero"): + calculate(1, "/", 0) + + +def test_main_reports_division_by_zero(capsys): + assert main(["1", "/", "0"]) == 1 + assert "division by zero" in capsys.readouterr().err + + def test_main_prints_result(capsys): assert main(["8", "/", "2"]) == 0 assert capsys.readouterr().out.strip() == "4.0"