Skip to content

Commit c415cad

Browse files
committed
tests for spectral_coverage and filter_width_factor
1 parent cc88592 commit c415cad

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
pip install -e .[testing]
3737
- name: Lint with flake8
3838
run: |
39-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
39+
flake8 . --count --select=E9,F63,F7 --show-source --statistics
4040
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4141
- name: Test with pytest
4242
run: |

slab/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import pathlib
44

5-
__version__ = '1.7.0'
5+
__version__ = '1.8.0'
66

77
# The variable _in_notebook is used to enable audio playing in Jupiter notebooks
88
# and on Google colab (see slab.sound.play())

tests/test_filter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ def test_cos_filterbank():
6767
length = numpy.random.randint(1000, 5000)
6868
low_cutoff = numpy.random.randint(0, 500)
6969
high_cutoff = numpy.random.choice([numpy.random.randint(5000, 15000), None])
70+
filter_width_factor = numpy.random.uniform(0.1, 2.5)
7071
n_filters = []
7172
for bandwidth in numpy.linspace(0.1, 0.9, 9):
72-
fbank = slab.Filter.cos_filterbank(length=length, bandwidth=bandwidth, low_cutoff=low_cutoff, high_cutoff=high_cutoff, pass_bands=False, samplerate=sound.samplerate)
73+
fbank = slab.Filter.cos_filterbank(length=length, bandwidth=bandwidth,
74+
filter_width_factor=filter_width_factor,
75+
low_cutoff=low_cutoff, high_cutoff=high_cutoff,
76+
pass_bands=False, samplerate=sound.samplerate)
7377
n_filters.append(fbank.n_filters)
7478
filtsound = fbank.apply(sound)
7579
assert filtsound.n_channels == fbank.n_filters

tests/test_sounds.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_sound_generation():
3030
# test if .name attribute of loaded sound object is the path string
3131
assert loaded1.name == f"{tmpdir / 'sound.wav'}"
3232

33+
3334
def test_read_write():
3435
for _ in range(20):
3536
for normalize in [True, False]:
@@ -99,3 +100,11 @@ def test_frames():
99100
center1 = window[frame_dur][0]
100101
center2 = sound[numpy.where(sound.times == center)[0][0]][0]
101102
numpy.testing.assert_almost_equal(center1, center2, decimal=1)
103+
104+
105+
def test_spectral_coverage():
106+
sig1 = slab.Sound.harmoniccomplex(f0=50, amplitude=[0,0,0])
107+
sig2 = slab.Sound.harmoniccomplex(f0=50, amplitude=[0,0,0,0,0])
108+
sig3 = slab.Sound.pinknoise()
109+
assert sig1.spectral_coverage(threshold='otsu') < sig2.spectral_coverage(threshold='otsu')
110+
assert sig2.spectral_coverage() < sig3.spectral_coverage()

0 commit comments

Comments
 (0)