source: python/tests/test_zero_crossing_rate.py @ 8489d7b

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampleryinfft+
Last change on this file since 8489d7b was 0b6d23d, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/tests: fix most prospect warnings

  • Property mode set to 100755
File size: 1.5 KB
Line 
1#! /usr/bin/env python
2
3from unittest import main
4from numpy.testing import TestCase
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[int(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[int(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[int(buf_size / 2) - 1] = 1.
36        self.vector[int(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[int(buf_size / 2) - 2] = 1.
42        self.vector[int(buf_size / 2)] = -1.
43        self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
44
45if __name__ == '__main__':
46    main()
Note: See TracBrowser for help on using the repository browser.