Add gps_sync/tests/test_core.py
This commit is contained in:
parent
eccc0d4b5f
commit
742b070672
1 changed files with 65 additions and 0 deletions
65
gps_sync/tests/test_core.py
Normal file
65
gps_sync/tests/test_core.py
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
import pytest
|
||||||
|
from gps_sync import core
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_gps_data():
|
||||||
|
return [
|
||||||
|
{"timestamp": "2024-05-01T12:00:00", "latitude": 48.5701, "longitude": 13.4551},
|
||||||
|
{"timestamp": "2024-05-01T12:00:05", "latitude": 48.5702, "longitude": 13.4552},
|
||||||
|
{"timestamp": "2024-05-01T12:00:10", "latitude": 48.5703, "longitude": 13.4553},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_wifi_data():
|
||||||
|
return [
|
||||||
|
{"timestamp": "2024-05-01T12:00:01", "signal_strength": -55.0},
|
||||||
|
{"timestamp": "2024-05-01T12:00:06", "signal_strength": -60.0},
|
||||||
|
{"timestamp": "2024-05-01T12:00:11", "signal_strength": -65.0},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_sync_with_gps_nominal(sample_gps_data, sample_wifi_data):
|
||||||
|
result = core.sync_with_gps(sample_gps_data, sample_wifi_data)
|
||||||
|
assert isinstance(result, list)
|
||||||
|
assert len(result) == 3
|
||||||
|
|
||||||
|
first = result[0]
|
||||||
|
assert set(first.keys()) == {"timestamp", "latitude", "longitude", "signal_strength"}
|
||||||
|
assert isinstance(first["latitude"], float)
|
||||||
|
assert isinstance(first["longitude"], float)
|
||||||
|
assert isinstance(first["signal_strength"], float)
|
||||||
|
|
||||||
|
|
||||||
|
def test_sync_with_gps_empty_inputs():
|
||||||
|
result = core.sync_with_gps([], [])
|
||||||
|
assert result == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_sync_with_gps_missing_fields():
|
||||||
|
gps_data = [{"timestamp": "2024-05-01T12:00:00", "latitude": 48.5}] # missing longitude
|
||||||
|
wifi_data = [{"timestamp": "2024-05-01T12:00:00", "signal_strength": -50.0}]
|
||||||
|
|
||||||
|
with pytest.raises((KeyError, ValueError, TypeError)):
|
||||||
|
core.sync_with_gps(gps_data, wifi_data)
|
||||||
|
|
||||||
|
|
||||||
|
def test_sync_with_gps_timestamps_mismatch(sample_gps_data):
|
||||||
|
wifi_data = [
|
||||||
|
{"timestamp": "2024-05-01T13:00:00", "signal_strength": -40.0},
|
||||||
|
{"timestamp": "2024-05-01T14:00:00", "signal_strength": -42.0},
|
||||||
|
]
|
||||||
|
result = core.sync_with_gps(sample_gps_data, wifi_data)
|
||||||
|
# Depending on implementation, may return nearest or limited results
|
||||||
|
assert isinstance(result, list)
|
||||||
|
for entry in result:
|
||||||
|
assert 'signal_strength' in entry
|
||||||
|
assert isinstance(entry['signal_strength'], float)
|
||||||
|
|
||||||
|
|
||||||
|
def test_sync_with_gps_data_integrity(sample_gps_data, sample_wifi_data):
|
||||||
|
result = core.sync_with_gps(sample_gps_data, sample_wifi_data)
|
||||||
|
for entry in result:
|
||||||
|
assert -100.0 <= entry['signal_strength'] <= 0.0
|
||||||
|
assert -90.0 <= entry['latitude'] <= 90.0
|
||||||
|
assert -180.0 <= entry['longitude'] <= 180.0
|
||||||
Loading…
Reference in a new issue