source: python/tests/test_note2midi.py @ 376d5e9

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

tests/: continue python3 preparation

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