Mercurial > hg > plosone_underreview
comparison tests/test_PitchBihist.py @ 85:9b2beffa5fdd branch-tests
test updates
author | Maria Panteli <m.x.panteli@gmail.com> |
---|---|
date | Tue, 26 Sep 2017 21:19:19 +0100 |
parents | 0e70021f251e |
children |
comparison
equal
deleted
inserted
replaced
84:027945e93211 | 85:9b2beffa5fdd |
---|---|
6 """ | 6 """ |
7 | 7 |
8 import pytest | 8 import pytest |
9 | 9 |
10 import numpy as np | 10 import numpy as np |
11 import os | |
11 | 12 |
12 import scripts.PitchBihist as PitchBihist | 13 import scripts.PitchBihist as PitchBihist |
13 | 14 |
14 | 15 |
15 pbi = PitchBihist.PitchBihist() | 16 pbi = PitchBihist.PitchBihist() |
16 | 17 TEST_MELODIA_FILE = os.path.join(os.path.dirname(__file__), os.path.pardir, |
18 'data', 'sample_dataset', 'Melodia', 'mel_1_2_1.csv') | |
17 | 19 |
18 def test_hz_to_cents(): | 20 def test_hz_to_cents(): |
19 freq_Hz = np.array([32.703, 65.406, 55, 110]) | 21 freq_Hz = np.array([32.703, 65.406, 55, 110]) |
20 freq_cents = pbi.hz_to_cents(freq_Hz) | 22 freq_cents = pbi.hz_to_cents(freq_Hz) |
21 freq_cents_true = np.array([0, 1200, 900, 2100]) | 23 freq_cents_true = np.array([0, 1200, 900, 2100]) |
28 octave_cents_true = np.array([900, 900, 0]) | 30 octave_cents_true = np.array([900, 900, 0]) |
29 assert np.array_equal(octave_cents, octave_cents_true) | 31 assert np.array_equal(octave_cents, octave_cents_true) |
30 | 32 |
31 | 33 |
32 def test_get_melody_from_file(): | 34 def test_get_melody_from_file(): |
33 melodia_file = 'data/sample_dataset/Melodia/mel_1_2_1.csv' | 35 melodia_file = TEST_MELODIA_FILE |
34 melody = pbi.get_melody_from_file(melodia_file) | 36 melody = pbi.get_melody_from_file(melodia_file) |
35 assert len(melody) < 12. * pbi.melody_sr | 37 assert len(melody) < 12. * pbi.melody_sr |
36 | 38 |
37 | 39 |
38 def test_get_melody_matrix(): | 40 def test_get_melody_matrix(): |
54 # for 16-sec segment with .5 hop size expect ~16 frames round up | 56 # for 16-sec segment with .5 hop size expect ~16 frames round up |
55 assert nframes == 17 | 57 assert nframes == 17 |
56 | 58 |
57 | 59 |
58 def test_bihist_from_melodia(): | 60 def test_bihist_from_melodia(): |
59 melodia_file = 'data/sample_dataset/Melodia/mel_1_2_1.csv' | 61 melodia_file = TEST_MELODIA_FILE |
60 bihist = pbi.bihist_from_melodia(melodia_file, secondframedecomp=False) | 62 bihist = pbi.bihist_from_melodia(melodia_file, secondframedecomp=False) |
61 assert bihist.shape == (60, 60) | 63 assert bihist.shape == (60, 60) |
62 | 64 |
63 | 65 |
64 def test_bihist_from_melodia_n_frames(): | 66 def test_bihist_from_melodia_n_frames(): |
65 melodia_file = 'data/sample_dataset/Melodia/mel_1_2_1.csv' | 67 melodia_file = TEST_MELODIA_FILE |
66 bihist = pbi.bihist_from_melodia(melodia_file, secondframedecomp=True) | 68 bihist = pbi.bihist_from_melodia(melodia_file, secondframedecomp=True) |
67 dur_sec = 11.5 # duration of first file in metadata.csv is > 11 seconds | 69 dur_sec = 11.5 # duration of first file in metadata.csv is > 11 seconds |
68 n_frames_true = np.round((dur_sec - pbi.win2sec) * 2) # for .5 sec hop size | 70 n_frames_true = np.round((dur_sec - pbi.win2sec) * 2) # for .5 sec hop size |
69 assert bihist.shape[1] == n_frames_true | 71 assert bihist.shape[1] == n_frames_true |
70 | 72 |