diff --git a/geiger_counter_visualizer/tests/test_core.py b/geiger_counter_visualizer/tests/test_core.py new file mode 100644 index 0000000..06bb589 --- /dev/null +++ b/geiger_counter_visualizer/tests/test_core.py @@ -0,0 +1,53 @@ +import pytest +import pandas as pd +from datetime import datetime +from geiger_counter_visualizer import core + + +@pytest.fixture +def sample_data_points(): + return [ + core.DataPoint(timestamp="2024-01-01T00:00:00", count=10, frequency=1.2), + core.DataPoint(timestamp="2024-01-01T00:00:01", count=15, frequency=1.4), + core.DataPoint(timestamp="2024-01-01T00:00:02", count=9, frequency=1.1) + ] + + +def test_datapoint_initialization(sample_data_points): + dp = sample_data_points[0] + assert isinstance(dp.timestamp, str) + assert dp.count == 10 + assert dp.frequency == pytest.approx(1.2) + # Valid ISO timestamp + parsed = datetime.fromisoformat(dp.timestamp) + assert isinstance(parsed, datetime) + + +def test_datapoint_type_validation(): + with pytest.raises((TypeError, ValueError)): + core.DataPoint(timestamp=123, count="a", frequency="b") + + +def test_visualize_data_monkeypatch(sample_data_points, monkeypatch): + calls = {} + + def fake_show(): + calls["called"] = True + monkeypatch.setattr("matplotlib.pyplot.show", fake_show) + + result = core.visualize_data(sample_data_points) + assert result is None + assert calls.get("called", False) is True + + +def test_visualize_data_empty(monkeypatch): + monkeypatch.setattr("matplotlib.pyplot.show", lambda: None) + # visualize_data should handle empty list gracefully + result = core.visualize_data([]) + assert result is None + + +def test_visualize_data_invalid_input(monkeypatch): + monkeypatch.setattr("matplotlib.pyplot.show", lambda: None) + with pytest.raises((AssertionError, TypeError)): + core.visualize_data([{"timestamp": "2024-01-01", "count": 3, "frequency": 0.5}]) \ No newline at end of file