-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_check.py
159 lines (123 loc) · 5.39 KB
/
test_check.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
"""
Run the tests by executing, for all test classes:
$ python -m unittest -v test_check.py
or
$ python test_check.py
"""
import check
import unittest
from typing import Any, Final
class TestArrayType(unittest.TestCase):
def test_GivenANotAnArray_When_arrangement_type_ThenExceptionIsRaised(self):
errors: Final = 'error'
self.assertRaises(TypeError, check.arrangement_type, errors)
class TestIsAnArray(unittest.TestCase):
def test_GivenANotAnArray_When_is_an_arrangement_ThenReturnFalse(self):
errors: Final = 'error'
self.assertFalse(check.is_an_arrangement(errors))
class TestNotEmpty(unittest.TestCase):
def test_GivenAnEmptyArray_When_not_empty_ThenExceptionIsRaised(self):
array: Final[list[Any]] = []
self.assertRaises(ValueError, check.not_empty, array)
def test_GivenANotEmptyArray_When_not_empty_ThenExceptionIsNotRaised(self):
array: Final = [1]
try:
check.not_empty(array)
except ValueError:
self.assertTrue(self, False)
class TestLengthIsEqualToN(unittest.TestCase):
def test_GivenANotEmptyArrayAndNDifferentThanItsSize_When_length_is_equal_to_N_ThenExceptionIsRaised(self):
array: Final = [1, 2, 3]
size: Final = len(array)
n_array: list[int] = []
for i in range(0, size):
n_array.append(i)
for i in range(size + 1, size + 5):
n_array.append(i)
for n in n_array:
self.assertRaises(ValueError, check.length_is_equal_to_n, array, n)
def test_GivenANotEmptyArrayAndNEqualToItsSize_When_length_is_equal_to_N_ThenExceptionIsNotRaised(self):
array: list[int] = []
for i in range(0, 5):
array.append(i)
size = len(array)
n = size
try:
check.length_is_equal_to_n(array, n)
except ValueError:
self.assertTrue(self, False)
class TestLengthIsLessThanN(unittest.TestCase):
def test_GivenANotEmptyArrayAndNLowerOrEqualThanItsSize_When_length_is_less_than_N_ThenExceptionIsRaised(self):
array: list[int] = []
for i in range(0, 5):
array.append(i)
size = len(array)
for n in range(0, size + 1):
self.assertRaises(ValueError, check.length_is_less_than_n, array, n)
def test_GivenANotEmptyArrayAndNGreaterThanItsSize_When_length_is_less_than_N_ThenExceptionIsNotRaised(self):
array: list[int] = []
for i in range(0, 5):
array.append(i)
size = len(array)
for n in range(size + 1, size + 5):
try:
check.length_is_less_than_n(array, n)
except ValueError:
self.assertTrue(self, False)
class TestLengthIsLessOrEqualToN(unittest.TestCase):
def test_GivenANotEmptyArrayAndNGreaterThanItsSize_When_length_is_less_or_equal_to_N_ThenExceptionIsNotRaised(self):
array: list[int] = []
for i in range(0, 5):
array.append(i)
size = len(array)
for n in range(size + 1, size + 5):
try:
check.length_is_less_or_equal_to_n(array, n)
except ValueError:
self.assertTrue(self, False)
def test_GivenANotEmptyArrayAndNLowerOrEqualToItsSize_When_length_is_less_or_equal_to_N_ThenExceptionIsRaised(self):
array: list[int] = []
for i in range(0, 5):
array.append(i)
size = len(array)
for n in range(0, size):
self.assertRaises(ValueError, check.length_is_less_or_equal_to_n, array, n)
class TestLengthIsGreaterThanN(unittest.TestCase):
def test_GivenANotEmptyArrayAndNLowerThanItsSize_When_length_is_greater_than_N_ThenExceptionIsNotRaised(self):
array: list[int] = []
for i in range(0, 5):
array.append(i)
size = len(array)
for n in range(0, size):
try:
check.length_is_greater_than_n(array, n)
except ValueError:
self.assertTrue(self, False)
def test_GivenANotEmptyArrayAndNGreaterOrEqualToItsSize_When_length_is_greater_than_N_ThenExceptionIsRaised(self):
array: list[int] = []
for i in range(0, 5):
array.append(i)
size = len(array)
for n in range(size, size + 5):
self.assertRaises(ValueError, check.length_is_greater_than_n, array, n)
class TestLengthIsGreaterOrEqualToN(unittest.TestCase):
def test_GivenANotEmptyArrayAndNLowerOrEqualToItsSize_When_length_is_greater_or_equal_to_N_ThenExceptionIsNotRaised(
self):
array: list[int] = []
for i in range(0, 5):
array.append(i)
size = len(array)
for n in range(0, size + 1):
try:
check.length_is_greater_or_equal_to_n(array, n)
except ValueError:
self.assertTrue(self, False)
def test_GivenANotEmptyArrayAndNLargerThanItsSize_When_length_is_greater_or_equal_to_N_ThenExceptionIsRaised(self):
array: list[int] = []
for i in range(0, 5):
array.append(i)
size = len(array)
for n in range(size + 1, size + 5):
self.assertRaises(ValueError, check.length_is_greater_or_equal_to_n, array, n)
if __name__ == '__main__':
unittest.main()