"""Beat interval plausibility helpers (audio detector)."""

import os
import sys
from collections import deque

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if PROJECT_ROOT not in sys.path:
    sys.path.insert(0, PROJECT_ROOT)

from tests.beat_detect import _is_plausible_ioi, _resolve_bpm  # noqa: E402


def test_is_plausible_ioi_rejects_double_time():
    times = deque([0.0, 0.5, 1.0])
    assert _is_plausible_ioi(1.0, times, 1.15) is False


def test_is_plausible_ioi_accepts_steady_grid():
    times = deque([0.0, 0.5, 1.0])
    assert _is_plausible_ioi(1.0, times, 1.5) is True


def test_resolve_bpm_prefers_intervals_over_wrong_aubio():
    times = deque([0.0, 0.5, 1.0, 1.5, 2.0])
    bpm = _resolve_bpm(times, 70.0)
    assert bpm is not None
    assert abs(bpm - 120.0) < 5.0
