Two test cells opened with sys.path.insert(0, /root/.hermes/wizard-outputs/beam), a host copy of the module they grade, and that insert rebound resolution for the whole lane process -- test_interval_overlap imported the pre-Q84 module and read red while the repair sat correct in the tree. Each cell now binds Path(__file__).resolve().parent and asserts the import landed there. New instrument: q133_verify.py behind CHECK-q133 (5 legs) and q133_oracle.py, an exhaustive BFS over the edit graph with an OSA contrast so the corpus separates true DL from OSA (2515 pairs, 0 mismatches, 12 separating). verify.py: 10 legs, 10 pass, 0 fault. beam/CHECK: 595 tests, 0 failures.
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
"""Cells for wizard-work/beam/expr_eval.py -- graded by beam/CHECK.
|
|
|
|
Binding (Q133, 2026-10-31): shipped as `sys.path.insert(0, '/root/.hermes/...')`,
|
|
an absolute path to a *host copy* of the module. It graded whatever sat there,
|
|
and worse, it put that directory at sys.path[0] for the whole lane process --
|
|
`test_interval_overlap.py` then imported the host's pre-Q84 `interval_overlap`,
|
|
so two cells written for the repaired module read red while the repair was
|
|
present and correct in this tree. The cell now imports the module beside it
|
|
and asserts that it did.
|
|
"""
|
|
import math
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(HERE))
|
|
|
|
import expr_eval as _exprmod # noqa: E402
|
|
from expr_eval import evaluate, EvalError # noqa: E402
|
|
|
|
assert Path(_exprmod.__file__).resolve().parent == HERE, _exprmod.__file__
|
|
|
|
cases = [
|
|
("2+3*4", 14.0),
|
|
("(2+3)*4", 20.0),
|
|
("2**3**2", 512.0), # right assoc
|
|
("10 // 3", 3.0),
|
|
("10 % 3", 1.0),
|
|
("-5 + 2", -3.0),
|
|
("2*-3", -6.0),
|
|
("sqrt(16)+abs(-2)", 6.0),
|
|
("max(1,5,2)", 5.0),
|
|
("sin(0)", 0.0),
|
|
("2**0.5", math.sqrt(2)),
|
|
("1e3 + 0.5", 1000.5),
|
|
]
|
|
for expr, exp in cases:
|
|
got = evaluate(expr)
|
|
assert got == exp, (expr, got, exp)
|
|
print("OK", expr, got)
|
|
|
|
# variables
|
|
assert evaluate("x*2 + pi", {'x': 4, 'pi': math.pi}) == 8 + math.pi
|
|
# errors
|
|
for bad in ["2 +", "foo", "1/0", "sin(1,2)", "2 **", "abc("]:
|
|
try:
|
|
evaluate(bad)
|
|
print("FAIL no error:", bad)
|
|
sys.exit(1)
|
|
except EvalError as e:
|
|
print("ERR ok:", bad, "->", e)
|
|
print("ALL PASS")
|