from lintunes.tap_tempo import TapTempo def test_steady_taps_120_bpm(): tempo = TapTempo() bpm = None for i in range(5): bpm = tempo.tap(10.0 + i * 0.5) # 0.5s intervals = 120 bpm assert bpm == 120 def test_first_tap_gives_no_bpm(): tempo = TapTempo() assert tempo.tap(1.0) is None assert tempo.tap_count == 1 def test_long_gap_resets_series(): tempo = TapTempo() tempo.tap(0.0) tempo.tap(0.5) assert tempo.bpm() == 120 # 5 seconds later: new series, old taps discarded assert tempo.tap(5.5) is None assert tempo.tap_count == 1 assert tempo.tap(6.1) == 100 # 0.6s interval def test_window_uses_recent_taps_only(): tempo = TapTempo() # 4 slow taps (1s = 60bpm) then 8 fast taps (0.25s = 240bpm); # only the last 8 taps count, so the slow ones age out entirely t = 0.0 for _ in range(4): tempo.tap(t) t += 1.0 for _ in range(8): tempo.tap(t) t += 0.25 assert tempo.bpm() == 240 def test_reset(): tempo = TapTempo() tempo.tap(0.0) tempo.tap(0.5) tempo.reset() assert tempo.bpm() is None assert tempo.tap_count == 0