[5810ed4] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
[1a6ef2c] | 3 | from numpy.testing import TestCase, run_module_suite |
---|
| 4 | from numpy.testing import assert_equal, assert_almost_equal |
---|
[4c01c0f] | 5 | from aubio import cvec |
---|
[1a6ef2c] | 6 | from numpy import array, shape, pi |
---|
| 7 | |
---|
| 8 | class aubio_cvec_test_case(TestCase): |
---|
| 9 | |
---|
| 10 | def test_vector_created_with_zeroes(self): |
---|
| 11 | a = cvec(10) |
---|
| 12 | a |
---|
| 13 | shape(a.norm) |
---|
| 14 | shape(a.phas) |
---|
| 15 | a.norm[0] |
---|
| 16 | assert_equal(a.norm, 0.) |
---|
| 17 | assert_equal(a.phas, 0.) |
---|
| 18 | |
---|
| 19 | def test_vector_assign_element(self): |
---|
| 20 | a = cvec() |
---|
| 21 | a.norm[0] = 1 |
---|
| 22 | assert_equal(a.norm[0], 1) |
---|
| 23 | a.phas[0] = 1 |
---|
| 24 | assert_equal(a.phas[0], 1) |
---|
| 25 | |
---|
| 26 | def test_vector_assign_element_end(self): |
---|
| 27 | a = cvec() |
---|
| 28 | a.norm[-1] = 1 |
---|
| 29 | assert_equal(a.norm[-1], 1) |
---|
| 30 | assert_equal(a.norm[len(a.norm)-1], 1) |
---|
| 31 | a.phas[-1] = 1 |
---|
| 32 | assert_equal(a.phas[-1], 1) |
---|
| 33 | assert_equal(a.phas[len(a.phas)-1], 1) |
---|
| 34 | |
---|
| 35 | def test_assign_cvec_norm_slice(self): |
---|
| 36 | spec = cvec(1024) |
---|
| 37 | spec.norm[40:100] = 100 |
---|
| 38 | assert_equal (spec.norm[0:40], 0) |
---|
| 39 | assert_equal (spec.norm[40:100], 100) |
---|
| 40 | assert_equal (spec.norm[100:-1], 0) |
---|
| 41 | assert_equal (spec.phas, 0) |
---|
| 42 | |
---|
| 43 | def test_assign_cvec_phas_slice(self): |
---|
| 44 | spec = cvec(1024) |
---|
| 45 | spec.phas[39:-1] = -pi |
---|
| 46 | assert_equal (spec.phas[0:39], 0) |
---|
| 47 | assert_equal (spec.phas[39:-1], -pi) |
---|
| 48 | assert_equal (spec.norm, 0) |
---|
| 49 | |
---|
| 50 | if __name__ == '__main__': |
---|
| 51 | from unittest import main |
---|
| 52 | main() |
---|