import sys
from pathlib import Path
import pytest

# Añadir raíz del proyecto al path
sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent))

from src.risk.sizing.fixed import FixedPositionSizer


def test_fixed_position_size_basic():
    sizer = FixedPositionSizer(capital_fraction=0.5)

    capital = 10_000
    entry_price = 100

    units = sizer.calculate_size(
        capital=capital,
        entry_price=entry_price
    )

    # 50% de 10k = 5k / 100 = 50 unidades
    assert units == 50


def test_fixed_position_size_full_capital():
    sizer = FixedPositionSizer(capital_fraction=1.0)

    units = sizer.calculate_size(
        capital=10_000,
        entry_price=200
    )

    assert units == 50


def test_fixed_invalid_fraction():
    with pytest.raises(ValueError):
        FixedPositionSizer(capital_fraction=1.5)
