source: python/tests/test_note2midi.py @ 6db7600

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

tests/test_note2midi.py: more tests

  • Property mode set to 100755
File size: 2.2 KB
RevLine 
[7d89e61]1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
[33102ab]3
[6db7600]4from aubio import note2midi, freq2note
[33102ab]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 ),
[f552e9e]16        ( 'Bb4', 70 ),
17        ( u'B♭4', 70 ),
[33102ab]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
[7d89e61]26class note2midi_good_values(unittest.TestCase):
[33102ab]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
[7d89e61]33class note2midi_wrong_values(unittest.TestCase):
[33102ab]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):
[f552e9e]40        " fails when passed a note with an invalid modifier "
[33102ab]41        self.assertRaises(ValueError, note2midi, 'C.1')
42
[f552e9e]43    def test_note2midi_another_wrong_modifier_again(self):
44        " fails when passed a note with a invalid note name "
[33102ab]45        self.assertRaises(ValueError, note2midi, 'CB-3')
46
47    def test_note2midi_wrong_octave(self):
[f552e9e]48        " fails when passed a wrong octave number "
[33102ab]49        self.assertRaises(ValueError, note2midi, 'CBc')
50
51    def test_note2midi_out_of_range(self):
[6db7600]52        " fails when passed a note out of range"
[33102ab]53        self.assertRaises(ValueError, note2midi, 'A9')
54
[6db7600]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
[f552e9e]63    def test_note2midi_wrong_data_type(self):
64        " fails when passed a non-string value "
65        self.assertRaises(TypeError, note2midi, 123)
66
[6db7600]67
68class freq2note_simple_test(unittest.TestCase):
69
70    def test_freq2note(self):
71        " make sure freq2note(441) == A4 "
72        self.assertEquals("A4", freq2note(441))
73
[33102ab]74if __name__ == '__main__':
75    unittest.main()
Note: See TracBrowser for help on using the repository browser.