1from wp30.scoring import numeric_match, yesno_match, is_abstention, qa_f1, score_synthetic, extract_numbers2from wp30.data.synthetic import generate_document3from wp30.data.exec_tasks import generate_exec_task, run_hidden_tests45def test_numeric():6 assert numeric_match("3,907,415 CAD", "3,907,415") == 1.07 assert numeric_match("The budget is 3907415.", "3,907,415") == 1.08 assert numeric_match("3,907,414", "3,907,415") == 0.09 assert numeric_match("1900.0", "1900", 1e-6) == 1.010 assert extract_numbers("ZR-77Q-0931 and 4,381,220") == [77.0, 931.0, 4381220.0] or 4381220.0 in extract_numbers("ZR-77Q-0931 and 4,381,220")1112def test_yesno_and_abstain():13 assert yesno_match("No, it was postponed.", "no") == 1.0 and yesno_match("Yes", "no") == 0.014 assert is_abstention("unknown") and is_abstention("The document does not say.") and not is_abstention("ZR-77Q-0931")1516def test_synthetic_deterministic_and_answerable():17 a = generate_document(5, 6, 2000); b = generate_document(5, 6, 2000)18 assert a["text"] == b["text"] and len(a["questions"]) == 1519 for q in a["questions"]:20 if q["answer_type"] in ("exact",):21 assert q["answer"] in a["text"] or any(al in a["text"] for al in q["aliases"]) or q["qtype"] == "temporal"2223def test_exec_reference_passes_and_wrong_fails():24 t = generate_exec_task(3)25 assert run_hidden_tests(t["questions"][0]["answer"], t["hidden_tests"])["correct"] == 1.026 assert run_hidden_tests("def net_revenue(rows):\n return 1.0", t["hidden_tests"])["correct"] == 0.02728def test_f1_normalization():29 assert qa_f1("The GhostVLAD pooling", ["GhostVLAD pooling"]) == 1.030