"""Tests for LangSmith evaluators (pure data extraction functions).

Generated by our friend.
"""

import pytest

from ax_prover.evaluators import (
    build_timeout_count,
    compilation_error_count,
    is_proven,
    max_iterations_reached,
    number_of_iterations,
    reviewer_rejections,
)


class TestIsProven:
    """Tests for is_proven evaluator."""

    @pytest.mark.parametrize(
        "outputs, expected",
        [
            ({"item": {"proven": True}}, True),
            ({"item": {"proven": False}}, False),
            ({"error": "some error"}, False),
            ({}, False),
            ({"item": {}}, False),
        ],
    )
    def test_is_proven(self, outputs, expected):
        """Returns correct proven status from outputs dict."""
        assert is_proven(outputs) == expected


class TestMetricEvaluators:
    """Tests for metric extraction evaluators."""

    @pytest.mark.parametrize(
        "func, key, value",
        [
            (number_of_iterations, "number_of_iterations", 5),
            (reviewer_rejections, "reviewer_rejections", 3),
            (compilation_error_count, "compilation_error_count", 2),
            (build_timeout_count, "build_timeout_count", 1),
        ],
    )
    def test_returns_value_when_present(self, func, key, value):
        """Returns the metric value when present in outputs."""
        assert func({"metrics": {key: value}}) == value

    @pytest.mark.parametrize(
        "func",
        [number_of_iterations, reviewer_rejections, compilation_error_count, build_timeout_count],
    )
    def test_returns_zero_when_missing(self, func):
        """Returns 0 when metrics key is absent."""
        assert func({}) == 0

    def test_max_iterations_reached_true(self):
        """Returns True when max_iterations_reached is True."""
        assert max_iterations_reached({"metrics": {"max_iterations_reached": True}}) is True

    def test_max_iterations_reached_default(self):
        """Returns False when metrics are missing."""
        assert max_iterations_reached({}) is False
