Skip to content

Commit 3c4b7f1

Browse files
authored
add tests for detectors (#9)
1 parent 9f627d3 commit 3c4b7f1

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

systole/detectors/engelse_zeelenberg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,4 @@ def numba_two(sfreq: int, low_pass, signal: np.ndarray) -> np.ndarray:
154154
# removing the 1st detection as it 1st needs the QRS complex amplitude for the threshold
155155
r_peaks.pop(0)
156156

157-
return r_peaks
157+
return np.array(r_peaks)

systole/detectors/hamilton.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ def numba_third(ma, b, sfreq):
125125

126126
QRS.pop(0)
127127

128-
return QRS
128+
return np.array(QRS)

tests/test_detectors.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import unittest
44
from unittest import TestCase
55

6-
from systole import import_ppg
7-
from systole.detectors import msptd
6+
from systole import import_ppg, import_dataset1
7+
from systole.detectors import msptd, moving_average, pan_tompkins, hamilton, christov, engelse_zeelenberg
88

9+
signal_df = import_dataset1(modalities=["ECG"])[: 20 * 2000]
910

1011
class TestDetectors(TestCase):
1112
def test_msptd(self):
@@ -17,6 +18,31 @@ def test_msptd(self):
1718
assert (peaks_onsets[0] == peaks).all()
1819
assert (peaks_onsets[1] == onsets).all()
1920

21+
def test_moving_average(self):
22+
"""Test moving average function"""
23+
peaks = moving_average(signal=signal_df.ecg.to_numpy(), sfreq=1000)
24+
assert peaks.sum() == 1037313
25+
26+
def test_pan_tompkins(self):
27+
"""Test moving average function"""
28+
peaks = pan_tompkins(signal=signal_df.ecg.to_numpy(), sfreq=1000)
29+
assert peaks.sum() == 1038115
30+
31+
def test_hamilton(self):
32+
"""Test moving average function"""
33+
peaks = hamilton(signal=signal_df.ecg.to_numpy(), sfreq=1000)
34+
assert peaks.sum() == 1066453
35+
36+
def test_christov(self):
37+
"""Test moving average function"""
38+
peaks = christov(signal=signal_df.ecg.to_numpy(), sfreq=1000)
39+
assert peaks.sum() == 1037238
40+
41+
def test_engelse_zeelenberg(self):
42+
"""Test moving average function"""
43+
peaks = engelse_zeelenberg(signal=signal_df.ecg.to_numpy(), sfreq=1000)
44+
assert peaks.sum() == 1036188
45+
2046

2147
if __name__ == "__main__":
2248
unittest.main(argv=["first-arg-is-ignored"], exit=False)

0 commit comments

Comments
 (0)