"""staleness_checker_test.py —— is_stale 单元测试。 移植自 reference-c++/visual_track_control/tests/staleness_checker_test.cpp。 覆盖(物理追踪思路 §7.1):从未取样判超龄、有效期内新鲜、超出有效期超龄、 边界恰好在有效期上(不算超龄)、时间戳不一致判超龄(C4)。 """ from visual_track_control.staleness_checker import is_stale def test_never_sampled_is_stale(): assert is_stale(0, 1000, 200) assert is_stale(-5, 1000, 200) def test_within_validity_is_fresh(): assert not is_stale(900, 1000, 200) assert not is_stale(1000, 1000, 200) # 刚取样 def test_beyond_validity_is_stale(): assert is_stale(799, 1000, 200) # 201 > 200 def test_exactly_at_boundary_is_fresh(): # 超龄判定为严格大于:恰好等于有效期仍算新鲜 assert not is_stale(800, 1000, 200) def test_inconsistent_timestamp_is_stale(): # C4:now < sample 时间戳不一致 → 年龄不可信 → 判超龄(宁降级不轻信) assert is_stale(2000, 1000, 200)