#!/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)()