""" 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