from __future__ import annotations import importlib.util import sys from pathlib import Path import numpy as np import pandas as pd spec = importlib.util.spec_from_file_location("s16", Path(__file__).parents[1] / "scripts/16_m34_session.py") sys.path.insert(0, str(Path(__file__).parents[1] / "scripts")) s16 = importlib.util.module_from_spec(spec) spec.loader.exec_module(s16) def pool(): fams = ["lookup"] * 40 + ["aggregation"] * 30 + ["multi_hop"] * 5 return [{"id": str(i), "family": f, "well": f"W{i % 4}", "scope": "well"} for i, f in enumerate(fams)] def test_count_reads_the_leading_number(): assert s16.count("300 from the C4-paired set") == 300 and s16.count(500) == 500 def test_question_draw_is_deterministic_spread_over_families_and_wells(): a = s16.draw_questions(pool(), {"questions": 30}, np.random.default_rng(1)) b = s16.draw_questions(pool(), {"questions": 30}, np.random.default_rng(1)) assert [q["id"] for q in a] == [q["id"] for q in b] and len({q["id"] for q in a}) == 30 assert {q["family"] for q in a} == {"lookup", "aggregation", "multi_hop"} assert len({q["well"] for q in a}) == 4 def test_t2_draw_is_stratified_by_well(): frame = pd.DataFrame({"item": [str(i) for i in range(1000)], "well": ["A"] * 700 + ["B"] * 300}) out = s16.draw_t2(frame, 100, np.random.default_rng(2)) assert len(out) == 100 and out["well"].value_counts().to_dict() == {"A": 70, "B": 30}