Add bpf_varianz_test/tests/test_core.py
This commit is contained in:
parent
e22f8523da
commit
71965fe445
1 changed files with 53 additions and 0 deletions
53
bpf_varianz_test/tests/test_core.py
Normal file
53
bpf_varianz_test/tests/test_core.py
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue