From d5957754fc4a2718595752062e71bc93ccd8deb9 Mon Sep 17 00:00:00 2001 From: Mika Date: Mon, 16 Mar 2026 13:59:11 +0000 Subject: [PATCH] Add scheduling_analysis/tests/test_core.py --- scheduling_analysis/tests/test_core.py | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scheduling_analysis/tests/test_core.py diff --git a/scheduling_analysis/tests/test_core.py b/scheduling_analysis/tests/test_core.py new file mode 100644 index 0000000..1d18df2 --- /dev/null +++ b/scheduling_analysis/tests/test_core.py @@ -0,0 +1,46 @@ +import pytest +import pandas as pd +from scheduling_analysis import core + +@pytest.fixture +def sample_data(): + return [ + {"run_id": "r1", "metric_name": "max_outlier_ms", "metric_value": 10.0, "mechanism": "sched_a"}, + {"run_id": "r2", "metric_name": "max_outlier_ms", "metric_value": 25.0, "mechanism": "sched_b"}, + {"run_id": "r1", "metric_name": "band_width_h", "metric_value": 5.0, "mechanism": "sched_a"}, + {"run_id": "r2", "metric_name": "band_width_h", "metric_value": 7.5, "mechanism": "sched_b"} + ] + + +def test_analyze_scheduling_effects_basic(sample_data): + result = core.analyze_scheduling_effects(sample_data) + assert isinstance(result, dict) + assert set(result.keys()) == {"max_outlier_effect", "resonance_band_shift", "metrics"} + + # numerical plausibility + assert isinstance(result["max_outlier_effect"], float) + assert isinstance(result["resonance_band_shift"], float) + assert abs(result["max_outlier_effect"] - 15.0) < 1e-6 + assert abs(result["resonance_band_shift"] - 2.5) < 1e-6 + + +def test_empty_data_raises(): + with pytest.raises(ValueError): + core.analyze_scheduling_effects([]) + + +def test_invalid_data_type(): + # Not a list should raise a TypeError + with pytest.raises(TypeError): + core.analyze_scheduling_effects("invalid") + + +def test_partial_metrics_present(): + data = [ + {"run_id": "r1", "metric_name": "max_outlier_ms", "metric_value": 10.0, "mechanism": "sched_a"}, + {"run_id": "r1", "metric_name": "band_width_h", "metric_value": 5.0, "mechanism": "sched_a"} + ] + result = core.analyze_scheduling_effects(data) + assert result["max_outlier_effect"] == pytest.approx(0.0) + assert result["resonance_band_shift"] == pytest.approx(0.0) + assert isinstance(result["metrics"], dict) \ No newline at end of file