按任务包规范组织文件,并记录与精确版本对应的证据。
选择一项能独立核算的科学计算。本例借鉴 Terminal-Bench-Science 的数值计算形式,使用虚构的质量和体积读数。Terminal-Bench-Science 0.1
编写与验证
运行前写清单位、空白校正、输出字段和绝对容差。独立核算出预期值,避免沿用解题代码。第 1 层程序化验证器检查数值有限、单位一致且误差在容差内。先由领域人员审阅方法的含义,再由程序评定结果。
校准与修正
运行参考实现,并用省略空白扣除的结果作对照。在私有证据中记录参考计算和选择容差的依据。超出容差记为检查失败,运行器不可用记为基础设施错误。如果无效结果被接受,修正检查后,用相同用例重跑前后两个版本。
可运行示例
用 Python 3.12 运行。从 7 mg 读数中扣除 1 mg 空白,再除以 3 mL。参考计算应通过,漏扣空白或单位错误的结果应失败。
python3.12 - <<'PY'
from decimal import Decimal
reading, blank, volume = map(Decimal, ("7", "1", "3"))
expected = Decimal("2.00") # independent reference: 6 mg / 3 mL
tolerance = Decimal("0.05")
def passes(value, unit):
return unit == "mg/mL" and value.is_finite() and abs(value - expected) <= tolerance
assert passes((reading - blank) / volume, "mg/mL")
assert not passes(reading / volume, "mg/mL")
assert not passes(expected, "g/mL")
assert not passes(Decimal("NaN"), "mg/mL")
print("reference pass, uncorrected, wrong unit and non-finite values fail")
PY在任务包内,把独立答案和容差检查放入验证器。记录误差及其单位,方便后来比较不同版本。