History

python/tests/test_pitchshift.py: add minimal tests

Paul Brossier committed 10 years ago

Commit fe6a4cd1 parent c2d076b1 file · +43 −0Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/tests/test_pitchshift.py+43−0
@@ -0,0 +1,43 @@
1+#! /usr/bin/env python
2+
3+from nose2 import TestCase
4+import aubio
5+
6+class aubio_pitchshift(TestCase):
7+
8+ def setUp(self):
9+ self.o = aubio.pitchshift()
10+
11+ def test_default_creation(self):
12+ self.assertEqual(self.o.get_pitchscale(), 1)
13+ self.assertEqual(self.o.get_transpose(), 0)
14+
15+ def test_on_zeros(self):
16+ test_length = 20000
17+ read = 0
18+ # test on zeros
19+ vec = aubio.fvec(512)
20+ transpose_range = 24
21+ while read < test_length:
22+ # transpose the samples
23+ out = self.o(vec)
24+ self.assertTrue((out == 0).all())
25+ # position in the file (between 0. and 1.)
26+ percent_read = read / float(test_length)
27+ # variable transpose rate (in semitones)
28+ transpose = 2 * transpose_range * percent_read - transpose_range
29+ # set transpose rate
30+ self.o.set_transpose(transpose)
31+ read += len(vec)
32+
33+ def test_transpose_too_high(self):
34+ with self.assertRaises(ValueError):
35+ self.o.set_transpose(24.3)
36+
37+ def test_transpose_too_low(self):
38+ with self.assertRaises(ValueError):
39+ self.o.set_transpose(-24.3)
40+
41+if __name__ == '__main__':
42+ from nose2 import main
43+ main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t