from edge.models import Keypoint from edge.smoothing import OneEuroFilter, KeypointSmoother, TrackSmootherPool def test_one_euro_first_sample_returns_input(): f = OneEuroFilter(min_cutoff=1.0, beta=0.0) assert f.filter(5.0, t=0.0) == 5.0 def test_one_euro_attenuates_jitter(): f = OneEuroFilter(min_cutoff=0.5, beta=0.0) f.filter(0.0, t=0.0) out = f.filter(10.0, t=0.1) # big jump at low cutoff -> damped below input assert 0.0 < out < 10.0 def test_keypoint_smoother_preserves_conf_and_length(): s = KeypointSmoother() kps = [Keypoint(float(i), float(i), 0.8) for i in range(17)] out = s.smooth(kps, t=0.0) assert len(out) == 17 assert out[3].conf == 0.8 def test_pool_returns_same_smoother_instance_for_same_track(): pool = TrackSmootherPool() assert pool.smoother_for(1) is pool.smoother_for(1) def test_pool_gives_independent_smoothers_per_track(): pool = TrackSmootherPool() assert pool.smoother_for(1) is not pool.smoother_for(2) def test_pool_forget_drops_state_so_next_call_is_fresh(): pool = TrackSmootherPool() s1 = pool.smoother_for(1) s1.smooth([Keypoint(0.0, 0.0, 0.9) for _ in range(17)], t=0.0) pool.forget(1) s2 = pool.smoother_for(1) assert s2 is not s1 # fresh filter: first sample passes through unfiltered regardless of prior state out = s2.smooth([Keypoint(50.0, 50.0, 0.9) for _ in range(17)], t=1.0) assert out[0].x == 50.0