6776f3f33377ec2ad3baed9ed432908d66a89f03
[python_utils.git] / tests / chords_test.py
1 #!/usr/bin/env python3
2
3 # © Copyright 2021-2022, Scott Gasch
4
5 """chord parser unittest"""
6
7 import unittest
8
9 from music.chords import ChordParser
10
11 import bootstrap
12 import unittest_utils as uu
13
14
15 class TestChordParder(unittest.TestCase):
16     def test_with_known_correct_answers(self):
17         expected_answers = {
18             'D': "root=D, others={'maj3': 4, 'perfect5th': 7}",
19             'Dmaj': "root=D, others={'maj3': 4, 'perfect5th': 7}",
20             'D major': "root=D, others={'maj3': 4, 'perfect5th': 7}",
21             'DM': "root=D, others={'maj3': 4, 'perfect5th': 7}",
22             'Dm': "root=D, others={'min3': 3, 'perfect5th': 7}",
23             'Dmin': "root=D, others={'min3': 3, 'perfect5th': 7}",
24             'D minor': "root=D, others={'min3': 3, 'perfect5th': 7}",
25             'Asus2': "root=A, others={'maj2': 2, 'perfect5th': 7}",
26             'Bsus4': "root=B, others={'perfect4': 5, 'perfect5th': 7}",
27             'F5': "root=F, others={'perfect5th': 7}",
28             'G/B': "root=G, others={'maj3': 4, 'perfect5th': 7, 'B': 3}",
29         }
30
31         cp = ChordParser()
32         for chord_name, expected_answer in expected_answers.items():
33             self.assertEqual(
34                 expected_answer, cp.parse(chord_name).__repr__(), f'Failed for {chord_name}'
35             )
36
37
38 if __name__ == '__main__':
39     bootstrap.initialize(unittest.main)()