Files
gps-denied-onboard/tests/e2e/test_synthetic_adapter.py
T
Yuzviak bf5b0e3ae2 fix(lint): resolve all ruff E402/I001/F821 errors
- Move pytestmark after all imports in 35 test files (E402: not-at-top)
- Add TYPE_CHECKING guard for FlightProcessor in composition.py (F821)
- Sort import blocks in src/ and tests/ (I001 auto-fix via ruff --fix)
- ruff check src/ tests/ now exits 0 with no errors

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 19:13:42 +03:00

53 lines
1.8 KiB
Python

"""SyntheticAdapter produces a deterministic straight-line trajectory."""
import numpy as np
import pytest
from gps_denied.testing.datasets.base import PlatformClass
from gps_denied.testing.datasets.synthetic import SyntheticAdapter
pytestmark = [pytest.mark.unit]
def test_synthetic_has_raw_imu():
adapter = SyntheticAdapter(num_frames=10, fps=5.0)
assert adapter.capabilities.has_raw_imu is True
assert adapter.capabilities.platform_class == PlatformClass.SYNTHETIC
def test_synthetic_iter_frames_count():
adapter = SyntheticAdapter(num_frames=10, fps=5.0)
frames = list(adapter.iter_frames())
assert len(frames) == 10
assert frames[0].frame_idx == 0
assert frames[-1].frame_idx == 9
def test_synthetic_frame_timestamps_monotonic():
adapter = SyntheticAdapter(num_frames=10, fps=5.0)
ts = [f.timestamp_ns for f in adapter.iter_frames()]
assert ts == sorted(ts)
# 5 fps → 200 ms spacing
deltas = np.diff(ts)
assert np.allclose(deltas, 200_000_000)
def test_synthetic_imu_samples_cover_frames():
adapter = SyntheticAdapter(num_frames=10, fps=5.0, imu_rate_hz=100.0)
imu = list(adapter.iter_imu())
# 10 frames at 5 fps = 2 s of data, at 100 Hz = 200 samples
assert len(imu) == 200
# Static trajectory → gravity on z, zero gyro
assert abs(imu[0].accel[2] + 9.81) < 1e-6
assert imu[0].gyro == (0.0, 0.0, 0.0)
def test_synthetic_ground_truth_matches_frames():
adapter = SyntheticAdapter(num_frames=10, fps=5.0)
poses = list(adapter.iter_ground_truth())
assert len(poses) == 10
# Straight-line east at 10 m/s → position at t=0.2s is 2m east of origin
# (synthetic puts GT at same timestamps as frames)
assert abs(poses[1].lat - poses[0].lat) < 1e-9 # no latitude change
assert poses[1].lon > poses[0].lon # moving east