From fe6a4cdd75ce2ceb611dd40a8deba0499857c7ff Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 17 Sep 2016 03:03:43 +0200 Subject: [PATCH] python/tests/test_pitchshift.py: add minimal tests --- python/tests/test_pitchshift.py | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 python/tests/test_pitchshift.py diff --git a/python/tests/test_pitchshift.py b/python/tests/test_pitchshift.py new file mode 100755 index 00000000..940124fc --- /dev/null +++ b/python/tests/test_pitchshift.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python + +from nose2 import TestCase +import aubio + +class aubio_pitchshift(TestCase): + + def setUp(self): + self.o = aubio.pitchshift() + + def test_default_creation(self): + self.assertEqual(self.o.get_pitchscale(), 1) + self.assertEqual(self.o.get_transpose(), 0) + + def test_on_zeros(self): + test_length = 20000 + read = 0 + # test on zeros + vec = aubio.fvec(512) + transpose_range = 24 + while read < test_length: + # transpose the samples + out = self.o(vec) + self.assertTrue((out == 0).all()) + # position in the file (between 0. and 1.) + percent_read = read / float(test_length) + # variable transpose rate (in semitones) + transpose = 2 * transpose_range * percent_read - transpose_range + # set transpose rate + self.o.set_transpose(transpose) + read += len(vec) + + def test_transpose_too_high(self): + with self.assertRaises(ValueError): + self.o.set_transpose(24.3) + + def test_transpose_too_low(self): + with self.assertRaises(ValueError): + self.o.set_transpose(-24.3) + +if __name__ == '__main__': + from nose2 import main + main() -- 2.11.0