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_long_session_converges_exactly(): tempo = TapTempo() bpm = None for i in range(30): bpm = tempo.tap(i * 0.5) # 30 steady taps at 120 bpm assert bpm == 120 def test_whole_session_is_averaged(): tempo = TapTempo() # One sloppy 1.0s interval up front, then 20 taps at 0.5s. All 21 taps # count (no rolling window), so the estimate is the overall average # 10.5s / 20 intervals = 0.525s -> 114 bpm, not the recent-taps 120. tempo.tap(0.0) t = 1.0 bpm = None for _ in range(20): bpm = tempo.tap(t) t += 0.5 assert tempo.tap_count == 21 assert bpm == 114 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