"""tca.shortfall_bps: signed implementation shortfall of a fill vs the arrival mid, in bps (cost positive)."""
from __future__ import annotations

from fxhnt.domain.execution.tca import shortfall_bps


def test_buy_above_mid_is_positive_cost() -> None:
    assert abs(shortfall_bps("BUY", arrival_mid=100.0, fill_price=100.1) - 10.0) < 1e-6


def test_sell_below_mid_is_positive_cost() -> None:
    assert abs(shortfall_bps("SELL", arrival_mid=100.0, fill_price=99.9) - 10.0) < 1e-6


def test_no_fill_is_zero() -> None:
    assert shortfall_bps("BUY", arrival_mid=100.0, fill_price=0.0) == 0.0


def test_sell_above_mid_is_negative_shortfall() -> None:
    """Selling above mid is a SAVING (negative cost) — maker rebate / price improvement."""
    assert abs(shortfall_bps("SELL", arrival_mid=100.0, fill_price=100.1) - (-10.0)) < 1e-6
