from fxhnt.domain.ts_trend import ts_trend_signal


def test_all_up_series_is_plus_one():
    closes = [float(p) for p in range(1, 201)]  # strictly ascending
    assert ts_trend_signal(closes, [20, 60, 120]) == 1.0


def test_all_down_series_is_minus_one():
    closes = [float(p) for p in range(200, 0, -1)]  # strictly descending
    assert ts_trend_signal(closes, [20, 60, 120]) == -1.0


def test_mixed_series_is_between():
    # up over the short horizon, down over the long horizon -> mean of signs in (-1, 1)
    closes = [100.0] * 100 + [50.0] * 30 + list(range(50, 90))  # recent rebound
    closes = [float(c) for c in closes]
    sig = ts_trend_signal(closes, [20, 120])
    assert sig is not None
    assert -1.0 < sig < 1.0


def test_insufficient_history_is_none():
    closes = [1.0, 2.0, 3.0]
    assert ts_trend_signal(closes, [20, 60, 120]) is None


def test_non_positive_close_is_none():
    closes = [float(p) for p in range(1, 200)]
    closes[-1 - 20] = 0.0  # needed close at lookback 20 is non-positive
    assert ts_trend_signal(closes, [20]) is None
