"""Maj@k index voting + solution-level p_correct.""" from mathcompose.eval.parse import first_error_index, majority_index, p_correct_from_samples, PARSE_FAIL def test_first_error_index(): assert first_error_index(r"\boxed{4}") == 4 assert first_error_index(r"\boxed{-1}") == -1 assert first_error_index("junk") == PARSE_FAIL def test_majority_index_drops_failures_and_breaks_ties_low(): assert majority_index([r"\boxed{2}", r"\boxed{2}", r"\boxed{3}", "junk"]) == 2 # tie between 2 and 3 -> earliest (2) assert majority_index([r"\boxed{2}", r"\boxed{3}"]) == 2 assert majority_index(["junk", "more junk"]) == PARSE_FAIL def test_p_correct(): assert p_correct_from_samples([r"\boxed{-1}", r"\boxed{-1}", r"\boxed{4}", r"\boxed{-1}"]) == 0.75 assert p_correct_from_samples([]) == 0.0