division by zero crashes

Done

examples/buggy_calc · 2026-11-09 14:55:40 UTC · took 12.0s

  1. Plan (done)
  2. Code (done)
  3. Test (done)
  4. Review (done)
  5. Finish (done)
Cost
$0.0011
Tests
Not run
Iterations
0
Re-plans
0
LLM calls
4
Prompt read from cache
66%

Usage by agent

Cost per agent
coder: $0.0011 coder coder, Cost: $0.0011 $0.0011
Tokens per agent
  • Cache read
  • Cache write
  • Input
  • Output
coder: 13.8K coder coder, Cache read: 8,444 coder, Cache write: 4,267 coder, Output: 1,029 13.8K
View as table
AgentCostCache readCache writeInputOutput
coder$0.00118,4444,267101,029

Timeline

  1. 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"