Download tests/test_math_grade.py from 42e/mathcompose: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/42e/mathcompose/resolve/main/tests/test_math_grade.py
- Command line
-
hf download hf://42e/mathcompose/tests/test_math_grade.py
-
curl -L -o test_math_grade.py https://huggingface.co/42e/mathcompose/resolve/main/tests/test_math_grade.py
1.37 kB
| """Smoke #2 (boxed parser) + #4 (answer grader).""" | |
| from mathcompose.common.math_grade import ( | |
| extract_boxed_int, extract_last_boxed, grade_answer, normalize_problem_text, | |
| ) | |
| def test_boxed_int(): | |
| assert extract_boxed_int(r"blah \boxed{-1}") == -1 | |
| assert extract_boxed_int(r"...\boxed{3}") == 3 | |
| assert extract_boxed_int(r"Verdict... \boxed{ 12 }") == 12 | |
| assert extract_boxed_int(r"\boxed{\text{-1}}") == -1 | |
| assert extract_boxed_int("no box; first error at step 5") == 5 | |
| assert extract_boxed_int("nothing here") is None | |
| def test_last_boxed_nested(): | |
| assert extract_last_boxed(r"\boxed{\frac{1}{2}}") == r"\frac{1}{2}" | |
| assert extract_last_boxed(r"\boxed{1} then \boxed{2}") == "2" | |
| def test_grade_answer_equivalence(): | |
| assert grade_answer("42", "42") | |
| assert grade_answer(r"\frac{1}{2}", "0.5") | |
| assert grade_answer(r"\frac{1}{2}", r"\frac{2}{4}") | |
| assert grade_answer(r"\sqrt{2}", "1.41421356") | |
| assert grade_answer("1,000", "1000") | |
| assert grade_answer("x+1", "1+x") | |
| assert grade_answer(r"2\pi", "6.283185307") | |
| def test_grade_answer_rejects(): | |
| assert not grade_answer("3", "4") | |
| assert not grade_answer(r"\frac{1}{3}", "0.33") | |
| assert not grade_answer(None, "4") | |
| def test_problem_normalization(): | |
| assert normalize_problem_text("What is $1+1$?") == normalize_problem_text("what is 1 + 1 ?") | |