[969bbb2] | 1 | from aubio import fvec, zero_crossing_rate |
---|
| 2 | |
---|
| 3 | #! /usr/bin/env python |
---|
| 4 | |
---|
| 5 | from numpy.testing import TestCase |
---|
| 6 | |
---|
| 7 | buf_size = 2048 |
---|
| 8 | |
---|
| 9 | class 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 | |
---|
| 49 | if __name__ == '__main__': |
---|
| 50 | from unittest import main |
---|
| 51 | main() |
---|