File size: 2,033 Bytes
be62603
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
"""
Unit tests for the grading system.
Run with: pytest tests/test_graders.py -v
"""
import sys
sys.path.insert(0, ".")

import pytest
from tasks import TASKS
from graders import grade_submission, normalize_rows, compute_episode_score


def test_correct_solutions_score_1():
    for task_id, task in TASKS.items():
        score, feedback, _ = grade_submission(task_id, task["correct_query"])
        assert score == 1.0, f"{task_id}: correct query scored {score} — {feedback}"


def test_wrong_query_scores_below_1():
    for task_id in list(TASKS.keys())[:3]:
        score, _, _ = grade_submission(task_id, "SELECT 'wrong'")
        assert score < 1.0, f"{task_id}: wrong query should score < 1.0, got {score}"


def test_buggy_query_scores_below_1():
    for task_id, task in TASKS.items():
        score, _, _ = grade_submission(task_id, task["buggy_query"])
        assert score < 1.0, f"{task_id}: buggy query should not score 1.0"


def test_scores_in_range():
    for task_id, task in TASKS.items():
        for query in [task["correct_query"], task["buggy_query"], "SELECT 1"]:
            score, _, _ = grade_submission(task_id, query)
            assert 0.0 <= score <= 1.0, f"{task_id}: score {score} out of range"


def test_deterministic():
    query = "SELECT first_name FROM employees"
    scores = [grade_submission("easy_missing_from", query)[0] for _ in range(5)]
    assert len(set(scores)) == 1, f"Non-deterministic scores: {scores}"


def test_normalize_rows():
    rows = [(1, "Hello ", 3.14159), (2, "world", 2.71828)]
    normalized = normalize_rows(rows)
    assert normalized[0][2] == 3.14
    assert normalized[0][1] == "Hello"


def test_episode_score_early_solve_bonus():
    task_id = list(TASKS.keys())[0]
    task = TASKS[task_id]
    score = compute_episode_score(task_id, [task["correct_query"]])
    assert score > 1.0, "Early solve on first attempt should get bonus"


def test_episode_score_no_submissions():
    score = compute_episode_score("easy_missing_from", [])
    assert score == 0.0