"""
Unit Tests for Technical Indicators Calculation Engine
"""
import pytest
import numpy as np
from python.analytics.technical_engine import TechnicalEngine

def test_ema_calculation():
    prices = np.array([10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0], dtype=np.float64)
    ema_5 = TechnicalEngine.calculate_ema(prices, 5)
    assert not np.isnan(ema_5[-1])
    # Last EMA value must be between initial mean and last price
    assert 12.0 <= ema_5[-1] <= 19.0

def test_vwap_calculation():
    high = np.array([105.0, 107.0, 106.0])
    low = np.array([100.0, 102.0, 101.0])
    close = np.array([102.0, 106.0, 104.0])
    volume = np.array([1000.0, 2000.0, 1500.0])

    vwap = TechnicalEngine.calculate_vwap(high, low, close, volume)
    assert len(vwap) == 3
    # VWAP should be roughly within min low and max high
    assert 100.0 <= vwap[-1] <= 107.0

def test_rsi_bounds():
    # Monotonically increasing close prices should give high RSI (>70)
    close = np.linspace(100, 200, 30)
    rsi = TechnicalEngine.calculate_rsi(close, 14)
    assert not np.isnan(rsi[-1])
    assert rsi[-1] > 80.0

    # Monotonically decreasing close prices should give low RSI (<30)
    close_down = np.linspace(200, 100, 30)
    rsi_down = TechnicalEngine.calculate_rsi(close_down, 14)
    assert not np.isnan(rsi_down[-1])
    assert rsi_down[-1] < 20.0
