38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""T12 bench_tokens 实验脚本单测(封闭,本地确定性)。"""
|
|
import json
|
|
|
|
from scripts import bench_tokens as bt
|
|
|
|
|
|
def test_build_workspace_has_brief_and_progress():
|
|
ws = bt.build_workspace("写个快排", "code", n_steps=3, n_rounds=2)
|
|
b = ws.get("brief")
|
|
assert b["goal"] == "写个快排"
|
|
assert len(b["plan"]) == 3
|
|
done = [p for p in ws.get("progress", []) if p.get("status") == "done"]
|
|
assert len(done) >= 1
|
|
|
|
|
|
def test_measure_returns_all_keys():
|
|
ws = bt.build_workspace("解释注意力机制", "general", n_steps=3)
|
|
m = bt.measure(ws, n_steps=3)
|
|
for k in ("a1", "a2", "a3", "a4", "prefix_hit"):
|
|
assert k in m
|
|
assert m["a1"] > 0 and m["a2"] > 0
|
|
|
|
|
|
def test_a1_baseline_larger_than_a2_ws():
|
|
ws = bt.build_workspace("写个二分查找", "code", n_steps=3, n_rounds=2)
|
|
m = bt.measure(ws, n_steps=3)
|
|
assert m["a1"] > m["a2"]
|
|
|
|
|
|
def test_run_writes_files(tmp_path):
|
|
data = tmp_path / "d.json"
|
|
data.write_text(json.dumps([{"id": "x1", "query": "写个快排", "domain": "code"}]),
|
|
encoding="utf-8")
|
|
out = tmp_path / "exp"
|
|
bt.run(str(data), str(out), n_steps=2)
|
|
assert (out / "E1_token_economics.csv").exists()
|
|
assert (out / "E1_token_economics.md").exists()
|