Add artifact_1_band_width_analysis/tests/test_core.py
This commit is contained in:
parent
ddefcf1dc6
commit
70ed1e8794
1 changed files with 50 additions and 0 deletions
50
artifact_1_band_width_analysis/tests/test_core.py
Normal file
50
artifact_1_band_width_analysis/tests/test_core.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
import pytest
|
||||||
|
from artifact_1_band_width_analysis import core
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_runs():
|
||||||
|
# Erstellt kleine RunData-Objekte für Testzwecke
|
||||||
|
run1 = core.RunData(band_width=100.0, aux=1, near_expiry=0.1, retry_tail_p99=5.0)
|
||||||
|
run2 = core.RunData(band_width=120.0, aux=2, near_expiry=0.15, retry_tail_p99=4.0)
|
||||||
|
run3 = core.RunData(band_width=80.0, aux=1, near_expiry=0.05, retry_tail_p99=6.0)
|
||||||
|
return [run1, run2, run3]
|
||||||
|
|
||||||
|
|
||||||
|
def test_calculate_statistics_basic(sample_runs):
|
||||||
|
stats = core.calculate_statistics(sample_runs)
|
||||||
|
assert isinstance(stats, dict)
|
||||||
|
|
||||||
|
# Erwartete Metriken vorhanden
|
||||||
|
for key in ["band_width", "retry_tail_p99"]:
|
||||||
|
assert key in stats
|
||||||
|
assert "median" in stats[key]
|
||||||
|
assert "iqr" in stats[key]
|
||||||
|
|
||||||
|
# Median-Test für band_width
|
||||||
|
expected_median_band = 100.0
|
||||||
|
assert pytest.approx(stats["band_width"]["median"], rel=1e-9) == expected_median_band
|
||||||
|
|
||||||
|
|
||||||
|
def test_calculate_statistics_iqr(sample_runs):
|
||||||
|
stats = core.calculate_statistics(sample_runs)
|
||||||
|
# IQR = Q3 - Q1, für band_width (80, 100, 120) -> 20.0
|
||||||
|
assert pytest.approx(stats["band_width"]["iqr"], rel=1e-9) == 20.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_compare_runs_difference():
|
||||||
|
run1 = core.RunData(band_width=100.0, aux=1, near_expiry=0.1, retry_tail_p99=5.0)
|
||||||
|
run2 = core.RunData(band_width=150.0, aux=1, near_expiry=0.2, retry_tail_p99=4.5)
|
||||||
|
|
||||||
|
cmp = core.compare_runs(run1, run2)
|
||||||
|
assert isinstance(cmp, dict)
|
||||||
|
|
||||||
|
# Prüfung des Differenzzeichens
|
||||||
|
assert pytest.approx(cmp["band_width_diff"], rel=1e-9) == 50.0
|
||||||
|
assert pytest.approx(cmp["retry_tail_diff"], rel=1e-9) == -0.5
|
||||||
|
|
||||||
|
|
||||||
|
def test_compare_runs_invalid_input():
|
||||||
|
# Typprüfung: Muss Exception werfen bei falschem Typ
|
||||||
|
with pytest.raises((AssertionError, TypeError)):
|
||||||
|
core.compare_runs("not_a_run", None)
|
||||||
Loading…
Reference in a new issue