summaryrefslogtreecommitdiff
path: root/tests/chords_test.py
blob: 8ecce71ff0321b97e979bd326f770dd190306364 (plain)
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
#!/usr/bin/env python3

# © Copyright 2021-2022, Scott Gasch

"""chord parser unittest"""

import unittest

from music.chords import ChordParser

import bootstrap
import unittest_utils as uu


class TestChordParder(unittest.TestCase):
    def test_with_known_correct_answers(self):
        expected_answers = {
            'D': "D (major)\nroot=D\n+ major 3rd (4) => F#\n+ perfect 5th (7) => A\n",
            'DM': "D (major)\nroot=D\n+ major 3rd (4) => F#\n+ perfect 5th (7) => A\n",
            'Dmaj': "D (major)\nroot=D\n+ major 3rd (4) => F#\n+ perfect 5th (7) => A\n",
            'D major': "D (major)\nroot=D\n+ major 3rd (4) => F#\n+ perfect 5th (7) => A\n",
        }

        cp = ChordParser()
        for chord_name, expected_answer in expected_answers.items():
            self.assertEqual(
                expected_answer, cp.parse(chord_name).__repr__(), f'Failed for {chord_name}'
            )


if __name__ == '__main__':
    bootstrap.initialize(unittest.main)()