44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""Unit tests: data integrity checks."""
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from src.data import validate_series
|
||
|
|
|
||
|
|
|
||
|
|
def _bar(ts, o=1.0, h=1.5, l=0.5, c=1.0):
|
||
|
|
return ts, o, h, l, c
|
||
|
|
|
||
|
|
|
||
|
|
def test_valid_series_passes():
|
||
|
|
ts = ["0", "1", "2", "3", "4"]
|
||
|
|
o = [1.0, 2.0, 1.0, 3.0, 3.0]
|
||
|
|
h = [1.5, 2.5, 1.5, 3.5, 3.5]
|
||
|
|
l = [0.5, 1.5, 0.5, 2.5, 2.5]
|
||
|
|
c = [1.0, 2.0, 1.2, 3.0, 3.2]
|
||
|
|
rep = validate_series(ts, o, h, l, c)
|
||
|
|
assert rep.ok is True
|
||
|
|
assert rep.errors == []
|
||
|
|
|
||
|
|
|
||
|
|
def test_missing_history_fails():
|
||
|
|
rep = validate_series(["0"], [1.0], [1.5], [0.5], [1.0])
|
||
|
|
assert rep.ok is False
|
||
|
|
|
||
|
|
|
||
|
|
def test_duplicate_timestamp_fails():
|
||
|
|
ts = ["0", "0", "1"]
|
||
|
|
rep = validate_series(ts, [1.0, 1.0, 1.0], [1.5, 1.5, 1.5], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0])
|
||
|
|
assert rep.ok is False
|
||
|
|
|
||
|
|
|
||
|
|
def test_out_of_order_fails():
|
||
|
|
ts = ["1", "0", "2"]
|
||
|
|
rep = validate_series(ts, [1.0] * 3, [1.5] * 3, [0.5] * 3, [1.0] * 3)
|
||
|
|
assert rep.ok is False
|
||
|
|
|
||
|
|
|
||
|
|
def test_low_above_high_fails():
|
||
|
|
ts = ["0", "1", "2"]
|
||
|
|
# low > high on first bar
|
||
|
|
rep = validate_series(ts, [1.0] * 3, [1.0] * 3, [2.0] * 3, [1.0] * 3)
|
||
|
|
assert rep.ok is False
|