source: python/tests/test_zero_crossing_rate.py @ d9a5466

feature/crepe_org
Last change on this file since d9a5466 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
RevLine 
[969bbb2]1#! /usr/bin/env python
2
3from numpy.testing import TestCase
[89e9e71]4from aubio import fvec, zero_crossing_rate
5
[969bbb2]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 """
[376d5e9]24        self.vector[int(buf_size / 2)] = 1.
[969bbb2]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 """
[376d5e9]29        self.vector[int(buf_size / 2)] = -1.
[969bbb2]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 """
[376d5e9]34        self.vector[int(buf_size / 2) - 1] = 1.
35        self.vector[int(buf_size / 2)] = -1.
[969bbb2]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"""
[376d5e9]40        self.vector[int(buf_size / 2) - 2] = 1.
41        self.vector[int(buf_size / 2)] = -1.
[969bbb2]42        self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
43
44if __name__ == '__main__':
[bb63c19]45    from unittest import main
[969bbb2]46    main()
Note: See TracBrowser for help on using the repository browser.