Add artifact.1/tests/test_core.py
This commit is contained in:
parent
ebff022889
commit
64240aa211
1 changed files with 61 additions and 0 deletions
61
artifact.1/tests/test_core.py
Normal file
61
artifact.1/tests/test_core.py
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
import pytest
|
||||||
|
import pandas as pd
|
||||||
|
from typing import List, Dict
|
||||||
|
from artifact_1 import core
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_metric_data() -> List[Dict[str, float]]:
|
||||||
|
return [
|
||||||
|
{"band_width": 10.0, "retry_tail_p99": 5.0, "band_center": 100.0},
|
||||||
|
{"band_width": 15.0, "retry_tail_p99": 6.0, "band_center": 105.0},
|
||||||
|
{"band_width": 20.0, "retry_tail_p99": 4.5, "band_center": 98.5},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def edge_metric_data() -> List[Dict[str, float]]:
|
||||||
|
return [
|
||||||
|
{"band_width": 0.0, "retry_tail_p99": 0.0, "band_center": 0.0},
|
||||||
|
{"band_width": 100.0, "retry_tail_p99": 200.0, "band_center": 300.0},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyse_metrics_returns_dict(sample_metric_data):
|
||||||
|
result = core.analyse_metrics(sample_metric_data)
|
||||||
|
assert isinstance(result, dict), "Result should be a dictionary"
|
||||||
|
for key in ("band_width", "retry_tail_p99", "band_center"):
|
||||||
|
assert key in result, f"Missing expected key: {key}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyse_metrics_computation_consistency(sample_metric_data):
|
||||||
|
result = core.analyse_metrics(sample_metric_data)
|
||||||
|
df = pd.DataFrame(sample_metric_data)
|
||||||
|
# Vergleich grundlegender statistischer Kenngrößen
|
||||||
|
assert pytest.approx(result["band_width"]["mean"]) == df["band_width"].mean()
|
||||||
|
assert pytest.approx(result["retry_tail_p99"]["mean"]) == df["retry_tail_p99"].mean()
|
||||||
|
assert pytest.approx(result["band_center"]["mean"]) == df["band_center"].mean()
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyse_metrics_with_edge_cases(edge_metric_data):
|
||||||
|
result = core.analyse_metrics(edge_metric_data)
|
||||||
|
assert all(isinstance(v, dict) for v in result.values())
|
||||||
|
for metric_values in result.values():
|
||||||
|
for v in metric_values.values():
|
||||||
|
assert not pd.isna(v), "Analysis should not contain NaN values"
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyse_metrics_invalid_input_raises():
|
||||||
|
with pytest.raises((TypeError, ValueError)):
|
||||||
|
core.analyse_metrics([{"band_width": "x", "retry_tail_p99": 1, "band_center": 2}])
|
||||||
|
|
||||||
|
with pytest.raises((KeyError, ValueError)):
|
||||||
|
core.analyse_metrics([{"band_width": 1.0, "retry_tail_p99": 2.0}])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("field", ["band_width", "retry_tail_p99", "band_center"])
|
||||||
|
def test_analyse_metrics_field_level_validation(sample_metric_data, field):
|
||||||
|
# Manipuliere ein Feld, um Fehler zu erzwingen
|
||||||
|
corrupted = [{**d, field: None} for d in sample_metric_data]
|
||||||
|
with pytest.raises((TypeError, ValueError)):
|
||||||
|
core.analyse_metrics(corrupted)
|
||||||
Loading…
Reference in a new issue