From 71965fe445995e284a72714aed93e151d82f8c82 Mon Sep 17 00:00:00 2001 From: Mika Date: Sat, 13 Dec 2025 14:37:15 +0000 Subject: [PATCH] Add bpf_varianz_test/tests/test_core.py --- bpf_varianz_test/tests/test_core.py | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bpf_varianz_test/tests/test_core.py diff --git a/bpf_varianz_test/tests/test_core.py b/bpf_varianz_test/tests/test_core.py new file mode 100644 index 0000000..653973b --- /dev/null +++ b/bpf_varianz_test/tests/test_core.py @@ -0,0 +1,53 @@ +import pytest +import math +import numpy as np +from bpf_varianz_test import core + + +def test_perform_levene_test_basic(): + kprobe_samples = [1.0, 1.2, 1.1, 1.3, 1.05] + bpf_samples = [1.0, 1.0, 1.02, 0.98, 1.01] + + p_value, significant = core.perform_levene_test(kprobe_samples, bpf_samples) + + assert isinstance(p_value, float) + assert isinstance(significant, bool) + assert 0.0 <= p_value <= 1.0 + + # Erwartung: Varianzen unterschiedlich -> p-Wert klein oder merkbar signifikant + # (nicht streng testen, da Stichproben klein) + assert p_value > 0 or significant in (True, False) + + +def test_perform_levene_test_identical_samples(): + kprobe_samples = [1.0, 1.1, 0.9, 1.05, 0.95] + bpf_samples = list(kprobe_samples) + + p_value, significant = core.perform_levene_test(kprobe_samples, bpf_samples) + assert pytest.approx(p_value, rel=1e-6) == 1.0 or p_value > 0.9 + assert significant is False + + +def test_bootstrap_variance_confidence_interval_typical_range(): + samples = [1.0, 1.1, 0.9, 1.2, 1.05, 0.95, 1.0] + low, high = core.bootstrap_variance_confidence_interval(samples, 500) + + assert isinstance(low, float) + assert isinstance(high, float) + assert low < high + + var_emp = np.var(samples, ddof=1) + # Das empirische Varianzmaß sollte im Intervall liegen + assert low <= var_emp <= high + + +def test_bootstrap_variance_confidence_interval_increasing_sample(): + samples_small_var = [1.0, 1.01, 0.99, 1.0, 1.02] + samples_large_var = [1.0, 1.3, 0.7, 1.4, 0.6] + + low_s, high_s = core.bootstrap_variance_confidence_interval(samples_small_var, 200) + low_l, high_l = core.bootstrap_variance_confidence_interval(samples_large_var, 200) + + # Erwartung: Varianzintervall der größeren Streuung weiter/höher + assert (high_l - low_l) >= (high_s - low_s) + assert high_l > high_s \ No newline at end of file