ext/py-musicutils.c: complete window implementation
[aubio.git] / python / tests / test_musicutils.py
1 #! /usr/bin/env python
2
3 from numpy.testing import TestCase
4 from numpy.testing.utils import assert_almost_equal
5 from aubio import window
6
7 class aubio_window(TestCase):
8
9     def test_accept_name_and_size(self):
10         window("default", 1024)
11
12     def test_fail_name_not_string(self):
13         try:
14             window(10, 1024)
15         except ValueError, e:
16             pass
17         else:
18             self.fail('non-string window type does not raise a ValueError')
19
20     def test_fail_size_not_int(self):
21         try:
22             window("default", "default")
23         except ValueError, e:
24             pass
25         else:
26             self.fail('non-integer window length does not raise a ValueError')
27
28     def test_compute_hanning_1024(self):
29         from numpy import cos, arange
30         from math import pi
31         size = 1024
32         aubio_window = window("hanning", size)
33         numpy_window = .5 - .5 * cos(2. * pi * arange(size) / size)
34         assert_almost_equal(aubio_window, numpy_window)
35
36 if __name__ == '__main__':
37     from unittest import main
38     main()