38 lines
No EOL
1.6 KiB
Python
38 lines
No EOL
1.6 KiB
Python
import pytest
|
|
from data_analysis import core
|
|
from types import SimpleNamespace
|
|
|
|
@pytest.fixture
|
|
def sample_data():
|
|
return [
|
|
SimpleNamespace(timestamp='2024-06-14T00:00:00', voltage_mv=100.0, temperature_c=20.0, humidity_percent=50.0),
|
|
SimpleNamespace(timestamp='2024-06-14T00:10:00', voltage_mv=200.0, temperature_c=21.0, humidity_percent=52.0),
|
|
SimpleNamespace(timestamp='2024-06-14T00:20:00', voltage_mv=300.0, temperature_c=22.0, humidity_percent=55.0)
|
|
]
|
|
|
|
def test_analyze_data_return_type(sample_data):
|
|
report = core.analyze_data(sample_data)
|
|
assert isinstance(report, dict), 'SummaryReport sollte ein dict sein'
|
|
for key in ['max_voltage', 'min_voltage', 'average_voltage', 'correlation_with_weather']:
|
|
assert key in report, f'{key} fehlt im SummaryReport'
|
|
|
|
def test_analyze_data_values(sample_data):
|
|
report = core.analyze_data(sample_data)
|
|
assert pytest.approx(report['max_voltage'], rel=1e-5) == 300.0
|
|
assert pytest.approx(report['min_voltage'], rel=1e-5) == 100.0
|
|
assert pytest.approx(report['average_voltage'], rel=1e-5) == 200.0
|
|
assert isinstance(report['correlation_with_weather'], float)
|
|
|
|
def test_analyze_data_empty_list():
|
|
empty_data = []
|
|
with pytest.raises(ValueError):
|
|
core.analyze_data(empty_data)
|
|
|
|
def test_analyze_data_invalid_input():
|
|
invalid_data = [1, 2, 3]
|
|
with pytest.raises(TypeError):
|
|
core.analyze_data(invalid_data)
|
|
|
|
def test_analyze_data_float_precision(sample_data):
|
|
report = core.analyze_data(sample_data)
|
|
assert all(isinstance(v, float) for v in report.values()), 'Alle Werte im Report müssen floats sein' |