source: python/tests/test_zero_crossing_rate.py @ aba718a

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

python/tests/test_zero_crossing_rate.py: clean up, chmod +x

  • Property mode set to 100755
File size: 1.5 KB
Line 
1#! /usr/bin/env python
2
3from numpy.testing import TestCase
4
5from aubio import fvec, zero_crossing_rate
6
7buf_size = 2048
8
9class zero_crossing_rate_test_case(TestCase):
10
11    def setUp(self):
12        self.vector = fvec(buf_size)
13
14    def test_zeroes(self):
15        """ check zero crossing rate on a buffer of 0. """
16        self.assertEqual(0., zero_crossing_rate(self.vector))
17
18    def test_ones(self):
19        """ check zero crossing rate on a buffer of 1. """
20        self.vector[:] = 1.
21        self.assertEqual(0., zero_crossing_rate(self.vector))
22
23    def test_impulse(self):
24        """ check zero crossing rate on a buffer with an impulse """
25        self.vector[buf_size / 2] = 1.
26        self.assertEqual(0., zero_crossing_rate(self.vector))
27
28    def test_negative_impulse(self):
29        """ check zero crossing rate on a buffer with a negative impulse """
30        self.vector[buf_size / 2] = -1.
31        self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
32
33    def test_single(self):
34        """ check zero crossing rate on single crossing """
35        self.vector[buf_size / 2 - 1] = 1.
36        self.vector[buf_size / 2] = -1.
37        self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
38
39    def test_single_with_gap(self):
40        """ check zero crossing rate on single crossing with a gap"""
41        self.vector[buf_size / 2 - 2] = 1.
42        self.vector[buf_size / 2] = -1.
43        self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
44
45if __name__ == '__main__':
46    from unittest import main
47    main()
Note: See TracBrowser for help on using the repository browser.