source: python/tests/test_zero_crossing_rate.py @ fe87823

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

python/tests/test_zero_crossing_rate.py: update

  • Property mode set to 100644
File size: 1.6 KB
Line 
1from aubio import fvec, zero_crossing_rate
2
3#! /usr/bin/env python
4
5from numpy.testing import TestCase
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(self):
15        """ create and delete fvec """
16        pass
17
18    def test_zeroes(self):
19        """ check zero crossing rate on a buffer of 0. """
20        self.assertEqual(0., zero_crossing_rate(self.vector))
21
22    def test_ones(self):
23        """ check zero crossing rate on a buffer of 1. """
24        self.vector[:] = 1.
25        self.assertEqual(0., zero_crossing_rate(self.vector))
26
27    def test_impulse(self):
28        """ check zero crossing rate on a buffer with an impulse """
29        self.vector[buf_size / 2] = 1.
30        self.assertEqual(0., zero_crossing_rate(self.vector))
31
32    def test_negative_impulse(self):
33        """ check zero crossing rate on a buffer with a negative impulse """
34        self.vector[buf_size / 2] = -1.
35        self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
36
37    def test_single(self):
38        """ check zero crossing rate on single crossing """
39        self.vector[buf_size / 2 - 1] = 1.
40        self.vector[buf_size / 2] = -1.
41        self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
42
43    def test_single_with_gap(self):
44        """ check zero crossing rate on single crossing with a gap"""
45        self.vector[buf_size / 2 - 2] = 1.
46        self.vector[buf_size / 2] = -1.
47        self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
48
49if __name__ == '__main__':
50    from unittest import main
51    main()
Note: See TracBrowser for help on using the repository browser.