Files
troupe-standup/wizard-work/beam/test_robin_hood_hash.py
T
spark bfa590269c beam: Q76 -- median cells are collected by the lane gate, and CHECK is green unmasked
test_sliding_window_median.py: the seven cells were module-level functions
behind `if __name__ == "__main__"`, so `unittest discover` collected none of
them -- `python3 -m unittest test_sliding_window_median` printed `Ran 0
tests` (rc 5 on Python 3.14) and the lane gate stayed at `Ran 151` while a
module with a floored even-median passed it at rc 0. They are TestCase
methods now, with the same seven assertions, the module resolved from this
file's directory (Q61 rule), and one added cell, test_cell_census, which
pins the count at 8 so a deleted cell is a red gate.

test_robin_hood_hash.py: `sys.path.insert(0, "/root/.hermes/wizard-outputs
/beam")` -> `str(pathlib.Path(__file__).resolve().parent)`. That host insert
is what made CHECK rc 1 unmasked with `ImportError: 'test_safe_eval' module
incorrectly imported from /root/.hermes/wizard-outputs/beam`.

Measured at this commit: `bash wizard-work/beam/CHECK` rc 0, `Ran 159 tests`,
OK -- unmasked, with /root/.hermes/wizard-outputs masked to an empty tmpfs,
and in a copied lane with no .git. 151 + 8 = 159. Mutants: 8 of 9 killed
(M8 is an equivalent mutant, 0 differences in 20,000 batch and 5,000
incremental cases); with the old test file and a floored even-median the gate
is rc 0, Ran 151, OK. Record: wizard-work/volt/q76-2026-10-26.md.
2026-10-26 11:18:04 +00:00

37 lines
1.3 KiB
Python

import pathlib, random, sys
# Q76 / 2026-10-26: resolve robin_hood_hash from THIS file's directory and from
# nowhere else (Q61 / test_toposort.py rule). This line used to read
# sys.path.insert(0, "/root/.hermes/wizard-outputs/beam"), which put a HOST
# directory first on sys.path for the whole `unittest discover` process; that is
# what made this lane's CHECK rc 1 with
# ImportError: 'test_safe_eval' module incorrectly imported from
# '/root/.hermes/wizard-outputs/beam'. Expected '.../wizard-work/beam'.
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from robin_hood_hash import RobinHoodHash
for trial in range(300):
r = RobinHoodHash(8)
d = {}
keys = [random.randint(0, 50) for _ in range(60)]
for k in keys:
r[k] = k*7+1
d[k] = k*7+1
for k in keys[::3]:
if k in d:
del r[k]; del d[k]
for k in list(d)[:5]:
r[k] = -1; d[k] = -1
assert len(r) == len(d), (len(r), len(d), trial)
for k in d:
assert r[k] == d[k], (k, r[k], d[k], trial)
for k in range(60):
assert (k in r) == (k in d), (k, trial)
assert sorted(r.items()) == sorted(d.items()), trial
try:
del r[99999]
raise SystemExit("no raise trial %d" % trial)
except KeyError:
pass
print("ALL 300 RANDOM TRIALS PASS")