/
test_hrmData.py
130 lines (110 loc) · 4.38 KB
/
test_hrmData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import pytest
def test_subtractDCOffset():
from hrmData import hrmData
from readData import readData
from timeSegment import timeSegment
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset)
subtractedOffsetValues = [-0.027071875, -0.002071875, 0.029178125,
0.054178125, 0.079178125]
assert hrmObject.meanSubtractedVoltage[0:5] == \
pytest.approx(subtractedOffsetValues)
def test_determineLagTime():
from hrmData import hrmData
from readData import readData
from timeSegment import timeSegment
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset)
actualHR = 80
assert 0.9*actualHR < hrmObject.heartRateList[0] < 1.1*actualHR
assert 0.9*actualHR < hrmObject.heartRateList[1] < 1.1*actualHR
assert 0.9*actualHR < hrmObject.heartRateList[2] < 1.1*actualHR
assert 0.9*actualHR < hrmObject.heartRateList[3] < 1.1*actualHR
assert 0.9*actualHR < hrmObject.heartRateList[4] < 1.1*actualHR
assert 0.9*actualHR < hrmObject.heartRateList[5] < 1.1*actualHR
def test_intervalHR():
from hrmData import hrmData
from readData import readData
from timeSegment import timeSegment
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset)
actualHR = 84.38818565400844
assert pytest.approx(hrmObject.global_mean_hr_bpm) == 84.38818565400844
hrmObject2 = hrmData(myDataset, 2, 8)
assert pytest.approx(hrmObject.global_mean_hr_bpm) == 84.38818565400844
def test_convertTimeToIdx():
from hrmData import hrmData
from readData import readData
from timeSegment import timeSegment
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset)
startIdx1 = 0
endIdx1 = 6
assert startIdx1 == hrmObject.startIdx
assert endIdx1 == hrmObject.endIdx
hrmObject2 = hrmData(myDataset, 2, 8)
startIdx2 = 1
endIdx2 = 4
assert startIdx2 == hrmObject2.startIdx
assert endIdx2 == hrmObject2.endIdx
def test_voltage_extremes():
from hrmData import hrmData
from readData import readData
from timeSegment import timeSegment
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset)
maxMinValue = (0.7875, -0.19375)
assert pytest.approx(hrmObject.voltage_extremes) == maxMinValue
def test_num_beats():
from hrmData import hrmData
from readData import readData
from timeSegment import timeSegment
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset)
numBeatsin31 = 19
assert numBeatsin31*0.8 < hrmObject.num_beats < numBeatsin31*1.2
def test_time_of_beats():
from hrmData import hrmData
from readData import readData
from timeSegment import timeSegment
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset)
locationOfBeats = [0., 0.7715, 1.543, 2.3145, 3.086, 3.8575, 4.629,
5.4005, 6.172, 6.9435, 7.715, 8.4865, 9.258, 10.0295,
10.801, 11.5725, 12.344, 13.1155, 13.887]
assert locationOfBeats == pytest.approx(hrmObject.beats)
@pytest.mark.xfail
def test_write_json():
from main import main
from hrmData import hrmData
from readData import readData
import json
from timeSegment import timeSegment
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset)
main()
data = {'File Name': hrmObject.rawData.csvFileName,
'mean_hr_bpm': hrmObject.mean_hr_bpm,
'voltage_extremes': hrmObject.voltage_extremes,
'duration': hrmObject.duration,
'num_beats': hrmObject.num_beats,
'beats': hrmObject.beats}
with open('test_data31.json') as data_file:
data_loaded = json.load(data_file)
data_loaded_list = data_loaded.items()
data_list = data.items()
assert data_loaded_list == data_list
def test_raise_exceptions():
from hrmData import hrmData
from readData import readData
from timeSegment import timeSegment
with pytest.raises(ValueError):
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset, 1, 4)
with pytest.raises(ValueError):
myDataset = readData("test_data31.csv")
hrmObject = hrmData(myDataset, 2, 5)
# with pytest.raises(ValueError):
# myDataset = readData("test_data31.csv")
# hrmObject = hrmData(myDataset)
# hrmObject.timeSegment = 1.5