"""macro 인덱스 파생 계산(ret_pct/avg) 단위 테스트 — 네트워크 미사용."""
from __future__ import annotations

import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]
if str(ROOT) not in sys.path:
    sys.path.insert(0, str(ROOT))

from src.quant_engine.macro_index_collection_v1 import MACRO_SYMBOLS, _avg, _ret_pct


def test_macro_symbols_cover_thirteen_raw_instruments():
    assert len(MACRO_SYMBOLS) == 13
    symbols = {s for s, _, _ in MACRO_SYMBOLS}
    assert "^KS11" in symbols  # KOSPI
    assert "HYG" in symbols
    # "Computed" 카테고리(MRS_COMPUTED 등)는 의도적으로 포함하지 않는다.
    assert "MRS_COMPUTED" not in symbols


def test_ret_pct_against_n_days_ago():
    closes = [110.0, 108, 107, 106, 105, 100.0]
    assert _ret_pct(closes, 5) == 10.0


def test_ret_pct_none_when_window_exceeds_length():
    assert _ret_pct([100.0, 99.0], 20) is None


def test_avg_returns_none_for_empty_list():
    assert _avg([]) is None


def test_avg_computes_mean():
    assert _avg([10.0, 20.0, 30.0]) == 20.0
