source: python/tests/test_zero_crossing_rate.py @ e85f35d

feature/crepe_org
Last change on this file since e85f35d was bb63c19, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] move unittest import to main

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