source: python/tests/test_note2midi.py @ 1b62ee9

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

tests/test_note2midi.py: use unicode_literals, preparing for python3

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