Skip to content

Commit

Permalink
increased coverage for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhammonds committed Jun 26, 2020
1 parent cbea586 commit 922a4bf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions neurodsp/tests/test_filt_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@ def test_check_filter_definition():
def test_check_filter_properties():

filter_coefs = design_fir_filter(FS, 'bandpass', (8, 12))
check_filter_properties(filter_coefs, 1, FS, 'bandpass', (8, 12))
assert True

passes = check_filter_properties(filter_coefs, 1, FS, 'bandpass', (8, 12))
assert passes is True

filter_coefs = design_fir_filter(FS, 'bandstop', (8, 12))
passes = check_filter_properties(filter_coefs, 1, FS, 'bandpass', (8, 12))
assert passes is False

filter_coefs = design_fir_filter(FS, 'bandpass', (20, 21))
passes = check_filter_properties(filter_coefs, 1, FS, 'bandpass', (8, 12))
assert passes is False


def test_check_filter_length():

Expand Down
5 changes: 5 additions & 0 deletions neurodsp/tests/test_filt_fir.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for FIR filters."""

from pytest import raises
import numpy as np

from neurodsp.tests.settings import FS
Expand Down Expand Up @@ -56,3 +57,7 @@ def test_compute_filter_length():
expected_filt_len = int(np.ceil(fs * n_cycles / f_lo)) + 1
filt_len = compute_filter_length(fs, 'bandpass', f_lo, f_hi, n_cycles=n_cycles, n_seconds=None)
assert filt_len == expected_filt_len

with raises(ValueError):
filt_len = compute_filter_length(fs, 'bandpass', f_lo, f_hi)

3 changes: 3 additions & 0 deletions neurodsp/tests/test_filt_iir.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def test_filter_signal_iir_2d(tsig2d):
assert out.shape == tsig2d.shape
assert sum(~np.isnan(out[0, :])) > 0

out, sos = filter_signal_iir(tsig2d, FS, 'bandpass', (8, 12), 3, return_filter=True)
assert np.shape(sos)[1] == 6

def test_apply_iir_filter(tsig):

out = apply_iir_filter(tsig, np.array([1, 1, 1, 1, 1, 1]))
Expand Down
4 changes: 4 additions & 0 deletions neurodsp/tests/test_filt_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for filter utilities."""

from pytest import raises
from neurodsp.tests.settings import FS

from neurodsp.filt.utils import *
Expand All @@ -19,6 +20,9 @@ def test_compute_frequency_response():
filter_coefs = design_fir_filter(FS, 'bandpass', (8, 12))
f_db, db = compute_frequency_response(filter_coefs, 1, FS)

with raises(ValueError):
f_db, db = compute_frequency_response(filter_coefs, None, FS)

def test_compute_pass_band():

assert compute_pass_band(FS, 'bandpass', (4, 8)) == 4.
Expand Down

0 comments on commit 922a4bf

Please sign in to comment.