source: python/tests/test_zero_crossing_rate.py.old @ eadd8d5

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

tests/python/: removed old python tests

  • Property mode set to 100644
File size: 1.8 KB
Line 
1from aubio import zero_crossing_rate
2
3#! /usr/bin/env python
4
5from numpy.testing import TestCase
6
7buf_size = 2048
8channels = 1
9
10class zero_crossing_rate_test_case(TestCase):
11
12  def setUp(self):
13    self.vector = new_fvec(buf_size, channels)
14
15  def tearDown(self):
16    del_fvec(self.vector)
17
18  def test(self):
19    """ create and delete fvec """
20    pass
21
22  def test_zeroes(self):
23    """ check zero crossing rate on a buffer of 0. """
24    self.assertEqual(0., zero_crossing_rate(self.vector))
25
26  def test_ones(self):
27    """ check zero crossing rate on a buffer of 1. """
28    for index in range(buf_size):
29      for channel in range(channels):
30        fvec_write_sample(self.vector, 1., channel, index)
31    self.assertEqual(0., zero_crossing_rate(self.vector))
32
33  def test_impulse(self):
34    """ check zero crossing rate on a buffer with an impulse """
35    fvec_write_sample(self.vector, 1., 0, buf_size / 2)
36    self.assertEqual(0., zero_crossing_rate(self.vector))
37
38  def test_negative_impulse(self):
39    """ check zero crossing rate on a buffer with a negative impulse """
40    fvec_write_sample(self.vector, -1., 0, buf_size / 2)
41    self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
42
43  def test_single(self):
44    """ check zero crossing rate on single crossing """
45    fvec_write_sample(self.vector, +1., 0, buf_size / 2 - 1)
46    fvec_write_sample(self.vector, -1., 0, buf_size / 2)
47    self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
48
49  def test_single_with_gap(self):
50    """ check zero crossing rate on single crossing with a gap"""
51    fvec_write_sample(self.vector, +1., 0, buf_size / 2 - 2)
52    fvec_write_sample(self.vector, -1., 0, buf_size / 2)
53    self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
54
55if __name__ == '__main__':
56  unittest.main()
Note: See TracBrowser for help on using the repository browser.