-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunitTests.py
179 lines (157 loc) · 4.59 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python3
# Import standard modules ...
import unittest
# Import special modules ...
try:
import numpy
except:
raise Exception("\"numpy\" is not installed; run \"pip install --user numpy\"") from None
# Import my modules ...
try:
import pyguymer3
except:
raise Exception("\"pyguymer3\" is not installed; run \"pip install --user PyGuymer3\"") from None
# Define a test case ...
class MyTestCase(unittest.TestCase):
"""
Test the module "pyguymer3"
"""
# Define a test ...
def test_convertBytesToPrettyBytes(self):
"""
Test the function "pyguymer3.convert_bytes_to_pretty_bytes()"
"""
self.assertSequenceEqual(
pyguymer3.convert_bytes_to_pretty_bytes(16.0 * 1024.0 * 1024.0),
(16.0, "MiB"),
)
# Define a test ...
def test_convertPrettyBytesToBytes(self):
"""
Test the function "pyguymer3.convert_pretty_bytes_to_bytes()"
"""
self.assertEqual(
pyguymer3.convert_pretty_bytes_to_bytes("16.0 MiB"),
16.0 * 1024.0 * 1024.0,
)
# Define a test ...
def test_convertSecondsToPrettyTime(self):
"""
Test the function "pyguymer3.convert_seconds_to_pretty_time()"
"""
self.assertEqual(
pyguymer3.convert_seconds_to_pretty_time(7326.311),
"2h 2m 6.3s",
)
# Define a test ...
def test_findIntegerDivisors(self):
"""
Test the function "pyguymer3.find_integer_divisors()"
"""
self.assertSequenceEqual(
pyguymer3.find_integer_divisors(12),
[2, 3, 4, 6],
)
# Define a test ...
def test_interpolate(self):
"""
Test the function "pyguymer3.interpolate()"
"""
self.assertEqual(
pyguymer3.interpolate(1.0, 3.0, 2.0, 4.0, 2.0),
3.0,
)
# Define a test ...
def test_intersection(self):
"""
Test the function "pyguymer3.intersection()"
"""
self.assertSequenceEqual(
pyguymer3.intersection(
(1.0, 3.0),
(3.0, 1.0),
(1.0, 1.0),
(3.0, 3.0),
).tolist(),
[2.0, 2.0],
)
# Define a test ...
def test_makePathSafe(self):
"""
Test the function "pyguymer3.make_path_safe()"
"""
self.assertEqual(
pyguymer3.make_path_safe(".what do you think of this path?", allowHidden = True),
".what do you think of this path",
)
self.assertEqual(
pyguymer3.make_path_safe(".what do you think of this path?", allowHidden = False),
"what do you think of this path",
)
# Define a test ...
def test_stats(self):
"""
Test the statistical functions "pyguymer3.mean()", "pyguymer3.var()",
"pyguymer3.stddev()" and "pyguymer3.stderr()"
"""
# Create datasets ...
# NOTE: See the "Worked examples" section of https://en.wikipedia.org/wiki/Student's_t-test
arr1 = numpy.array(
[
30.02,
29.99,
30.11,
29.97,
30.01,
29.99,
],
dtype = numpy.float64,
)
arr2 = numpy.array(
[
29.89,
29.93,
29.72,
29.98,
30.02,
29.98,
],
dtype = numpy.float64,
)
self.assertAlmostEqual(
pyguymer3.mean(arr1),
30.015,
)
self.assertAlmostEqual(
pyguymer3.var(arr1),
2.058333333333355e-3,
)
self.assertAlmostEqual(
pyguymer3.stddev(arr1),
4.536885862938757e-2,
)
self.assertAlmostEqual(
pyguymer3.stderr(arr1),
2.028957039137771e-2,
)
self.assertAlmostEqual(
pyguymer3.mean(arr2),
29.92,
)
self.assertAlmostEqual(
pyguymer3.var(arr2),
9.700000000000071e-3,
)
self.assertAlmostEqual(
pyguymer3.stddev(arr2),
9.848857801796140e-2,
)
self.assertAlmostEqual(
pyguymer3.stderr(arr2),
4.404543109109064e-2,
)
# Use the proper idiom in the main module ...
# NOTE: See https://docs.python.org/3.12/library/multiprocessing.html#the-spawn-and-forkserver-start-methods
if __name__ == "__main__":
# Run the tests ...
unittest.main()