"""Tests for trajectory post-processing primitives.""" from __future__ import annotations import numpy as np from ai_mouse._postprocess import gaussian_smooth def test_gaussian_smooth_preserves_endpoints() -> None: x = np.array([1.0, 5.0, 3.0, 8.0, 2.0, 6.0, 4.0]) result = gaussian_smooth(x, sigma=1.0) assert result[0] == 1.0 assert result[-1] == 4.0 def test_gaussian_smooth_short_input_unchanged() -> None: x = np.array([1.0, 2.0, 3.0]) result = gaussian_smooth(x, sigma=1.0) assert np.array_equal(result, x) def test_gaussian_smooth_constant_unchanged() -> None: x = np.full(20, 7.5) result = gaussian_smooth(x, sigma=1.0) assert np.allclose(result, x, atol=1e-6) from ai_mouse._postprocess import snap_endpoints def test_snap_endpoints_pins_first_and_last() -> None: forward = np.linspace(0.1, 0.9, 16) lateral = np.full(16, 0.5) f, l = snap_endpoints(forward.copy(), lateral.copy(), seq_len=16) assert f[0] == 0.0 assert l[0] == 0.0 assert f[-1] == 1.0 assert l[-1] == 0.0 def test_snap_endpoints_preserves_middle() -> None: forward = np.linspace(0.0, 1.0, 16) lateral = np.zeros(16) f, _ = snap_endpoints(forward.copy(), lateral.copy(), seq_len=16, n_snap=4) # Points before the last n_snap should be unchanged assert np.allclose(f[1 : 16 - 4], forward[1 : 16 - 4], atol=1e-6)