"""Far-Field ASR Score.""" import pytest from ffas import ffas, ffas_harmonic, robustness, smooth_speed_from_rtf, word_accuracy def test_perfect_wer_scores_one(): assert ffas([0.0, 0.0]) == 1.0 def test_word_accuracy_is_remaining_fraction(): assert word_accuracy(0.0) == 1.0 assert word_accuracy(0.25) == pytest.approx(0.75) assert word_accuracy(1.37) == pytest.approx(1e-3) def test_harmonic_mean_of_two_values(): assert ffas_harmonic([0.5, 1.0]) == pytest.approx(2 / (1 / 0.5 + 1 / 1.0)) def test_rejects_non_positive_scores_and_negative_wer(): with pytest.raises(ValueError): ffas_harmonic([0.0]) with pytest.raises(ValueError): ffas([-0.1]) def test_low_snr_collapse_beats_similar_average_wer(): """Avg WER is almost the same; FFAS drops when Low SNR is unusable.""" clean_but_brittle = [0.01, 0.02, 0.03, 1.20] # avg 0.315 even = [0.28, 0.30, 0.32, 0.34] # avg 0.310 assert sum(clean_but_brittle) / 4 == pytest.approx(0.315) assert sum(even) / 4 == pytest.approx(0.310) assert ffas(even) > 0.6 assert ffas(clean_but_brittle) < 0.02 def test_rtf_is_a_tie_breaker_not_a_rescue(): wers = [0.10, 0.12, 0.14, 0.16] slow = ffas(wers, rtf=1.2) fast = ffas(wers, rtf=40.0) assert fast > slow brittle = [0.02, 0.04, 0.06, 1.10] assert ffas(brittle, rtf=80.0) < ffas(wers, rtf=1.2) def test_missing_or_zero_rtf_omits_speed_term(): wers = [0.1, 0.2] assert ffas(wers) == pytest.approx(ffas(wers, rtf=None)) assert ffas(wers, rtf=0.0) == pytest.approx(ffas(wers)) def test_robustness_and_speed(): assert robustness(0.0, 0.0) == 1.0 assert robustness(0.0, 0.5) == pytest.approx(0.5) assert smooth_speed_from_rtf(0) == 0 assert smooth_speed_from_rtf(1) == pytest.approx(0.5)