import pytest

from backtesting import engine as backtest_engine
from ml import optimizer
from scoring import engine as scoring_engine
from scoring import policy


def test_score_brackets_are_contiguous_and_shared_by_all_scoring_paths():
    assert backtest_engine.BRACKETS is policy.SCORE_BRACKETS
    assert optimizer.BRACKETS is policy.SCORE_BRACKETS

    for left, right in zip(policy.SCORE_BRACKETS, policy.SCORE_BRACKETS[1:]):
        assert left[1] == right[0]

    for tenth in range(0, 1001):
        score = tenth / 10
        matches = [bracket for bracket in policy.SCORE_BRACKETS if policy.score_in_bracket(score, bracket)]
        assert len(matches) == 1, f"score {score} matched {matches}"
        assert policy.assessment_for_score(score) == matches[0][2]


@pytest.mark.parametrize(
    ("score", "assessment"),
    [
        (0, "EXTREME CAUTION"),
        (19.999, "EXTREME CAUTION"),
        (20, "CAUTION — OVERHEATED"),
        (35, "NEUTRAL"),
        (50, "MODERATE OPPORTUNITY"),
        (65, "STRONG ACCUMULATION ZONE"),
        (80, "EXTREME ACCUMULATION ZONE"),
        (100, "EXTREME ACCUMULATION ZONE"),
    ],
)
def test_assessment_boundaries_match_live_scoring(score, assessment):
    assert policy.assessment_for_score(score) == assessment
    assert scoring_engine.assessment_for_score(score) == assessment
