1005 B
1005 B
STATUS — eval phase
Claimed gates: D1, D2, D3, D4, D5
Verify commands (cold, run from repo root)
python -m unittest -q
python calc.py "2+3*4"
python calc.py "(2+3)*4"
python calc.py "7/2"
python calc.py "4/2"
python calc.py "1/0" # error to stderr, exit 1
python calc.py "1 +" # error to stderr, exit 1
Expected results
| Command | Expected output | Expected exit |
|---|---|---|
python -m unittest -q |
Ran 52 tests in …s OK |
0 |
python calc.py "2+3*4" |
14 |
0 |
python calc.py "(2+3)*4" |
20 |
0 |
python calc.py "7/2" |
3.5 |
0 |
python calc.py "4/2" |
2 |
0 |
python calc.py "1/0" |
error: division by zero (stderr) |
1 |
python calc.py "1 +" |
error: … (stderr) |
1 |
Files added
calc/evaluator.py—evaluate(node)walker +EvalErrorcalc/test_evaluator.py— 18 unittest cases covering D1–D3calc.py— CLI entry point (D4)
Commit SHA
3ff8ae9