"""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")