from __future__ import annotations import pytest from app.engine.indicators import atr, ema, rolling_std, rsi, sma from app.schemas import Candle def candle(high: float, low: float, close: float, open_: float | None = None) -> Candle: return Candle( ts=0, open=open_ if open_ is not None else close, high=high, low=low, close=close, volume=1, ) def test_sma() -> None: assert sma([1, 2, 3, 4, 5], 3) == [None, None, 2.0, 3.0, 4.0] def test_ema() -> None: assert ema([1, 2, 3, 4, 5], 3) == [None, None, 2.0, 3.0, 4.0] def test_rsi_monotonic_is_100() -> None: values = [float(i) for i in range(1, 20)] assert rsi(values, 14)[-1] == pytest.approx(100.0) def test_atr_flat_market_is_zero() -> None: candles = [candle(100, 100, 100) for _ in range(20)] assert atr(candles, 5)[-1] == pytest.approx(0.0) def test_rolling_std() -> None: result = rolling_std([1, 1, 1, 1], 2) assert result[-1] == pytest.approx(0.0)