feat(lib): add resample_arc, build_timestamps
This commit is contained in:
@@ -72,3 +72,35 @@ def test_enforce_forward_monotonic_clips_to_unit_interval() -> None:
|
||||
out = enforce_forward_monotonic(f.copy())
|
||||
assert out[0] == 0.0
|
||||
assert out[-1] == 1.0
|
||||
|
||||
|
||||
from ai_mouse._postprocess import build_timestamps, resample_arc
|
||||
|
||||
|
||||
def test_resample_arc_identity_when_same_length() -> None:
|
||||
pts = np.array([[0.0, 0.0], [1.0, 1.0], [2.0, 0.0], [3.0, 1.0]])
|
||||
out = resample_arc(pts, 4)
|
||||
assert np.allclose(out, pts, atol=1e-6)
|
||||
|
||||
|
||||
def test_resample_arc_changes_length() -> None:
|
||||
pts = np.array([[float(i), 0.0] for i in range(10)])
|
||||
out = resample_arc(pts, 5)
|
||||
assert out.shape == (5, 2)
|
||||
# Endpoints preserved
|
||||
assert np.allclose(out[0], pts[0])
|
||||
assert np.allclose(out[-1], pts[-1])
|
||||
|
||||
|
||||
def test_build_timestamps_strictly_increasing() -> None:
|
||||
log_dt = np.array([0.0, 2.0, 2.5, 3.0, 2.0])
|
||||
ts = build_timestamps(log_dt, total_duration_ms=200.0)
|
||||
assert ts[0] == 0
|
||||
assert np.all(np.diff(ts) >= 1) # at least 1 ms apart
|
||||
|
||||
|
||||
def test_build_timestamps_total_close_to_target() -> None:
|
||||
log_dt = np.array([1.0] * 10)
|
||||
ts = build_timestamps(log_dt, total_duration_ms=300.0)
|
||||
# Last timestamp should be roughly total - one slot
|
||||
assert abs(ts[-1] - 270) < 60 # tolerant of clipping
|
||||
|
||||
Reference in New Issue
Block a user