source: python/tests/test_zero_crossing_rate.py @ fcb6e8c

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampler
Last change on this file since fcb6e8c 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
RevLine 
[969bbb2]1#! /usr/bin/env python
2
[0b6d23d]3from unittest import main
[969bbb2]4from numpy.testing import TestCase
[89e9e71]5from aubio import fvec, zero_crossing_rate
6
[969bbb2]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 """
[376d5e9]25        self.vector[int(buf_size / 2)] = 1.
[969bbb2]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 """
[376d5e9]30        self.vector[int(buf_size / 2)] = -1.
[969bbb2]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 """
[376d5e9]35        self.vector[int(buf_size / 2) - 1] = 1.
36        self.vector[int(buf_size / 2)] = -1.
[969bbb2]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"""
[376d5e9]41        self.vector[int(buf_size / 2) - 2] = 1.
42        self.vector[int(buf_size / 2)] = -1.
[969bbb2]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.