Add data_visualization/tests/test_core.py
This commit is contained in:
parent
b2333d4978
commit
f0ee38e69f
1 changed files with 51 additions and 0 deletions
51
data_visualization/tests/test_core.py
Normal file
51
data_visualization/tests/test_core.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import pytest
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.figure as mpl_figure
|
||||||
|
|
||||||
|
from src.data_visualization import core
|
||||||
|
|
||||||
|
|
||||||
|
def test_plot_spectrum_returns_figure():
|
||||||
|
# Nominal case with a small set of frequencies
|
||||||
|
frequency_data = [20.0, 100.0, 1000.0, 5000.0, 15000.0]
|
||||||
|
fig = core.plot_spectrum(frequency_data)
|
||||||
|
assert isinstance(fig, mpl_figure.Figure)
|
||||||
|
|
||||||
|
|
||||||
|
def test_plot_spectrum_handles_empty_data():
|
||||||
|
# Should not crash on empty input, should still return a Figure
|
||||||
|
fig = core.plot_spectrum([])
|
||||||
|
assert isinstance(fig, mpl_figure.Figure)
|
||||||
|
|
||||||
|
|
||||||
|
def test_plot_spectrum_with_large_data():
|
||||||
|
# Large dataset of synthetic frequency amplitudes
|
||||||
|
frequency_data = np.linspace(0, 22050, num=2048).tolist()
|
||||||
|
fig = core.plot_spectrum(frequency_data)
|
||||||
|
assert isinstance(fig, mpl_figure.Figure)
|
||||||
|
|
||||||
|
|
||||||
|
def test_plot_spectrum_invalid_input_type():
|
||||||
|
# Edge case: wrong input type should raise a TypeError or ValueError
|
||||||
|
with pytest.raises((TypeError, ValueError)):
|
||||||
|
core.plot_spectrum('not_a_list')
|
||||||
|
|
||||||
|
|
||||||
|
def test_plot_spectrum_visual_properties(monkeypatch):
|
||||||
|
# Patch pyplot to check function calls without actually rendering
|
||||||
|
call_log = {}
|
||||||
|
|
||||||
|
def fake_plot(x, y, **kwargs):
|
||||||
|
call_log['called'] = True
|
||||||
|
call_log['x_len'] = len(x)
|
||||||
|
call_log['y_len'] = len(y)
|
||||||
|
|
||||||
|
monkeypatch.setattr(core.plt, 'plot', fake_plot)
|
||||||
|
|
||||||
|
freq_data = [10.0, 50.0, 100.0]
|
||||||
|
fig = core.plot_spectrum(freq_data)
|
||||||
|
|
||||||
|
assert isinstance(fig, mpl_figure.Figure)
|
||||||
|
assert call_log.get('called', False)
|
||||||
|
assert call_log['x_len'] == len(freq_data)
|
||||||
|
assert call_log['y_len'] == len(freq_data)
|
||||||
Loading…
Reference in a new issue