File size: 1,631 Bytes
dec6257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Tests for src/benchmark_runner.py — pure functions only."""

import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))

import pytest
from benchmark_runner import log_question_result


def _result(evaluation_status, marks_awarded, api_ok=True, parse_ok=True, pred=["A"]):
    return {
        "question_id": "TEST001",
        "api_call_successful": api_ok,
        "parse_successful": parse_ok,
        "predicted_answer": pred,
        "marks_awarded": marks_awarded,
        "evaluation_status": evaluation_status,
        "attempt": 1,
    }


def test_correct_returns_correct():
    assert log_question_result(_result("correct", 4)) == "correct"


def test_incorrect_returns_incorrect():
    assert log_question_result(_result("incorrect", -1)) == "incorrect"


def test_partial_3_of_4_returns_partial():
    assert log_question_result(_result("partial_3_of_4", 3)) == "partial"


def test_partial_2_of_3_plus_returns_partial():
    assert log_question_result(_result("partial_2_of_3_plus", 2)) == "partial"


def test_partial_1_of_2_plus_returns_partial():
    assert log_question_result(_result("partial_1_of_2_plus", 1)) == "partial"


def test_skip_returns_skipped():
    assert log_question_result(_result("skipped", 0, pred="SKIP")) == "skipped"


def test_api_fail_returns_api_fail():
    assert log_question_result(_result("failure_api_or_parse", 0, api_ok=False, parse_ok=False, pred=None)) == "api_fail"


def test_parse_fail_returns_parse_fail():
    r = _result("failure_api_or_parse", 0, api_ok=True, parse_ok=False, pred=None)
    assert log_question_result(r) == "parse_fail"