Add data_analysis/tests/test_core.py
This commit is contained in:
parent
3348b9050d
commit
5a5b2c8450
1 changed files with 55 additions and 0 deletions
55
data_analysis/tests/test_core.py
Normal file
55
data_analysis/tests/test_core.py
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
import pytest
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from data_analysis import core
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_run_data():
|
||||||
|
base_time = datetime(2024, 1, 1, 12, 0, 0)
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
'run_id': 'r1',
|
||||||
|
'timestamp': base_time,
|
||||||
|
'delta_t': 0.5,
|
||||||
|
'expiring_at': base_time + timedelta(hours=1)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'run_id': 'r2',
|
||||||
|
'timestamp': base_time + timedelta(seconds=5),
|
||||||
|
'delta_t': -0.2,
|
||||||
|
'expiring_at': base_time + timedelta(hours=2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'run_id': 'r3',
|
||||||
|
'timestamp': base_time + timedelta(seconds=10),
|
||||||
|
'delta_t': 0.0,
|
||||||
|
'expiring_at': base_time + timedelta(hours=3)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_runs_structure(sample_run_data):
|
||||||
|
result = core.analyze_runs(sample_run_data)
|
||||||
|
assert isinstance(result, dict), 'Result must be a dict'
|
||||||
|
expected_keys = {'total_runs', 'negative_dt_count', 'negative_dt_ratio'}
|
||||||
|
for key in expected_keys:
|
||||||
|
assert key in result, f'Missing key: {key}'
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_runs_negative_count(sample_run_data):
|
||||||
|
result = core.analyze_runs(sample_run_data)
|
||||||
|
assert result['negative_dt_count'] == 1
|
||||||
|
assert result['total_runs'] == 3
|
||||||
|
assert result['negative_dt_ratio'] == pytest.approx(1/3, rel=1e-3)
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_runs_empty_list():
|
||||||
|
result = core.analyze_runs([])
|
||||||
|
assert result['total_runs'] == 0
|
||||||
|
assert result['negative_dt_count'] == 0
|
||||||
|
assert result['negative_dt_ratio'] == 0.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_runs_type_validation():
|
||||||
|
with pytest.raises((TypeError, AssertionError)):
|
||||||
|
core.analyze_runs('invalid_input')
|
||||||
Loading…
Reference in a new issue