DesenrolaAi / python-basic-pitch /tests /test_temporal_chord_metrics.py
Azure DevOps Pipeline
deploy: Merged PR 29: melhoria no projeto, refatoracao e desempenho para 100 pessoas logadas
07e5a95
Raw
History Blame Contribute Delete
1.32 kB
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from temporal_chord_metrics import ChordInterval, evaluate_temporal_chords
class TemporalChordMetricsTests(unittest.TestCase):
def test_pesa_acerto_pela_duracao_e_mede_fronteira(self):
reference = [ChordInterval(0, 2, "C"), ChordInterval(2, 4, "G")]
estimated = [ChordInterval(0, 2.25, "C"), ChordInterval(2.25, 4, "G")]
metrics = evaluate_temporal_chords(reference, estimated, tolerance_seconds=0.5)
self.assertAlmostEqual(metrics["exact_wcsr"], 0.9375)
self.assertEqual(metrics["boundaries"]["f1"], 1.0)
def test_distingue_raiz_de_qualidade_completa(self):
reference = [ChordInterval(0, 1, "Cmaj7")]
estimated = [ChordInterval(0, 1, "C7")]
metrics = evaluate_temporal_chords(reference, estimated)
self.assertEqual(metrics["root_wcsr"], 1.0)
self.assertEqual(metrics["full_quality_wcsr"], 0.0)
def test_rejeita_intervalos_sobrepostos(self):
with self.assertRaises(ValueError):
evaluate_temporal_chords(
[ChordInterval(0, 2, "C"), ChordInterval(1, 3, "G")],
[ChordInterval(0, 3, "C")],
)
if __name__ == "__main__":
unittest.main()