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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
'''
testsuite.py
Copyright © 2025 Authors. Pls refer to the AUTHORS file
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
import unittest
from lib8 import *
class Testing(unittest.TestCase):
'''
OSD.8.0
Copyright © 2025 Niels Müller Larsen
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_isOdd1(self):
self.assertTrue(isOddInt(1))
def test_isOdd2(self):
import sys
self.assertTrue(isOddInt(sys.maxsize))
def test_isOdd3(self):
self.assertFalse(isOddInt(2**53))
def test_isOdd4(self):
self.assertTrue(isOddInt(2**63-1))
'''
OSD.8.1
Copyright © 2025 PAUL MICKY D COSTA
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_valid_inputs(self):
self.assertEqual(factorial(1), 1)
self.assertEqual(factorial(2), 2)
self.assertEqual(factorial(3), 6)
self.assertEqual(factorial(5), 120)
self.assertEqual(factorial(10), 3628800)
def test_zero_input(self):
self.assertEqual(factorial(0), -1)
def test_negative_input(self):
self.assertEqual(factorial(-5), -1)
def test_non_integer_input(self):
self.assertEqual(factorial(3.5), -1)
self.assertEqual(factorial("5"), -1)
self.assertEqual(factorial(None), -1)
def test_large_input(self):
self.assertEqual(factorial(20), 2432902008176640000)
'''
OSD.8.2
Copyright © 2025 Tania and (formatted by) NML
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_max31(self):
self.assertEqual(max_of_3(1,2,3), 3)
def test_max32(self):
self.assertEqual(max_of_3(10, 5, 7), 10)
def test_max33(self):
self.assertEqual(max_of_3(-1, -5, -3), -1)
def test_max34(self):
self.assertEqual(max_of_3(7, 7, 7), 7)
def test_max35(self):
self.assertEqual(max_of_3(100, 1000, 10), 1000)
'''
OSD.8.3
Copyright © 2025 Navneet and (formatted by) NML
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_word_freq0(self):
dic = {}
s = 'This is a test. This test is only a test.'
res = {
'this': 2,
'is': 2,
'a': 2,
'test': 3,
'only': 1,
}
self.assertEqual(word_freq(s.lower(), dic), res)
'''
OSD.8.4
Copyright © 2025 PAUL MICKY D COSTA
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_basic_dictionary(self):
dic = {"apple": 2, "banana": 3, "orange": 1}
expected = {"apple", "banana", "orange"}
self.assertEqual(unique_words(dic), expected)
def test_empty_dictionary(self):
self.assertEqual(unique_words({}), set())
def test_single_word(self):
self.assertEqual(unique_words({"hello": 10}), {"hello"})
def test_non_dict_input(self):
self.assertEqual(unique_words(None), set())
self.assertEqual(unique_words(["apple", "banana"]), set())
self.assertEqual(unique_words("notadict"), set())
'''
OSD.8.5
Copyright © 2025 SUSHIL THAPA
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_is_perfect1(self):
# 6 = 1 + 2 + 3
self.assertTrue(is_perfect(6))
def test_is_perfect2(self):
# 28 = 1 + 2 + 4 + 7 + 14
self.assertTrue(is_perfect(28))
def test_is_perfect3(self):
# 496 is a known perfect number
self.assertTrue(is_perfect(496))
def test_is_perfect4(self):
# 12 is not a perfect number
self.assertFalse(is_perfect(12))
def test_is_perfect5(self):
# 1 has no proper divisors
self.assertFalse(is_perfect(1))
def test_is_perfect6(self):
# 0 is not a perfect number
self.assertFalse(is_perfect(0))
'''
OSD.8.6
Copyright © 2025 PAUL MICKY D COSTA
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_v2p_metric(self):
self.assertEqual(v2p(15, 'metric'), (4, 0)) # 15 km/h = 4:00 min/km
self.assertEqual(v2p(12, 'metric'), (5, 0)) # 12 km/h = 5:00 min/km
self.assertEqual(v2p(11, 'metric'), (5, 27.272727272727252)) # 11 km/h = 5:27 min/km
self.assertEqual(v2p(6, 'metric'), (10, 0)) # 6 km/h = 10:00 min/km
self.assertEqual(v2p(0, 'metric'), (0, 0)) # edge case
def test_v2p_imperial(self):
self.assertEqual(v2p(12, 'imperial'), (5, 0)) # 12 mph = 5:00 min/mile
self.assertEqual(v2p(8, 'imperial'), (7, 30)) # 8 mph = 7:30 min/mile
self.assertEqual(v2p(4, 'imperial'), (15, 0)) # 4 mph = 15:00 min/mile
self.assertEqual(v2p(0, 'imperial'), (0, 0)) # edge case
def test_p2v_metric(self):
self.assertAlmostEqual(p2v((5, 0), 'metric'), 12.0)
self.assertAlmostEqual(p2v((5, 27.273), 'metric'), 11.0, 1)
self.assertAlmostEqual(p2v((10, 0), 'metric'), 6.0)
self.assertAlmostEqual(p2v((0, 0), 'metric'), 0.0)
def test_p2v_imperial(self):
self.assertAlmostEqual(p2v((5, 0), 'imperial'), 12.0)
self.assertAlmostEqual(p2v((7, 30), 'imperial'), 8.0)
self.assertAlmostEqual(p2v((15, 0), 'imperial'), 4.0)
self.assertAlmostEqual(p2v((0, 0), 'imperial'), 0.0)
# one test of second param removed by NML
'''
OSD.8.7
Copyright © 2025 Tania and (formatted by) NML
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_entropy1(self):
self.assertEqual(password_entropy('password'), 47.818239387999334)
def test_entropy2(self):
self.assertEqual(password_entropy('Password123'), 65.75007915849908)
def test_entropy3(self):
self.assertEqual(password_entropy('P@ssw0rd!'), 53.79551931149925)
def test_entropy4(self):
self.assertEqual(password_entropy(''), 0.0)
def test_entropy5(self):
self.assertEqual(password_entropy(' '), 11.954559846999834)
def test_entropy6(self):
self.assertEqual(password_entropy('123456'), 35.8636795409995)
def test_entropy7(self):
self.assertEqual(password_entropy('A'), 5.977279923499917)
def test_entropy8(self):
self.assertEqual(password_entropy('!@#$%^'), 35.8636795409995)
def test_entropy9(self):
self.assertTrue(password_entropy('abracadabraABR') > 80) # l = 14
def test_entropyA(self):
self.assertFalse(password_entropy('abracadabraABRACA', N = 26) > 80) # l = 17
'''
OSD.8.8
Copyright © 2025 Navneet and (formatted by) NML
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_interest1(self):
a = 1000
t = 3
i = 5
self.assertEqual(acc_interest(a, t, i), 1157.6250000000002)
'''
OSD.8.9
Copyright © 2025 PAUL MICKY D COSTA
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_standard_radii(self):
import math
self.assertAlmostEqual(vol_sphere(1), (4/3) * math.pi * 1**3)
self.assertAlmostEqual(vol_sphere(2), (4/3) * math.pi * 8)
self.assertAlmostEqual(vol_sphere(3), (4/3) * math.pi * 27)
def test_zero_radius(self):
self.assertEqual(vol_sphere(0), 0.0)
def test_negative_radius(self):
self.assertEqual(vol_sphere(-5), -1)
def test_large_radius(self):
self.assertAlmostEqual(vol_sphere(10), (4/3) * math.pi * 1000)
'''
OSD.8.10
Copyright © 2025 SUSHIL THAPA
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_distance1(self):
p1 = Point(0, 0)
p2 = Point(3, 4)
self.assertEqual(p1.distance(p2), 5)
def test_distance2(self):
p1 = Point(1, 1)
p2 = Point(1, 1)
self.assertEqual(p1.distance(p2), 0)
def test_distance3(self):
p1 = Point(-1, -1)
p2 = Point(2, 3)
self.assertAlmostEqual(p1.distance(p2), 5.0)
def test_distance4(self):
p1 = Point(5, 0)
p2 = Point(0, 12)
self.assertEqual(p1.distance(p2), 13)
def test_distance5(self):
p1 = Point(-3, 4)
p2 = Point(3, -4)
self.assertAlmostEqual(p1.distance(p2), 10.0)
'''
OSD.8.11
Copyright © 2025 NML.
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_geopoint0(self):
g= GeoPoint(56.15674, 10.21076) # Aarhus
o = GeoPoint(55.67594, 12.56553) # Copenhagen
self.assertEqual(g.distance(o), 156.65774019967023)
def test_geopoint1(self):
g= GeoPoint(52.2296756, 21.0122287)
o = GeoPoint(52.406374, 16.9251681)
self.assertEqual(g.distance(o), 279.35290160430094)
'''
OSD.8.12
Copyright © 2025 Tania and (formatted by) NML
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_acronym1(self):
self.assertEqual(acronym('random access memory'), 'RAM')
def test_acronym2(self):
self.assertEqual(acronym('central processing unit'), 'CPU')
def test_acronym3(self):
self.assertEqual(acronym('graphics processing unit'), 'GPU')
def test_acronym4(self):
self.assertEqual(acronym('self contained underwater breathing apparatus'), 'SCUBA')
def test_acronym5(self):
self.assertEqual(acronym(' national aeronautics space administration '), 'NASA')
def test_acronym6(self):
self.assertEqual(acronym(''), '')
def test_acronym7(self):
self.assertEqual(acronym('hello'), 'H')
'''
OSD.8.13
Copyright © 2025 Navneet and (formatted by) NML
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_numerology1(self):
self.assertEqual(numerologize('John Doe'), 71)
def test_numerology2(self):
self.assertEqual(numerologize('Niels'), 59)
'''
OSD.8.14
Copyright © 2025 PAUL MICKY D COSTA
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_caesarE0(self):
# Test case where the input is 'Jacta est alea' and the key is 3
self.assertEqual(caesarE('Jacta est alea', 3), 'MDFWDHVWDOHD')
def test_caesarE1(self):
# Test case where the input is 'hello world' and the key is 5
self.assertEqual(caesarE('hello world', 5), 'MJQQT1TWQI')
def test_caesarE2(self):
# Test case where the input is 'ABC' and the key is 1
self.assertEqual(caesarE('ABC', 1), 'BCD')
def test_caesarE3(self):
# Test case where the input is 'XYZ' and the key is 4
self.assertEqual(caesarE('XYZ', 4), '123')
def test_caesarE4(self):
# Test case with no alphabetic characters
self.assertEqual(caesarE('123 456!@#', 3), '456789')
def test_caesarE5(self):
# Test case where the input is 'TEST' and the key is 26 (full rotation)
self.assertEqual(caesarE('TEST', 36), 'TEST')
def test_caesarE6(self):
self.assertEqual(caesarE('PYTHON', 10), 'Z83RYX')
'''
OSD.8.15
Copyright © 2025 SUSHIL THAPA
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_caesarD1(self):
self.assertEqual(caesarD('MDFWDHVWDOHD', 3), 'JACTAESTALEA')
def test_caesarD2(self):
self.assertEqual(caesarD('MJQQT1TWQI', 5), 'HELLOWORLD')
def test_caesarD3(self):
self.assertEqual(caesarD('Z83RYX', 10), 'PYTHON')
def test_caesarD4(self):
self.assertEqual(caesarD('CAESARCIPHER', 0), 'CAESARCIPHER')
def test_caesarD5(self):
self.assertEqual(caesarD('SAMETEXTSAMEKEY', 36), 'SAMETEXTSAMEKEY')
def test_caesarD6(self):
self.assertEqual(caesarD('BMQIBCFU', 1), 'ALPHABET')
'''
OSD.8.16
Copyright © 2025 NML
Licensed under the BSD-3 License,
please refer to the LICENSE document
'''
def test_wc0(self):
self.assertEqual(wc('abc\ndef'), (2, 2, 8))
if __name__ == '__main__':
unittest.main()
|