diff options
| author | Scott Gasch <[email protected]> | 2022-04-22 09:42:08 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2022-04-22 09:42:08 -0700 |
| commit | 711a9fd699f7c724f0aab7c1c43511cfbf7b2281 (patch) | |
| tree | 441b5fceae86f7e11adcf3a0ce9fff69bb0c9ce0 /tests | |
| parent | 068d71327bf6ec8618cd70a6d3fce5d075503cae (diff) | |
Add a chord parser test.
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/chords_test.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/chords_test.py b/tests/chords_test.py new file mode 100755 index 0000000..6776f3f --- /dev/null +++ b/tests/chords_test.py @@ -0,0 +1,39 @@ +#!/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': "root=D, others={'maj3': 4, 'perfect5th': 7}", + 'Dmaj': "root=D, others={'maj3': 4, 'perfect5th': 7}", + 'D major': "root=D, others={'maj3': 4, 'perfect5th': 7}", + 'DM': "root=D, others={'maj3': 4, 'perfect5th': 7}", + 'Dm': "root=D, others={'min3': 3, 'perfect5th': 7}", + 'Dmin': "root=D, others={'min3': 3, 'perfect5th': 7}", + 'D minor': "root=D, others={'min3': 3, 'perfect5th': 7}", + 'Asus2': "root=A, others={'maj2': 2, 'perfect5th': 7}", + 'Bsus4': "root=B, others={'perfect4': 5, 'perfect5th': 7}", + 'F5': "root=F, others={'perfect5th': 7}", + 'G/B': "root=G, others={'maj3': 4, 'perfect5th': 7, 'B': 3}", + } + + 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)() |
