From f0ee38e69fd6d827f1c9581a3a306b489f3f64bc Mon Sep 17 00:00:00 2001 From: Mika Date: Sun, 19 Apr 2026 02:07:47 +0000 Subject: [PATCH] Add data_visualization/tests/test_core.py --- data_visualization/tests/test_core.py | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 data_visualization/tests/test_core.py diff --git a/data_visualization/tests/test_core.py b/data_visualization/tests/test_core.py new file mode 100644 index 0000000..a52419f --- /dev/null +++ b/data_visualization/tests/test_core.py @@ -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)