source: python/tests/test_note2midi.py @ f552e9e

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since f552e9e was f552e9e, checked in by Paul Brossier <piem@piem.org>, 11 years ago

lib/aubio/midiconv.py: improve note2midi

  • Property mode set to 100755
File size: 1.7 KB
Line 
1# -*- encoding: utf8 -*-
2
3from aubio import note2midi
4import unittest
5
6list_of_known_notes = (
7        ( 'C-1', 0 ),
8        ( 'C#-1', 1 ),
9        ( 'd2', 38 ),
10        ( 'C3', 48 ),
11        ( 'B3', 59 ),
12        ( 'B#3', 60 ),
13        ( 'A4', 69 ),
14        ( 'A#4', 70 ),
15        ( 'Bb4', 70 ),
16        ( u'B♭4', 70 ),
17        ( 'G8', 115 ),
18        ( u'G♯8', 116 ),
19        ( 'G9', 127 ),
20        ( u'G\udd2a2', 45 ),
21        ( u'B\ufffd2', 45 ),
22        ( u'A♮2', 45 ),
23        )
24
25class TestNote2MidiGoodValues(unittest.TestCase):
26
27    def test_note2midi_known_values(self):
28        " known values are correctly converted "
29        for note, midi in list_of_known_notes:
30            self.assertEqual ( note2midi(note), midi )
31
32class TestNote2MidiWrongValues(unittest.TestCase):
33
34    def test_note2midi_missing_octave(self):
35        " fails when passed only one character"
36        self.assertRaises(ValueError, note2midi, 'C')
37
38    def test_note2midi_wrong_modifier(self):
39        " fails when passed a note with an invalid modifier "
40        self.assertRaises(ValueError, note2midi, 'C.1')
41
42    def test_note2midi_another_wrong_modifier_again(self):
43        " fails when passed a note with a invalid note name "
44        self.assertRaises(ValueError, note2midi, 'CB-3')
45
46    def test_note2midi_wrong_octave(self):
47        " fails when passed a wrong octave number "
48        self.assertRaises(ValueError, note2midi, 'CBc')
49
50    def test_note2midi_out_of_range(self):
51        " fails when passed a out of range note"
52        self.assertRaises(ValueError, note2midi, 'A9')
53
54    def test_note2midi_wrong_data_type(self):
55        " fails when passed a non-string value "
56        self.assertRaises(TypeError, note2midi, 123)
57
58if __name__ == '__main__':
59    unittest.main()
Note: See TracBrowser for help on using the repository browser.