-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathunittests.py
executable file
·150 lines (132 loc) · 6 KB
/
unittests.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python
import unittest
from cms50dplus import *
class CMS50DplusTests(unittest.TestCase):
# LIVE DATA
def test_LiveData_init_length(self):
t = datetime.datetime.utcnow()
self.assertRaises(ValueError, LiveDataPoint, t, [0x80,0,0,0])
LiveDataPoint(t, [0x80,0,0,0,0])
def test_LiveData_init_syncbit(self):
t = datetime.datetime.utcnow()
LiveDataPoint(t, [0x80,0,0,0,0])
self.assertRaises(ValueError, LiveDataPoint, t, [0,0,0,0,0])
self.assertRaises(ValueError, LiveDataPoint, t, [0,0x80,0,0,0])
self.assertRaises(ValueError, LiveDataPoint, t, [0,0,0x80,0,0])
self.assertRaises(ValueError, LiveDataPoint, t, [0,0,0,0x80,0])
self.assertRaises(ValueError, LiveDataPoint, t, [0,0,0,0,0x80])
def test_LiveData_signalStrength(self):
t = datetime.datetime.utcnow()
for x in range(16):
y = LiveDataPoint(t, [0x80 | x, 0, 0, 0, 0])
self.assertEquals(y.signalStrength, x)
self.assertEquals(y.getBytes(), [0x80 | x, 0, 0, 0, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_LiveData_fingerOut(self):
t = datetime.datetime.utcnow()
# false
y = LiveDataPoint(t, [0x80, 0, 0, 0, 0])
self.assertFalse(y.fingerOut)
# true
y = LiveDataPoint(t, [0x80 | 0x10, 0, 0, 0, 0])
self.assertTrue(y.fingerOut)
self.assertEquals(y.getBytes(), [0x80 | 0x10, 0, 0, 0, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_LiveData_droppingSpO2(self):
t = datetime.datetime.utcnow()
# false
y = LiveDataPoint(t, [0x80, 0, 0, 0, 0])
self.assertFalse(y.droppingSpO2)
# true
y = LiveDataPoint(t, [0x80 | 0x20, 0, 0, 0, 0])
self.assertTrue(y.droppingSpO2)
self.assertEquals(y.getBytes(), [0x80 | 0x20, 0, 0, 0, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_LiveData_beep(self):
t = datetime.datetime.utcnow()
# false
y = LiveDataPoint(t, [0x80, 0, 0, 0, 0])
self.assertFalse(y.beep)
# true
y = LiveDataPoint(t, [0x80 | 0x40, 0, 0, 0, 0])
self.assertTrue(y.beep)
self.assertEquals(y.getBytes(), [0x80 | 0x40, 0, 0, 0, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_LiveData_pulseWaveform(self):
t = datetime.datetime.utcnow()
for x in range(128):
y = LiveDataPoint(t, [0x80, x, 0, 0, 0])
self.assertEquals(y.pulseWaveform, x)
self.assertEquals(y.getBytes(), [0x80, x, 0, 0, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_LiveData_barGraph(self):
t = datetime.datetime.utcnow()
for x in range(16):
y = LiveDataPoint(t, [0x80, 0, x, 0, 0])
self.assertEquals(y.barGraph, x)
self.assertEquals(y.getBytes(), [0x80, 0, x, 0, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_LiveData_probeError(self):
t = datetime.datetime.utcnow()
# false
y = LiveDataPoint(t, [0x80, 0, 0, 0, 0])
self.assertFalse(y.probeError)
# true
y = LiveDataPoint(t, [0x80, 0, 0x10, 0, 0])
self.assertTrue(y.probeError)
self.assertEquals(y.getBytes(), [0x80, 0, 0x10, 0, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_LiveData_searching(self):
t = datetime.datetime.utcnow()
# false
y = LiveDataPoint(t, [0x80, 0, 0, 0, 0])
self.assertFalse(y.searching)
# true
y = LiveDataPoint(t, [0x80, 0, 0x20, 0, 0])
self.assertTrue(y.searching)
self.assertEquals(y.getBytes(), [0x80, 0, 0x20, 0, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_LiveData_pulseRate(self):
t = datetime.datetime.utcnow()
for x in range(256):
highbit = (x & 0x80) >> 1
lowbits = x & 0x7f
y = LiveDataPoint(t, [0x80, 0, highbit, lowbits, 0])
self.assertEquals(y.pulseRate, x)
self.assertEquals(y.getBytes(), [0x80, 0, highbit, lowbits, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_LiveData_bloodSpO2(self):
t = datetime.datetime.utcnow()
for x in range(128):
y = LiveDataPoint(t, [0x80, 0, 0, 0, x])
self.assertEquals(y.bloodSpO2, x)
self.assertEquals(y.getBytes(), [0x80, 0, 0, 0, x])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
# RECORDED DATA
def test_RecordedData_init_length(self):
t = datetime.datetime.utcnow()
self.assertRaises(IndexError, RecordedDataPoint, t, [0xf0,0x80])
RecordedDataPoint(t, [0xf0, 0x80, 0])
def test_RecordedData_init_syncbits(self):
t = datetime.datetime.utcnow()
self.assertRaises(ValueError, RecordedDataPoint, t, [0,0,0])
self.assertRaises(ValueError, RecordedDataPoint, t, [0xf0,0,0])
self.assertRaises(ValueError, RecordedDataPoint, t, [0,0x80,0])
def test_RecordedData_pulseRate(self):
t = datetime.datetime.utcnow()
for x in range(256):
highbit = (x & 0x80) >> 7
lowbits = x & 0x7f
y = RecordedDataPoint(t, [0xf0 | highbit, 0x80 | lowbits, 0])
self.assertEquals(y.pulseRate, x)
self.assertEquals(y.getBytes(), [0xf0 | highbit, 0x80 | lowbits, 0])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
def test_RecordedData_bloodSpO2(self):
t = datetime.datetime.utcnow()
for x in range(128):
y = RecordedDataPoint(t, [0xf0, 0x80, x])
self.assertEquals(y.bloodSpO2, x)
self.assertEquals(y.getBytes(), [0xf0, 0x80, x])
self.assertEquals(y.__repr__(), eval(y.__repr__()).__repr__())
if __name__ == '__main__':
unittest.main()