"""Historique de niveaux -> hauteurs de barres de la forme d'onde. L'overlay affiche une forme d'onde facon dictee : le niveau le plus recent a GAUCHE, les plus anciens vers la droite. Les positions sans donnee (debut d'enregistrement) ou silencieuses retombent sur un plancher, dessine comme un petit point plutot qu'une barre — c'est ce qui donne la traine pointillee. """ import pytest from audio_level import bar_heights, push_level def test_push_ajoute_en_tete(): assert push_level([], 0.5, capacity=3) == [0.5] assert push_level([0.5], 0.8, capacity=3) == [0.8, 0.5] def test_push_borne_la_capacite_en_jetant_le_plus_ancien(): h = [0.3, 0.2, 0.1] assert push_level(h, 0.9, capacity=3) == [0.9, 0.3, 0.2] def test_push_ne_modifie_pas_l_historique_recu(): h = [0.3] push_level(h, 0.9, capacity=3) assert h == [0.3] def test_push_borne_le_niveau_dans_zero_un(): assert push_level([], 5.0, capacity=2) == [1.0] assert push_level([], -3.0, capacity=2) == [0.0] def test_bar_heights_complete_avec_le_plancher(): b = bar_heights([1.0], n_bars=4, floor=0.08) assert len(b) == 4 assert b[0] == 1.0 assert b[1:] == [0.08, 0.08, 0.08] def test_bar_heights_tronque_si_historique_trop_long(): b = bar_heights([0.9, 0.8, 0.7, 0.6, 0.5], n_bars=3, floor=0.05) assert b == [0.9, 0.8, 0.7] def test_bar_heights_applique_le_plancher_aux_silences(): b = bar_heights([0.0, 0.5], n_bars=2, floor=0.1) assert b == [0.1, 0.5] def test_bar_heights_refuse_un_nombre_de_barres_absurde(): with pytest.raises(ValueError): bar_heights([0.5], n_bars=0, floor=0.1)