Add run_data_analysis/tests/test_core.py
This commit is contained in:
parent
cd5f4aa37a
commit
ca66a15e24
1 changed files with 64 additions and 0 deletions
64
run_data_analysis/tests/test_core.py
Normal file
64
run_data_analysis/tests/test_core.py
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import pytest
|
||||||
|
import math
|
||||||
|
from run_data_analysis import core
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def valid_run_data():
|
||||||
|
return {
|
||||||
|
"band_center": 125.4,
|
||||||
|
"band_width": 20.1,
|
||||||
|
"cluster_score": 0.85,
|
||||||
|
"retry_tail": 1.12
|
||||||
|
}
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def edge_run_data():
|
||||||
|
# Enthält extreme, aber valide Werte zur Stabilitätsprüfung
|
||||||
|
return {
|
||||||
|
"band_center": 0.0,
|
||||||
|
"band_width": 0.0001,
|
||||||
|
"cluster_score": 0.0,
|
||||||
|
"retry_tail": 10.0
|
||||||
|
}
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def invalid_run_data():
|
||||||
|
# Fehlende Felder, um Validierung zu testen
|
||||||
|
return {
|
||||||
|
"band_center": "unknown",
|
||||||
|
"band_width": None,
|
||||||
|
"cluster_score": 0.9
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_analyse_run_data_returns_expected_keys(valid_run_data):
|
||||||
|
result = core.analyse_run_data(valid_run_data)
|
||||||
|
expected_keys = {"band_center", "band_width", "cluster_score", "retry_tail", "aggregates"}
|
||||||
|
assert isinstance(result, dict)
|
||||||
|
assert expected_keys.issubset(result.keys())
|
||||||
|
|
||||||
|
def test_analyse_run_data_value_types(valid_run_data):
|
||||||
|
result = core.analyse_run_data(valid_run_data)
|
||||||
|
# Prüfe auf numerische Ergebnisse
|
||||||
|
for key in ["band_center", "band_width", "cluster_score", "retry_tail"]:
|
||||||
|
assert isinstance(result[key], (int, float))
|
||||||
|
assert not math.isnan(result[key])
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyse_run_data_edge_values(edge_run_data):
|
||||||
|
result = core.analyse_run_data(edge_run_data)
|
||||||
|
assert result["band_center"] == pytest.approx(0.0)
|
||||||
|
assert result["band_width"] > 0
|
||||||
|
assert result["retry_tail"] >= 10.0
|
||||||
|
|
||||||
|
def test_analyse_run_data_invalid_input_raises(invalid_run_data):
|
||||||
|
with pytest.raises((TypeError, ValueError)):
|
||||||
|
core.analyse_run_data(invalid_run_data)
|
||||||
|
|
||||||
|
def test_analyse_run_data_aggregate_metrics(valid_run_data):
|
||||||
|
result = core.analyse_run_data(valid_run_data)
|
||||||
|
# Aggregates sollte statistische Substruktur enthalten
|
||||||
|
aggregates = result.get("aggregates")
|
||||||
|
assert isinstance(aggregates, dict)
|
||||||
|
for metric in ("mean", "stdev"):
|
||||||
|
assert metric in aggregates
|
||||||
|
assert aggregates["mean"] > 0.0
|
||||||
Loading…
Reference in a new issue