1.7 KiB
1.7 KiB
STATUS — phase eval
Commit: c5e74ed
Gates
D1 — arithmetic
Checks: evaluate(parse(tokenize(s))) for +, -, *, /, precedence, parens, unary minus.
| Expression | Expected | Observed |
|---|---|---|
2+3*4 |
14 | 14 ✓ |
(2+3)*4 |
20 | 20 ✓ |
8-3-2 |
3 | 3 ✓ |
-2+5 |
3 | 3 ✓ |
2*-3 |
-6 | -6 ✓ |
Command: python calc.py "2+3*4" etc.
Status: PASS
D2 — division
True division: python calc.py "7/2" → 3.5 ✓
EvalError on div-by-zero:
$ python calc.py "1/0"; echo "exit: $?"
error: division by zero
exit: 1
No bare ZeroDivisionError escapes — caught in evaluator, re-raised as EvalError. ✓
Status: PASS
D3 — result type
Rule: whole-valued float prints without .0; non-whole prints as float.
$ python calc.py "4/2" → 2
$ python calc.py "7/2" → 3.5
_fmt() in calc.py checks isinstance(val, float) and val.is_integer() and converts to int for display. ✓
Status: PASS
D4 — CLI
$ python calc.py "2+3*4"
14
exit: 0
$ python calc.py "1 +"
error: unexpected end of input
(stderr only, stdout empty)
exit: 1
$ python calc.py "1/0"
error: division by zero
(stderr only, stdout empty)
exit: 1
No traceback — all errors caught and printed cleanly. ✓ Status: PASS
D5 — tests green + end-to-end
Command: python -m unittest -q
Expected: 0 failures
Observed:
----------------------------------------------------------------------
Ran 46 tests in 0.001s
OK
Prior lex + parse suites still pass (no regression). 46 = 13 lex + 15 parse + 18 eval. ✓ Status: PASS