Add data_analysis/tests/test_core.py
This commit is contained in:
parent
397fb37b30
commit
6b7d4a432f
1 changed files with 56 additions and 0 deletions
56
data_analysis/tests/test_core.py
Normal file
56
data_analysis/tests/test_core.py
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import pytest
|
||||||
|
import numpy as np
|
||||||
|
from data_analysis import core
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def synthetic_audio_data():
|
||||||
|
# 1 kHz sinus test signal with small noise
|
||||||
|
sr = 22050
|
||||||
|
t = np.linspace(0, 1, sr)
|
||||||
|
signal = np.sin(2 * np.pi * 1000 * t) + 0.01 * np.random.randn(len(t))
|
||||||
|
return signal
|
||||||
|
|
||||||
|
|
||||||
|
def test_patternreport_init():
|
||||||
|
report = core.PatternReport(pattern_name='TestPattern', frequency=440.0, correlation=0.95, comments='Valid pattern')
|
||||||
|
assert isinstance(report.pattern_name, str)
|
||||||
|
assert isinstance(report.frequency, float)
|
||||||
|
assert 0 <= report.correlation <= 1
|
||||||
|
assert isinstance(report.comments, str)
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_patterns_returns_list(synthetic_audio_data):
|
||||||
|
result = core.analyze_patterns(synthetic_audio_data)
|
||||||
|
assert isinstance(result, list)
|
||||||
|
assert all(isinstance(r, core.PatternReport) for r in result)
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_patterns_field_values_within_bounds(synthetic_audio_data):
|
||||||
|
results = core.analyze_patterns(synthetic_audio_data)
|
||||||
|
for r in results:
|
||||||
|
assert isinstance(r.pattern_name, str)
|
||||||
|
assert isinstance(r.frequency, float)
|
||||||
|
assert r.frequency > 0
|
||||||
|
assert isinstance(r.correlation, float)
|
||||||
|
assert 0.0 <= r.correlation <= 1.0
|
||||||
|
assert isinstance(r.comments, str)
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_patterns_handles_empty_input():
|
||||||
|
with pytest.raises((ValueError, AssertionError)):
|
||||||
|
_ = core.analyze_patterns([])
|
||||||
|
|
||||||
|
|
||||||
|
def test_repeatability_of_output(synthetic_audio_data):
|
||||||
|
res1 = core.analyze_patterns(synthetic_audio_data)
|
||||||
|
res2 = core.analyze_patterns(synthetic_audio_data)
|
||||||
|
# Frequencies should be similar within tolerance
|
||||||
|
assert len(res1) == len(res2)
|
||||||
|
for r1, r2 in zip(res1, res2):
|
||||||
|
assert pytest.approx(r1.frequency, rel=1e-3) == r2.frequency
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_types_raise():
|
||||||
|
with pytest.raises((TypeError, ValueError)):
|
||||||
|
_ = core.analyze_patterns('not_an_array')
|
||||||
Loading…
Reference in a new issue