File size: 824 Bytes
014b14c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""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