2 # -*- coding: utf-8 -*-
4 from __future__ import unicode_literals
6 from aubio import note2midi, freq2note
9 list_of_known_notes = (
28 class note2midi_good_values(unittest.TestCase):
30 def test_note2midi_known_values(self):
31 " known values are correctly converted "
32 for note, midi in list_of_known_notes:
33 self.assertEqual ( note2midi(note), midi )
35 class note2midi_wrong_values(unittest.TestCase):
37 def test_note2midi_missing_octave(self):
38 " fails when passed only one character"
39 self.assertRaises(ValueError, note2midi, 'C')
41 def test_note2midi_wrong_modifier(self):
42 " fails when passed a note with an invalid modifier "
43 self.assertRaises(ValueError, note2midi, 'C.1')
45 def test_note2midi_another_wrong_modifier_again(self):
46 " fails when passed a note with a invalid note name "
47 self.assertRaises(ValueError, note2midi, 'CB-3')
49 def test_note2midi_wrong_octave(self):
50 " fails when passed a wrong octave number "
51 self.assertRaises(ValueError, note2midi, 'CBc')
53 def test_note2midi_out_of_range(self):
54 " fails when passed a note out of range"
55 self.assertRaises(ValueError, note2midi, 'A9')
57 def test_note2midi_wrong_note_name(self):
58 " fails when passed a note with a wrong name"
59 self.assertRaises(ValueError, note2midi, 'W9')
61 def test_note2midi_wrong_octave(self):
62 " fails when passed a note with a wrong octave"
63 self.assertRaises(ValueError, note2midi, 'C-9')
65 def test_note2midi_wrong_data_type(self):
66 " fails when passed a non-string value "
67 self.assertRaises(TypeError, note2midi, 123)
70 class freq2note_simple_test(unittest.TestCase):
72 def test_freq2note(self):
73 " make sure freq2note(441) == A4 "
74 self.assertEqual("A4", freq2note(441))
76 if __name__ == '__main__':