-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestIntegerExhaustion.py
More file actions
42 lines (32 loc) · 1.42 KB
/
TestIntegerExhaustion.py
File metadata and controls
42 lines (32 loc) · 1.42 KB
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
import unittest
import sys
def process_integer(n):
""" Example function that squares the input integer if it's valid. """
if not isinstance(n, int):
raise ValueError("Input must be an integer")
return n * n
class TestIntegerExhaustion(unittest.TestCase):
def test_integer_exhaustion(self):
""" Tests integer input using exhaustion for large ranges. """
min_test_value = -sys.maxsize - 1 # Equivalent to int.min in many cases
max_test_value = sys.maxsize # Equivalent to int.max
# Test extreme values
self.assertEqual(process_integer(min_test_value), min_test_value ** 2)
self.assertEqual(process_integer(max_test_value), max_test_value ** 2)
# Test smaller sample range to avoid excessive runtime
for i in range(-1000, 1001):
with self.subTest(i=i):
self.assertEqual(process_integer(i), i * i)
# Test common edge cases
self.assertEqual(process_integer(0), 0)
self.assertEqual(process_integer(1), 1)
self.assertEqual(process_integer(-1), 1)
# Test non-integer inputs
with self.assertRaises(ValueError):
process_integer("string")
with self.assertRaises(ValueError):
process_integer(5.5)
with self.assertRaises(ValueError):
process_integer(None)
if __name__ == '__main__':
unittest.main()