Add artifact_2_worker_binding_analysis/tests/test_core.py
This commit is contained in:
parent
7f8c8b7f57
commit
8e6c061416
1 changed files with 51 additions and 0 deletions
51
artifact_2_worker_binding_analysis/tests/test_core.py
Normal file
51
artifact_2_worker_binding_analysis/tests/test_core.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import pytest
|
||||||
|
from artifact_2_worker_binding_analysis import core
|
||||||
|
|
||||||
|
|
||||||
|
def make_worker_data(worker_values):
|
||||||
|
"""Hilfsfunktion zur Erzeugung einer Liste von WorkerBindingResult-ähnlichen Dicts."""
|
||||||
|
return [{"worker_id": wid, "population_percentage": val} for wid, val in worker_values]
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_worker_binding_typical_case():
|
||||||
|
data_enforced = make_worker_data([
|
||||||
|
("w1", 40.0),
|
||||||
|
("w2", 60.0),
|
||||||
|
])
|
||||||
|
data_randomized = make_worker_data([
|
||||||
|
("w1", 50.0),
|
||||||
|
("w2", 50.0),
|
||||||
|
])
|
||||||
|
result = core.analyze_worker_binding(data_enforced, data_randomized)
|
||||||
|
assert isinstance(result, dict)
|
||||||
|
# Erwartung: Ergebnis enthält Kennzahlen wie Durchschnittsunterschied oder Ähnliches
|
||||||
|
assert "difference_mean" in result
|
||||||
|
assert "workers_compared" in result
|
||||||
|
assert result["workers_compared"] == 2
|
||||||
|
# Überprüfen, ob Zahlen sinnvoll (Vergleichswert) sind
|
||||||
|
assert isinstance(result["difference_mean"], (float, int))
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_worker_binding_empty_inputs():
|
||||||
|
# Leere Eingaben sollten zu sinnvollem Default führen, nicht Absturz
|
||||||
|
result = core.analyze_worker_binding([], [])
|
||||||
|
assert isinstance(result, dict)
|
||||||
|
assert result.get("workers_compared", 0) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_worker_binding_mismatched_workers():
|
||||||
|
data_enforced = make_worker_data([("w1", 70.0)])
|
||||||
|
data_randomized = make_worker_data([("w2", 30.0)])
|
||||||
|
result = core.analyze_worker_binding(data_enforced, data_randomized)
|
||||||
|
# Sollte neutralen Vergleich liefern, kein Exception
|
||||||
|
assert isinstance(result, dict)
|
||||||
|
# Möglicherweise keine Overlap -> Differenzen leer oder 0
|
||||||
|
assert "workers_compared" in result
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_worker_binding_input_validation():
|
||||||
|
# Ungültige Typen -> Fehler
|
||||||
|
with pytest.raises((AssertionError, TypeError, ValueError)):
|
||||||
|
core.analyze_worker_binding(None, None)
|
||||||
|
with pytest.raises((AssertionError, TypeError, ValueError)):
|
||||||
|
core.analyze_worker_binding([{"wrong_field": 1}], [])
|
||||||
Loading…
Reference in a new issue