Browse Source

test: testing ema

pull/15/head
QuentinN42 8 months ago
parent
commit
ba1a67f02a
Signed by: number42 GPG Key ID: 2CD7D563712B3A50
  1. 39
      tests/indicators/test_ema.py

39
tests/indicators/test_ema.py

@ -0,0 +1,39 @@
"""Realy basic tests."""
import pytest
from datetime import datetime
from pandas import DataFrame, Series # type: ignore
from auto_trading.indicators.ema import EMA
def date(j: int) -> datetime:
return datetime.strptime(f"2015-03-{j}", "%Y-%m-%d")
@pytest.mark.parametrize(
"nb_values, data, expected",
[
(
10,
DataFrame(
{
"close": {
(date(i), st): 10 if i == 10 and st == "GOOG" else 0
for i in range(1, 11)
for st in ("GOOG", "GOOGL")
}
}
),
{"GOOG": 1.48, "GOOGL": 0.0},
),
],
)
def test_ema(nb_values: int, data: DataFrame, expected: Series) -> None:
"""Test the ema indicator."""
ema = EMA(nb_values)
res = ema(data).to_dict()
# round all values
res = {k: round(v, 3) for k, v in res.items()}
assert res == expected
Loading…
Cancel
Save