Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -1,10 +1,8 @@ | |||
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | 2 | ||
| 3 | from numpy.testing import TestCase, run_module_suite | 3 | from numpy.testing import TestCase |
| 4 | from numpy.testing import assert_equal, assert_almost_equal | 4 | from numpy.testing import assert_equal, assert_almost_equal |
| 5 | from numpy import random | 5 | import numpy as np |
| 6 | from math import pi | ||
| 7 | from numpy import array | ||
| 8 | from aubio import cvec, filterbank, float_type | 6 | from aubio import cvec, filterbank, float_type |
| 9 | from utils import array_from_text_file | 7 | from utils import array_from_text_file |
| 10 | 8 | ||
| @@ -16,14 +14,14 @@ class aubio_filterbank_test_case(TestCase): · 5 unmodified lines | |||
| 16 | 14 | ||
| 17 | def test_set_coeffs(self): | 15 | def test_set_coeffs(self): |
| 18 | f = filterbank(40, 512) | 16 | f = filterbank(40, 512) |
| 19 | r = random.random([40, int(512 / 2) + 1]).astype(float_type) | 17 | r = np.random.random([40, int(512 / 2) + 1]).astype(float_type) |
| 20 | f.set_coeffs(r) | 18 | f.set_coeffs(r) |
| 21 | assert_equal (r, f.get_coeffs()) | 19 | assert_equal (r, f.get_coeffs()) |
| 22 | 20 | ||
| 23 | def test_phase(self): | 21 | def test_phase(self): |
| 24 | f = filterbank(40, 512) | 22 | f = filterbank(40, 512) |
| 25 | c = cvec(512) | 23 | c = cvec(512) |
| 26 | c.phas[:] = pi | 24 | c.phas[:] = np.pi |
| 27 | assert_equal( f(c), 0); | 25 | assert_equal( f(c), 0); |
| 28 | 26 | ||
| 29 | def test_norm(self): | 27 | def test_norm(self): |
| @@ -35,16 +33,17 @@ class aubio_filterbank_test_case(TestCase): · 5 unmodified lines | |||
| 35 | def test_random_norm(self): | 33 | def test_random_norm(self): |
| 36 | f = filterbank(40, 512) | 34 | f = filterbank(40, 512) |
| 37 | c = cvec(512) | 35 | c = cvec(512) |
| 38 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type) | 36 | c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type) |
| 39 | assert_equal( f(c), 0) | 37 | assert_equal( f(c), 0) |
| 40 | 38 | ||
| 41 | def test_random_coeffs(self): | 39 | def test_random_coeffs(self): |
| 42 | f = filterbank(40, 512) | 40 | win_s = 128 |
| 43 | c = cvec(512) | 41 | f = filterbank(40, win_s) |
| 44 | r = random.random([40, int(512 / 2) + 1]).astype(float_type) | 42 | c = cvec(win_s) |
| 43 | r = np.random.random([40, int(win_s / 2) + 1]).astype(float_type) | ||
| 45 | r /= r.sum() | 44 | r /= r.sum() |
| 46 | f.set_coeffs(r) | 45 | f.set_coeffs(r) |
| 47 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type) | 46 | c.norm[:] = np.random.random((int(win_s / 2) + 1,)).astype(float_type) |
| 48 | assert_equal ( f(c) < 1., True ) | 47 | assert_equal ( f(c) < 1., True ) |
| 49 | assert_equal ( f(c) > 0., True ) | 48 | assert_equal ( f(c) > 0., True ) |
| 50 | 49 | ||
| @@ -52,7 +51,7 @@ class aubio_filterbank_test_case(TestCase): · 1 unmodified line | |||
| 52 | f = filterbank(40, 512) | 51 | f = filterbank(40, 512) |
| 53 | c = cvec(512) | 52 | c = cvec(512) |
| 54 | f.set_mel_coeffs_slaney(44100) | 53 | f.set_mel_coeffs_slaney(44100) |
| 55 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type) | 54 | c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type) |
| 56 | assert_equal ( f(c) < 1., True ) | 55 | assert_equal ( f(c) < 1., True ) |
| 57 | assert_equal ( f(c) > 0., True ) | 56 | assert_equal ( f(c) > 0., True ) |
| 58 | 57 | ||
| @@ -63,6 +62,6 @@ class aubio_filterbank_test_case(TestCase): · 4 unmodified lines | |||
| 63 | assert_almost_equal ( expected, f.get_coeffs() ) | 62 | assert_almost_equal ( expected, f.get_coeffs() ) |
| 64 | 63 | ||
| 65 | if __name__ == '__main__': | 64 | if __name__ == '__main__': |
| 66 | from unittest import main | 65 | from nose2 import main |
| 67 | main() | 66 | main() |
| 68 | 67 | ||