Skip to content

Commit d4471c0

Browse files
authored
Merge pull request #107 from The-Motor-Unit/test-decomp
test: final decomp test + minor comment edits
2 parents 54d6d0b + cbeb19c commit d4471c0

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

tests/test_decomposition.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from sklearn.datasets import make_blobs
1313
from sklearn.cluster import KMeans
1414

15-
# Note: Fixtures are special pytest objects calld into individual tests,
15+
# Note: Fixtures are special pytest objects called into individual tests,
1616
# they are useful when data is required to test a function
1717

1818

@@ -442,3 +442,21 @@ def test_silhouette_score():
442442
assert np.isclose(
443443
sil, sil_by_hand
444444
), "Inter and intra distances incorrectly calculated."
445+
446+
def test_decomposition():
447+
"""
448+
Run unit test on decomposition function from EMGdecomPy.
449+
"""
450+
# load data
451+
gl_10 = loadmat("data/raw/GL_10.mat")
452+
raw = gl_10["SIG"]
453+
454+
decompose = emg.decomposition.decomposition(raw, M=3, R=2)
455+
keys = list(decompose.keys())
456+
457+
assert type(decompose) == dict, "Incorrect object returned."
458+
assert keys == ['B', 'MUPulses', 'SIL', 'PNR'], "Incorrect keys returned."
459+
assert type(decompose['B']) == np.ndarray, "Incorrect datatype returned in B key."
460+
assert type(decompose['MUPulses']) == np.ndarray, "Incorrect datatype returned in MUPulses key."
461+
assert type(decompose['SIL']) == np.ndarray, "Incorrect datatype returned in B key."
462+
assert type(decompose['PNR']) == np.ndarray, "Incorrect datatype returned in PNR key."

tests/test_preprocessing.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from emgdecompy import preprocessing as emg
55
import numpy as np
66
from scipy import linalg
7+
from scipy.io import loadmat
78

89
# Test script for all functions defined in src/preprocessing.py
910

@@ -182,6 +183,24 @@ def test_flatten_signal():
182183

183184
# Test that empty channel has been removed
184185
assert (m * n) != flat.shape[0], "Empty array not removed"
186+
187+
def test_butter_bandpass_filter():
188+
"""
189+
Run unit test on butter_bandpass_filter function from EMGdecomPy.
190+
"""
191+
192+
gl_10 = loadmat("data/raw/GL_10.mat")
193+
raw = gl_10["SIG"]
194+
195+
# select two channels from raw data
196+
data = raw[1, 1:3]
197+
198+
d = emg.flatten_signal(data)
199+
x = emg.butter_bandpass_filter(d)
200+
201+
assert type(x) == np.ndarray, "Incorrect datatype returned."
202+
assert x.shape == d.shape, "Incorrect shape returned."
203+
185204

186205

187206
def test_center_matrix():

tests/test_viz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import panel
99
import pytest
1010

11-
# Note: Fixtures are special PyTest objects calld into individual tests,
11+
# Note: Fixtures are special PyTest objects called into individual tests,
1212
# they are useful when data is repeatedly required to test functions
1313

1414

0 commit comments

Comments
 (0)