division by zero crashes
Done- Plan (done)
- Code (done)
- Test (done)
- Review (done)
- Finish (done)
Cost
$0.0048
Tests
Passed
Iterations
1
Re-plans
0
LLM calls
13
Prompt read from cache
63%
Usage by agent
- Cache read
- Cache write
- Input
- Output
View as table
| Agent | Cost | Cache read | Cache write | Input | Output |
|---|---|---|---|---|---|
| planner | $0.0010 | 3,867 | 3,002 | 8 | 1,092 |
| coder | $0.0012 | 11,364 | 4,605 | 10 | 933 |
| tester | $0.0017 | 13,687 | 6,076 | 10 | 1,702 |
| reviewer | $0.0010 | 3,451 | 4,963 | 6 | 610 |
Timeline
-
planner iteration 1 Finished 3 calls · 7,969 tokens · $0.0010 · 11.4s
Loading…
-
coder iteration 1 Finished 4 calls · 16.9K tokens · $0.0012 · 7.3s
Loading…
-
tester iteration 1 Finished 4 calls · 21.5K tokens · $0.0017 · 14.9s
Loading…
-
verify iteration 1 Passed 0.5s
.............. [100%] 14 passed in 0.02s
-
reviewer iteration 1 Finished 2 calls · 9,030 tokens · $0.0010 · 9.1s
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..9930cb5 100644 --- a/test_calc.py +++ b/test_calc.py @@ -23,3 +23,31 @@ 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(("left", "right"), [(1, 0), (0, 0)]) +def test_division_by_zero_raises(left, right): + with pytest.raises(CalculatorError, match="division by zero"): + calculate(left, "/", right) + + +def test_main_reports_division_by_zero(capsys): + assert main(["1", "/", "0"]) == 1 + assert "division by zero" in capsys.readouterr().err + + +@pytest.mark.parametrize("right", [-0.0, 0.0]) +def test_division_by_negative_or_positive_zero_raises(right): + with pytest.raises(CalculatorError, match="division by zero"): + calculate(5, "/", right) + + +def test_main_reports_division_by_zero_float_spelling(capsys): + assert main(["1", "/", "0.0"]) == 1 + captured = capsys.readouterr() + assert "division by zero" in captured.err + assert "Traceback" not in captured.err + + +def test_division_by_tiny_nonzero_still_divides(): + assert calculate(1, "/", 1e-300) == pytest.approx(1e300)