|
| 1 | +import pytest |
| 2 | + |
| 3 | +from skythought.evals.tasks.mmlu.mmlu_handler import MMLUProTaskHandler |
| 4 | + |
| 5 | + |
| 6 | +class MockTaskConfig: |
| 7 | + templating_parameters = {"template": "Question: {question}\n\nChoices:\n{choices}"} |
| 8 | + answer_key = "answer" |
| 9 | + question_key = "question" |
| 10 | + choices_key = "choices" |
| 11 | + context_key = "context" |
| 12 | + |
| 13 | + |
| 14 | +@pytest.mark.parametrize( |
| 15 | + "problem, response, expected", |
| 16 | + [ |
| 17 | + ( |
| 18 | + { |
| 19 | + "question": "What is the main function of the left ventricle?", |
| 20 | + "choices": "A) Pumps blood to the lungs\nB) Pumps blood to the body\nC) Collects blood from the body\nD) Stores blood", |
| 21 | + "answer": "B", |
| 22 | + "answer_index": 1, |
| 23 | + }, |
| 24 | + "B) Pumps blood to the body", |
| 25 | + True, |
| 26 | + ), |
| 27 | + ( |
| 28 | + { |
| 29 | + "question": "What does GDP stand for?", |
| 30 | + "choices": "A) Gross Domestic Product\nB) General Development Plan\nC) Global Distribution Process\nD) Geographic Data Point", |
| 31 | + "answer": "A", |
| 32 | + "answer_index": 0, |
| 33 | + }, |
| 34 | + "I think it's B", |
| 35 | + False, |
| 36 | + ), |
| 37 | + ], |
| 38 | +) |
| 39 | +def test_check_correctness(problem, response, expected): |
| 40 | + handler = MMLUProTaskHandler(task_config=MockTaskConfig) |
| 41 | + assert handler.check_correctness(problem, generation=response) == expected |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.parametrize( |
| 45 | + "problem, expected", |
| 46 | + [ |
| 47 | + ( |
| 48 | + { |
| 49 | + "question": "What is the main function of the left ventricle?", |
| 50 | + "choices": "A) Pumps blood to the lungs\nB) Pumps blood to the body\nC) Collects blood from the body\nD) Stores blood", |
| 51 | + "answer": "B", |
| 52 | + "answer_index": 1, |
| 53 | + }, |
| 54 | + "Question: What is the main function of the left ventricle?\n\nChoices:" |
| 55 | + "\nA) Pumps blood to the lungs\nB) Pumps blood to the body\nC) Collects blood from the body\nD) Stores blood", |
| 56 | + ), |
| 57 | + ], |
| 58 | +) |
| 59 | +def test_generate_prompt( |
| 60 | + problem, |
| 61 | + expected, |
| 62 | +): |
| 63 | + handler = MMLUProTaskHandler(task_config=MockTaskConfig) |
| 64 | + assert handler.generate_prompt(problem) == expected |
0 commit comments