| | from pathlib import Path |
| | import sys |
| |
|
| |
|
| | ROOT = Path(__file__).resolve().parents[1] |
| | if str(ROOT) not in sys.path: |
| | sys.path.insert(0, str(ROOT)) |
| |
|
| | from eval_utils import grade_response, parse_valid_options |
| |
|
| |
|
| | def test_mcq_extract_standard_answer_marker(): |
| | question = "A. Red\nB. Blue\nC. Green\nD. Purple\nAnswer in format **Answer:X**." |
| | response = "**Answer:C**" |
| | graded = grade_response(question, "c", response) |
| | assert graded["task_type"] == "mcq" |
| | assert graded["pred"] == "c" |
| | assert graded["extract_ok"] is True |
| | assert graded["correct"] is True |
| |
|
| |
|
| | def test_mcq_extract_supports_a_to_f(): |
| | question = "A. Red\nB. Blue\nC. Green\nD. Purple\nE. Pink\nF. Orange\nAnswer in format **Answer:X**." |
| | response = "Final answer is F" |
| | graded = grade_response(question, "f", response) |
| | assert graded["pred"] == "f" |
| | assert graded["correct"] is True |
| |
|
| |
|
| | def test_mcq_extract_from_long_reasoning_tail_option(): |
| | question = "Options are A, B, C, and D." |
| | response = "I compared all paths. The best match is Option B." |
| | graded = grade_response(question, "b", response) |
| | assert graded["pred"] == "b" |
| | assert graded["correct"] is True |
| |
|
| |
|
| | def test_mcq_parse_options_from_list_sentence(): |
| | opts = parse_valid_options("The choices are A, B, C, and D.") |
| | assert opts == {"A", "B", "C", "D"} |
| |
|
| |
|
| | def test_mcq_parse_options_from_slash_sentence(): |
| | opts = parse_valid_options("Pick from A/B/C/D.") |
| | assert opts == {"A", "B", "C", "D"} |
| |
|
| |
|
| | def test_mcq_invalid_option_not_in_question_choices(): |
| | question = "A. First\nB. Second\nC. Third\nD. Fourth" |
| | response = "**Answer:E**" |
| | graded = grade_response(question, "d", response) |
| | assert graded["pred"] == "" |
| | assert graded["extract_ok"] is False |
| | assert graded["correct"] is False |
| |
|
| |
|
| | def test_fill_extract_standard_marker(): |
| | question = "Please report the full word. Answer in format **Answer:WORD**." |
| | response = "**Answer:UNPROVERBIAL**" |
| | graded = grade_response(question, "UNPROVERBIAL", response) |
| | assert graded["task_type"] == "fill_blank" |
| | assert graded["pred"] == "UNPROVERBIAL" |
| | assert graded["pred_norm"] == "unproverbial" |
| | assert graded["correct"] is True |
| |
|
| |
|
| | def test_fill_extract_trailing_punctuation(): |
| | question = "Please report the full word. Answer in format **Answer:WORD**." |
| | response = "Answer: unproverbial." |
| | graded = grade_response(question, "UNPROVERBIAL", response) |
| | assert graded["pred_norm"] == "unproverbial" |
| | assert graded["correct"] is True |
| |
|
| |
|
| | def test_fill_extract_with_quotes(): |
| | question = "Please report the full word. Answer in format **Answer:WORD**." |
| | response = "Final answer: “UNPROVERBIAL”" |
| | graded = grade_response(question, "UNPROVERBIAL", response) |
| | assert graded["pred_norm"] == "unproverbial" |
| | assert graded["correct"] is True |
| |
|
| |
|
| | def test_fill_normalization_case_spaces_fullwidth(): |
| | question = "Please report the full word. Answer in format **Answer:WORD**." |
| | response = "Answer: UNPROVERBIAL " |
| | graded = grade_response(question, "unproverbial", response) |
| | assert graded["pred_norm"] == "unproverbial" |
| | assert graded["answer_norm"] == "unproverbial" |
| | assert graded["correct"] is True |
| |
|
| |
|
| | def test_fill_wrong_spelling_is_not_correct(): |
| | question = "Please report the full word. Answer in format **Answer:WORD**." |
| | response = "Answer: UNPROVERBIA" |
| | graded = grade_response(question, "UNPROVERBIAL", response) |
| | assert graded["pred_norm"] == "unproverbia" |
| | assert graded["correct"] is False |
| |
|
| |
|