"""Tests for benchmark suite."""

import anesthesim  # noqa: F401
from anesthesim.benchmarks.environments import BENCHMARK_ENVS
from anesthesim.benchmarks.runner import run_benchmarks


class TestBenchmarkEnvironments:
    def test_env_list_not_empty(self):
        assert len(BENCHMARK_ENVS) >= 3

    def test_each_env_has_required_fields(self):
        for env in BENCHMARK_ENVS:
            assert "env_id" in env
            assert "name" in env
            assert "difficulty_tiers" in env
            assert len(env["difficulty_tiers"]) >= 2

    def test_env_ids_are_valid(self):
        import gymnasium as gym
        for env in BENCHMARK_ENVS:
            e = gym.make(env["env_id"])
            e.close()


class TestBenchmarkRunner:
    def test_run_benchmarks_returns_dict(self):
        results = run_benchmarks(n_episodes=2, seed=42)
        assert isinstance(results, dict)
        assert len(results) == 3

    def test_results_have_baselines(self):
        results = run_benchmarks(n_episodes=2, seed=42)
        for name, data in results.items():
            assert "random" in data
            assert "heuristic" in data
            assert "mean_reward" in data["random"]
            assert "std_reward" in data["random"]

    def test_heuristic_beats_random(self):
        results = run_benchmarks(n_episodes=3, seed=42)
        for name, data in results.items():
            assert data["heuristic"]["mean_reward"] > data["random"]["mean_reward"]
