File size: 1,316 Bytes
07e5a95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()