source: python/tests/test_midi2note.py @ 9ead7a9

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

lib/aubio/midiconv.py: add note2 midi

  • Property mode set to 100644
File size: 1.2 KB
Line 
1# -*- encoding: utf8 -*-
2
3from aubio import midi2note
4import unittest
5
6list_of_known_midis = (
7        ( 0, 'C-1' ),
8        ( 1, 'C#-1' ),
9        ( 38, 'D2' ),
10        ( 48, 'C3' ),
11        ( 59, 'B3' ),
12        ( 60, 'C4' ),
13        ( 127, 'G9' ),
14        )
15
16class TestMidi2NoteGoodValues(unittest.TestCase):
17
18    def test_midi2note_known_values(self):
19        " known values are correctly converted "
20        for midi, note in list_of_known_midis:
21            self.assertEqual ( midi2note(midi), note )
22
23class TestNote2MidiWrongValues(unittest.TestCase):
24
25    def test_midi2note_negative_value(self):
26        " fails when passed a negative value "
27        self.assertRaises(ValueError, midi2note, -2)
28
29    def test_midi2note_negative_value(self):
30        " fails when passed a value greater than 127 "
31        self.assertRaises(ValueError, midi2note, 128)
32
33    def test_midi2note_floating_value(self):
34        " fails when passed a floating point "
35        self.assertRaises(TypeError, midi2note, 69.2)
36
37    def test_midi2note_character_value(self):
38        " fails when passed a value that can not be transformed to integer "
39        self.assertRaises(TypeError, midi2note, "a")
40
41if __name__ == '__main__':
42    unittest.main()
Note: See TracBrowser for help on using the repository browser.