fractus-vorax / tests /test_spawn.py
thefinalboss's picture
Fractus-Vorax v1.0.0 — the takeover: sealed CTE brain + ingestion organs + mechanical speech (199 tests, honest floors)
1da7ac7 verified
Raw
History Blame Contribute Delete
1.24 kB
# tests/test_spawn.py
from fractus_vorax.hv import bundle, hash_hv
from fractus_vorax.organs.spawn import ExpertRegistry
CAP_TOKENS = ["what", "is", "the", "capital", "of"]
BOOK_TOKENS = ["who", "wrote"]
def _sig(tokens, D=2048):
return bundle([hash_hv(t, D) for t in tokens])
def test_spawn_and_route():
reg = ExpertRegistry()
reg.spawn("capitals", _sig(CAP_TOKENS), 0, 4)
reg.spawn("books", _sig(BOOK_TOKENS), 5, 9)
assert len(reg) == 2
hits = reg.route(_sig(["what", "is", "the", "capital", "of", "germany"]))
assert hits[0][0] == "capitals"
assert hits[0][1] > 0.5
def test_route_empty():
assert ExpertRegistry().route(_sig(CAP_TOKENS)) == []
def test_get():
reg = ExpertRegistry()
e = reg.spawn("capitals", _sig(CAP_TOKENS), 0, 4)
assert reg.get("capitals") == e
assert reg.get("nope") is None
def test_save_load_roundtrip(tmp_path):
reg = ExpertRegistry()
reg.spawn("capitals", _sig(CAP_TOKENS), 0, 4)
reg.spawn("books", _sig(BOOK_TOKENS), 5, 9)
reg.save(tmp_path / "experts")
loaded = ExpertRegistry.load(tmp_path / "experts")
assert len(loaded) == 2
hits = loaded.route(_sig(["who", "wrote", "hamlet"]))
assert hits[0][0] == "books"