Download tests/test_math_adv.py from Upwork-AIML/Conditional_Causal_Difficulty_for_LLMs: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/Upwork-AIML/Conditional_Causal_Difficulty_for_LLMs/resolve/main/tests/test_math_adv.py
- Command line
-
hf download hf://Upwork-AIML/Conditional_Causal_Difficulty_for_LLMs/tests/test_math_adv.py
-
curl -L -o test_math_adv.py https://huggingface.co/Upwork-AIML/Conditional_Causal_Difficulty_for_LLMs/resolve/main/tests/test_math_adv.py
1.96 kB
| """Unit tests for MATH-Adv gold extraction and external complexity mapping.""" | |
| from __future__ import annotations | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) | |
| from causal_difficulty.llm_cache import ( | |
| answers_equal, | |
| extract_boxed, | |
| extract_gold_math, | |
| extract_pred_math, | |
| normalize_math_answer, | |
| validate_cached_response, | |
| ) | |
| from math_adv_pipeline import compute_complexity_from_levels, parse_level | |
| def test_extract_boxed_nested(): | |
| sol = r"Therefore $\boxed{\frac{1}{2}}$ is the answer." | |
| assert extract_boxed(sol) == r"\frac{1}{2}" | |
| def test_extract_gold_math_from_solution(): | |
| sol = ( | |
| "We compute step by step and conclude " | |
| r"$\boxed{2}$ vertical asymptotes." | |
| ) | |
| assert extract_gold_math(sol) == "2" | |
| def test_answers_equal_numeric_and_latex(): | |
| assert answers_equal("2", "2") | |
| assert answers_equal(" $2$ ", "2") | |
| assert not answers_equal("3", "2") | |
| def test_normalize_math_answer_strips_latex_spacing(): | |
| assert normalize_math_answer(r"\frac{1}{2}") == r"\frac{1}{2}" | |
| def test_parse_level_strings(): | |
| assert parse_level("Level 3") == 3 | |
| assert parse_level(4) == 4 | |
| def test_compute_complexity_from_levels(): | |
| scores = compute_complexity_from_levels([1, 3, 5]) | |
| assert scores[0] == 0.05 | |
| assert abs(scores[1] - 0.5) < 1e-9 | |
| assert abs(scores[2] - 0.95) < 1e-9 | |
| def test_extract_pred_math_prefers_answer_line(): | |
| text = "Work shown here.\nANSWER: 42" | |
| assert extract_pred_math(text) == "42" | |
| def test_extract_pred_math_falls_back_to_boxed(): | |
| text = r"Therefore the result is $\boxed{\frac{1}{2}}$." | |
| assert extract_pred_math(text) == r"\frac{1}{2}" | |
| def test_validate_competition_accepts_boxed_without_answer_line(): | |
| text = r"Long solution without ANSWER tag but with $\boxed{7}$ at end." | |
| ok, reason = validate_cached_response(text, style="competition") | |
| assert ok, reason | |