-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestDataCapture.py
152 lines (117 loc) · 5.28 KB
/
TestDataCapture.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
151
152
from DataCapture import DataCapture, Stats
import pytest
def build_test_data(data: list[int]) -> list[DataCapture, Stats]:
'''Instantiate and populate a DataCapture and returns it with a Stats object in a list for testing'''
capture = DataCapture()
for n in data:
capture.add(n)
stats = capture.build_stats()
return [capture, stats]
class TestDataCapture:
[capture, stats] = build_test_data([3,9,3,4,6])
# input validations:
def test_type_error_str_one(self):
'''capture.add() must receive an int ("a" is not an int)'''
with pytest.raises(TypeError):
self.capture.add('a')
def test_type_error_float_one(self):
'''capture.add() must receive an int (1.1 is not an int)'''
with pytest.raises(TypeError):
self.capture.add(1.1)
class TestStats:
[capture1, stats1] = build_test_data([3,9,3,4,6])
# input validations:
def test_type_error_str_one(self):
'''stats1.less() must receive an int ("a" is not an int)'''
with pytest.raises(TypeError):
self.stats1.less('a')
def test_type_error_str_two(self):
'''stats1.between() must receive integers ("a" is not an int)'''
with pytest.raises(TypeError):
self.stats1.between('a', 1)
def test_type_error_str_three(self):
'''stats1.greater() must receive an int ("a" is not an int)'''
with pytest.raises(TypeError):
self.stats1.greater('a')
def test_type_error_float_one(self):
'''stats1.less() must receive an int (1.1 is not an int)'''
with pytest.raises(TypeError):
self.stats1.less(1.1)
def test_type_error_float_two(self):
'''stats1.between() must receive integers (1.1 is not an int)'''
with pytest.raises(TypeError):
self.stats1.between(1.1, 1)
def test_type_error_float_three(self):
'''stats1.greater() must receive an int (1.1 is not an int)'''
with pytest.raises(TypeError):
self.stats1.greater(1.1)
def test_less_lower_limit(self):
'''stats1.less() must receive an int n such as 0 <= n < 1000'''
with pytest.raises(ValueError):
self.stats1.less(-1)
def test_less_higher_limit(self):
'''stats1.less() must receive an int n such as 0 <= n < 1000'''
with pytest.raises(ValueError):
self.stats1.less(1000)
def test_between_lower_limit(self):
'''stats1.between() must receive integers n such as 0 <= n < 1000'''
with pytest.raises(ValueError):
self.stats1.between(-1, 4)
def test_between_higher_limit(self):
'''stats1.between() must receive integers n such as 0 <= n < 1000'''
with pytest.raises(ValueError):
self.stats1.between(4, 1000)
def test_between_swiched_args(self):
'''stats1.between(n, m) must receive integers n and m such as n <= m'''
with pytest.raises(ValueError):
self.stats1.between(7, 4)
def test_greater_lower_limit(self):
'''stats1.greater() must receive an int n such as 0 <= n < 1000'''
with pytest.raises(ValueError):
self.stats1.greater(-1)
def test_greater_higher_limit(self):
'''stats1.greater() must receive an int n such as 0 <= n < 1000'''
with pytest.raises(ValueError):
self.stats1.greater(1000)
# value tests:
def test_less_one(self):
'''Should return 2 (only two values 3, 3 are less than 4)'''
assert (self.stats1.less(4) == 2)
def test_between_one(self):
'''Should return 4 (3, 3, 4 and 6 are between 3 and 6)'''
assert (self.stats1.between(3, 6) == 4)
def test_between_two(self):
'''Should return 4 (3, 3, 4 and 6 are between 3 and 6)'''
assert (self.stats1.between(3, 6) == 4)
def test_greater_one(self):
'''Should return 2 (6 and 9 are the only two values greater than 4)'''
assert (self.stats1.greater(4) == 2)
[capture2, stats2] = build_test_data([3, 3, 3, 3])
def test_less_two(self):
'''Should return 0 (none are less than 3)'''
assert (self.stats2.less(3) == 0)
def test_between_three(self):
'''Should return 4 (3, 3, 3 and 3 are between 3 and 3)'''
assert (self.stats2.between(3, 3) == 4)
def test_between_four(self):
'''Should return 0 (none are between 4 and 6)'''
assert (self.stats2.between(4, 6) == 0)
def test_greater_two(self):
'''Should return 0 (none are greater than 3)'''
assert (self.stats2.greater(3) == 0)
[capture3, stats3] = build_test_data([0, 1, 2, 3, 3, 999, 600, 0, 5])
def test_less_three(self):
'''Should return 7 (0, 1, 2, 3, 3, 0 and 5 are less than 500)'''
assert (self.stats3.less(500) == 7)
def test_less_four(self):
'''Should return 0 (none are less than 0)'''
assert (self.stats3.less(0) == 0)
def test_between_five(self):
'''Should return 9 (all are between 0 and 999)'''
assert (self.stats3.between(0, 999) == 9)
def test_between_six(self):
'''Should return 1 (1 is between 1 and 1)'''
assert (self.stats3.between(1, 1) == 1)
def test_greater_three(self):
'''Should return 2 (600 and 999 are greater than 500)'''
assert (self.stats3.greater(500) == 2)