Showing the changes to python/tests (5 of 5 files). Show all
Unified · Split
| @@ -16,7 +16,7 @@ class aubio_filterbank_test_case(TestCase): · 15 unmodified lines | |||
| 16 | 16 | ||
| 17 | def test_set_coeffs(self): | 17 | def test_set_coeffs(self): |
| 18 | f = filterbank(40, 512) | 18 | f = filterbank(40, 512) |
| 19 | r = random.random([40, 512 / 2 + 1]).astype('float32') | 19 | r = random.random([40, int(512 / 2) + 1]).astype('float32') |
| 20 | f.set_coeffs(r) | 20 | f.set_coeffs(r) |
| 21 | assert_equal (r, f.get_coeffs()) | 21 | assert_equal (r, f.get_coeffs()) |
| 22 | 22 | ||
| @@ -35,16 +35,16 @@ class aubio_filterbank_test_case(TestCase): · 12 unmodified lines | |||
| 35 | def test_random_norm(self): | 35 | def test_random_norm(self): |
| 36 | f = filterbank(40, 512) | 36 | f = filterbank(40, 512) |
| 37 | c = cvec(512) | 37 | c = cvec(512) |
| 38 | c.norm[:] = random.random((512 / 2 + 1,)).astype('float32') | 38 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32') |
| 39 | assert_equal( f(c), 0) | 39 | assert_equal( f(c), 0) |
| 40 | 40 | ||
| 41 | def test_random_coeffs(self): | 41 | def test_random_coeffs(self): |
| 42 | f = filterbank(40, 512) | 42 | f = filterbank(40, 512) |
| 43 | c = cvec(512) | 43 | c = cvec(512) |
| 44 | r = random.random([40, 512 / 2 + 1]).astype('float32') | 44 | r = random.random([40, int(512 / 2) + 1]).astype('float32') |
| 45 | r /= r.sum() | 45 | r /= r.sum() |
| 46 | f.set_coeffs(r) | 46 | f.set_coeffs(r) |
| 47 | c.norm[:] = random.random((512 / 2 + 1,)).astype('float32') | 47 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32') |
| 48 | assert_equal ( f(c) < 1., True ) | 48 | assert_equal ( f(c) < 1., True ) |
| 49 | assert_equal ( f(c) > 0., True ) | 49 | assert_equal ( f(c) > 0., True ) |
| 50 | 50 | ||
| @@ -52,7 +52,7 @@ class aubio_filterbank_test_case(TestCase): · 1 unmodified line | |||
| 52 | f = filterbank(40, 512) | 52 | f = filterbank(40, 512) |
| 53 | c = cvec(512) | 53 | c = cvec(512) |
| 54 | f.set_mel_coeffs_slaney(44100) | 54 | f.set_mel_coeffs_slaney(44100) |
| 55 | c.norm[:] = random.random((512 / 2 + 1,)).astype('float32') | 55 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32') |
| 56 | assert_equal ( f(c) < 1., True ) | 56 | assert_equal ( f(c) < 1., True ) |
| 57 | assert_equal ( f(c) > 0., True ) | 57 | assert_equal ( f(c) > 0., True ) |
| 58 | 58 | ||
| @@ -69,7 +69,7 @@ class freq2note_simple_test(unittest.TestCase): · 68 unmodified lines | |||
| 69 | 69 | ||
| 70 | def test_freq2note(self): | 70 | def test_freq2note(self): |
| 71 | " make sure freq2note(441) == A4 " | 71 | " make sure freq2note(441) == A4 " |
| 72 | self.assertEquals("A4", freq2note(441)) | 72 | self.assertEqual("A4", freq2note(441)) |
| 73 | 73 | ||
| 74 | if __name__ == '__main__': | 74 | if __name__ == '__main__': |
| 75 | unittest.main() | 75 | unittest.main() |
| @@ -30,7 +30,7 @@ class aubio_pvoc_test_case(TestCase): · 29 unmodified lines | |||
| 30 | win_s, hop_s = 1024, 256 | 30 | win_s, hop_s = 1024, 256 |
| 31 | f = pvoc (win_s, hop_s) | 31 | f = pvoc (win_s, hop_s) |
| 32 | t = fvec (hop_s) | 32 | t = fvec (hop_s) |
| 33 | for time in range( 4 * win_s / hop_s ): | 33 | for time in range( int ( 4 * win_s / hop_s ) ): |
| 34 | s = f(t) | 34 | s = f(t) |
| 35 | r = f.rdo(s) | 35 | r = f.rdo(s) |
| 36 | assert_equal ( array(t), 0) | 36 | assert_equal ( array(t), 0) |
| @@ -22,24 +22,24 @@ class zero_crossing_rate_test_case(TestCase): · 21 unmodified lines | |||
| 22 | 22 | ||
| 23 | def test_impulse(self): | 23 | def test_impulse(self): |
| 24 | """ check zero crossing rate on a buffer with an impulse """ | 24 | """ check zero crossing rate on a buffer with an impulse """ |
| 25 | self.vector[buf_size / 2] = 1. | 25 | self.vector[int(buf_size / 2)] = 1. |
| 26 | self.assertEqual(0., zero_crossing_rate(self.vector)) | 26 | self.assertEqual(0., zero_crossing_rate(self.vector)) |
| 27 | 27 | ||
| 28 | def test_negative_impulse(self): | 28 | def test_negative_impulse(self): |
| 29 | """ check zero crossing rate on a buffer with a negative impulse """ | 29 | """ check zero crossing rate on a buffer with a negative impulse """ |
| 30 | self.vector[buf_size / 2] = -1. | 30 | self.vector[int(buf_size / 2)] = -1. |
| 31 | self.assertEqual(2./buf_size, zero_crossing_rate(self.vector)) | 31 | self.assertEqual(2./buf_size, zero_crossing_rate(self.vector)) |
| 32 | 32 | ||
| 33 | def test_single(self): | 33 | def test_single(self): |
| 34 | """ check zero crossing rate on single crossing """ | 34 | """ check zero crossing rate on single crossing """ |
| 35 | self.vector[buf_size / 2 - 1] = 1. | 35 | self.vector[int(buf_size / 2) - 1] = 1. |
| 36 | self.vector[buf_size / 2] = -1. | 36 | self.vector[int(buf_size / 2)] = -1. |
| 37 | self.assertEqual(2./buf_size, zero_crossing_rate(self.vector)) | 37 | self.assertEqual(2./buf_size, zero_crossing_rate(self.vector)) |
| 38 | 38 | ||
| 39 | def test_single_with_gap(self): | 39 | def test_single_with_gap(self): |
| 40 | """ check zero crossing rate on single crossing with a gap""" | 40 | """ check zero crossing rate on single crossing with a gap""" |
| 41 | self.vector[buf_size / 2 - 2] = 1. | 41 | self.vector[int(buf_size / 2) - 2] = 1. |
| 42 | self.vector[buf_size / 2] = -1. | 42 | self.vector[int(buf_size / 2)] = -1. |
| 43 | self.assertEqual(2./buf_size, zero_crossing_rate(self.vector)) | 43 | self.assertEqual(2./buf_size, zero_crossing_rate(self.vector)) |
| 44 | 44 | ||
| 45 | if __name__ == '__main__': | 45 | if __name__ == '__main__': |
| @@ -4,8 +4,10 @@ def array_from_text_file(filename, dtype = 'float'): · 3 unmodified lines | |||
| 4 | import os.path | 4 | import os.path |
| 5 | from numpy import array | 5 | from numpy import array |
| 6 | filename = os.path.join(os.path.dirname(__file__), filename) | 6 | filename = os.path.join(os.path.dirname(__file__), filename) |
| 7 | return array([line.split() for line in open(filename).readlines()], | 7 | with open(filename) as f: |
| 8 | dtype = dtype) | 8 | lines = f.readlines() |
| 9 | return array([line.split() for line in lines], | ||
| 10 | dtype = dtype) | ||
| 9 | 11 | ||
| 10 | def list_all_sounds(rel_dir): | 12 | def list_all_sounds(rel_dir): |
| 11 | import os.path, glob | 13 | import os.path, glob |