""" Regression test for a real bug: taking a median/consensus across sibling-correlation estimates discarded a genuine match whenever most neighbours simply didn't happen to share this episode's specific jingle variant. Found directly on hpr0400: its three closest neighbours (399, 401, 402) correlated at ~0, but hpr0398 matched cleanly at 29.25s -- a median across all four reports ~0, silently discarding real evidence. """ import unittest from hpr_stripper.detect import _best_sibling_estimate class TestBestSiblingEstimate(unittest.TestCase): def test_takes_the_best_match_not_the_median(self): # hpr0400's real neighbour estimates: 398 matched cleanly, the # other three didn't share this episode's jingle variant at all. estimates = [0.25, 0.25, 0.25, 29.25] value, flag = _best_sibling_estimate(estimates) self.assertEqual(value, 29.25) self.assertIsNone(flag) def test_flags_when_nothing_found_anywhere_nearby(self): estimates = [0.25, 0.25, 0.25, 0.25] value, flag = _best_sibling_estimate(estimates) self.assertEqual(value, 0.25) self.assertEqual(flag, "no_asr_anchor_and_xcorr_inconclusive") def test_no_estimates_returns_none_none(self): self.assertEqual(_best_sibling_estimate([]), (None, None)) def test_single_strong_estimate_is_trusted(self): value, flag = _best_sibling_estimate([15.25]) self.assertEqual(value, 15.25) self.assertIsNone(flag) if __name__ == "__main__": unittest.main()