1
|
|
|
""" |
2
|
|
|
:mod:`tests.unit.test_digital` -- Unit Tests |
3
|
|
|
============================================ |
4
|
|
|
|
5
|
|
|
.. module:: tests.unit.test_digital |
6
|
|
|
:synopsis: Unit tests for the lib.digital module. |
7
|
|
|
|
8
|
|
|
.. moduleauthor:: Bill Maroney <[email protected]> |
9
|
|
|
""" |
10
|
|
|
|
11
|
|
|
from typing import List, Union |
12
|
|
|
import pytest |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class TestDigitSum(object): |
|
|
|
|
16
|
|
|
""" A collection of positive and negative unit tests for the :func:`lib.digital.digit_sum` function """ |
|
|
|
|
17
|
|
|
|
18
|
|
|
@classmethod |
19
|
|
|
def get_import(cls): |
20
|
|
|
""" Get and return the :func:`lib.digital.digit_sum` function |
21
|
|
|
|
22
|
|
|
.. note:: this isolates the import so any error/exception is raised by individual unit tests. |
|
|
|
|
23
|
|
|
|
24
|
|
|
:return: the :func:`lib.digital.digit_sum` function |
25
|
|
|
""" |
26
|
|
|
from lib.digital import digit_sum |
27
|
|
|
return digit_sum |
28
|
|
|
|
29
|
|
|
@pytest.mark.parametrize("value,expected_answer", [(0, 0), (9, 9), (11, 2), (123, 6), (654321, 21)]) |
|
|
|
|
30
|
|
|
def test_digit_sum_correctness(self, value: int, expected_answer: int): |
31
|
|
|
""" Test the correctness of :func:`lib.digital.digit_sum` using known answer tests |
32
|
|
|
|
33
|
|
|
:param value: the input value |
34
|
|
|
:param expected_answer: the expected answer |
35
|
|
|
:raises AssertionError: if :func:`lib.digital.digit_sum` returns the wrong type |
36
|
|
|
:raises AssertionError: if :func:`lib.digital.digit_sum` returns the wrong value |
37
|
|
|
""" |
38
|
|
|
|
39
|
|
|
digit_sum = self.get_import() |
40
|
|
|
computed_answer = digit_sum(value) |
41
|
|
|
assert isinstance(computed_answer, digit_sum.__annotations__["return"]), "wrong type" |
42
|
|
|
assert computed_answer == expected_answer, "wrong answer" |
43
|
|
|
|
44
|
|
|
def test_digit_sum_bad_n_type_str(self): |
45
|
|
|
""" Test that :func:`lib.digital.digit_sum` raises a ``TypeError`` for a non-``int`` value for `n` (``str``) """ |
|
|
|
|
46
|
|
|
digit_sum = self.get_import() |
47
|
|
|
with pytest.raises(TypeError): |
48
|
|
|
digit_sum("123") |
49
|
|
|
|
50
|
|
|
def test_digit_sum_bad_n_type_float(self): |
51
|
|
|
""" Test that :func:`lib.digital.digit_sum` raises a ``TypeError`` for a non-``int`` value for `n` (``float``) |
|
|
|
|
52
|
|
|
""" |
53
|
|
|
digit_sum = self.get_import() |
54
|
|
|
with pytest.raises(TypeError): |
55
|
|
|
digit_sum(123.0) |
56
|
|
|
|
57
|
|
|
def test_digit_sum_bad_n_negative(self): |
58
|
|
|
""" Test that :func:`lib.digital.digit_sum` raises a ``ValueError`` for a negative value for `n` """ |
|
|
|
|
59
|
|
|
digit_sum = self.get_import() |
60
|
|
|
with pytest.raises(ValueError): |
61
|
|
|
digit_sum(-123) |
62
|
|
|
|
63
|
|
|
def test_digit_sum_bad_base_type_str(self): |
|
|
|
|
64
|
|
|
""" Test that :func:`lib.digital.digit_sum` raises a ``TypeError`` for a non-``int`` value for `base` (``str``) |
|
|
|
|
65
|
|
|
""" |
66
|
|
|
digit_sum = self.get_import() |
67
|
|
|
with pytest.raises(TypeError): |
68
|
|
|
digit_sum(123, base="2") |
69
|
|
|
|
70
|
|
|
def test_digit_sum_bad_base_type_float(self): |
|
|
|
|
71
|
|
|
""" Test that :func:`lib.digital.digit_sum` raises a ``TypeError`` for a non-``int`` value for `base` |
|
|
|
|
72
|
|
|
(``float``) |
73
|
|
|
""" |
74
|
|
|
digit_sum = self.get_import() |
75
|
|
|
with pytest.raises(TypeError): |
76
|
|
|
digit_sum(123, base=2.0) |
77
|
|
|
|
78
|
|
|
def test_digit_sum_bad_base_negative(self): |
|
|
|
|
79
|
|
|
""" Test that :func:`lib.digital.digit_sum` raises a ``ValueError`` for a negative value for `base` """ |
|
|
|
|
80
|
|
|
digit_sum = self.get_import() |
81
|
|
|
with pytest.raises(ValueError): |
82
|
|
|
digit_sum(123, base=-2) |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
class TestNumDigits(object): |
|
|
|
|
86
|
|
|
""" A collection of positive and negative unit tests for the :func:`lib.digital.num_digits` function """ |
|
|
|
|
87
|
|
|
|
88
|
|
|
@classmethod |
89
|
|
|
def get_import(cls): |
90
|
|
|
""" Get and return the :func:`lib.digital.num_digits` function |
91
|
|
|
|
92
|
|
|
.. note:: this isolates the import so any error/exception is raised by individual unit tests. |
|
|
|
|
93
|
|
|
|
94
|
|
|
:return: the :func:`lib.digital.num_digits` function |
95
|
|
|
""" |
96
|
|
|
from lib.digital import num_digits |
97
|
|
|
return num_digits |
98
|
|
|
|
99
|
|
|
@pytest.mark.parametrize("value,expected_answer", |
100
|
|
|
[(0, 1), (9, 1), (10, 2), (55, 2), (99, 2), (100, 3), (999, 3), (1000, 4)]) |
|
|
|
|
101
|
|
|
def test_num_digits_correctness_kat(self, value: int, expected_answer: int): |
102
|
|
|
""" Test the correctness of :func:`lib.digital.num_digits` using known answer tests |
103
|
|
|
|
104
|
|
|
:param value: the input value |
105
|
|
|
:param expected_answer: the expected answer |
106
|
|
|
:raises AssertionError: if :func:`lib.digital.num_digits` returns the wrong type |
107
|
|
|
:raises AssertionError: if :func:`lib.digital.num_digits` returns the wrong value |
108
|
|
|
""" |
109
|
|
|
|
110
|
|
|
num_digits = self.get_import() |
111
|
|
|
computed_answer = num_digits(value) |
112
|
|
|
assert isinstance(computed_answer, num_digits.__annotations__["return"]), "wrong type" |
113
|
|
|
assert computed_answer == expected_answer, "wrong answer" |
114
|
|
|
|
115
|
|
|
def test_num_digits_correctness_random(self): |
|
|
|
|
116
|
|
|
""" Test the correctness of :func:`lib.digital.num_digits` using random inputs with predictable answers |
|
|
|
|
117
|
|
|
|
118
|
|
|
That is, generate a random length (`n`) and a random integer of that length (`x`). Then, check that |
|
|
|
|
119
|
|
|
:func:`lib.digital.num_digits` evaluated at `x` equals `n`. |
120
|
|
|
|
121
|
|
|
:raises AssertionError: if :func:`lib.digital.num_digits` returns the wrong type |
122
|
|
|
:raises AssertionError: if :func:`lib.digital.num_digits` returns the wrong value |
123
|
|
|
""" |
124
|
|
|
|
125
|
|
|
from random import randint |
126
|
|
|
num_digits = self.get_import() |
127
|
|
|
for i in range(1000): # a moderate but arbitrary number of random tests |
|
|
|
|
128
|
|
|
digit_len = randint(1, 50) # a moderate but arbitrary length (n) |
129
|
|
|
random_integer = randint(10 ** (digit_len - 1), 10 ** digit_len - 1) # the random number (x) |
|
|
|
|
130
|
|
|
computed_answer = num_digits(random_integer) |
131
|
|
|
assert isinstance(computed_answer, num_digits.__annotations__["return"]), "wrong type" |
132
|
|
|
assert computed_answer == digit_len, "wrong answer" |
133
|
|
|
|
134
|
|
|
def test_num_digits_bad_n_type_str(self): |
135
|
|
|
""" Test that :func:`lib.digital.num_digits` raises a ``TypeError`` for a non-``int`` value for `n` (``str``) |
|
|
|
|
136
|
|
|
""" |
137
|
|
|
num_digits = self.get_import() |
138
|
|
|
with pytest.raises(TypeError): |
139
|
|
|
num_digits("123") |
140
|
|
|
|
141
|
|
|
def test_num_digits_bad_n_type_float(self): |
|
|
|
|
142
|
|
|
""" Test that :func:`lib.digital.num_digits` raises a ``TypeError`` for a non-``int`` value for `n` (``float``) |
|
|
|
|
143
|
|
|
""" |
144
|
|
|
num_digits = self.get_import() |
145
|
|
|
with pytest.raises(TypeError): |
146
|
|
|
num_digits(123.0) |
147
|
|
|
|
148
|
|
|
def test_num_digits_bad_n_negative(self): |
149
|
|
|
""" Test that :func:`lib.digital.num_digits` raises a ``ValueError`` for a negative value for `n` """ |
|
|
|
|
150
|
|
|
num_digits = self.get_import() |
151
|
|
|
with pytest.raises(ValueError): |
152
|
|
|
num_digits(-123) |
153
|
|
|
|
154
|
|
|
def test_num_digits_bad_base_type_str(self): |
|
|
|
|
155
|
|
|
""" Test that :func:`lib.digital.num_digits` raises a ``TypeError`` for a non-``int`` value for `base` (``str``) |
|
|
|
|
156
|
|
|
""" |
157
|
|
|
num_digits = self.get_import() |
158
|
|
|
with pytest.raises(TypeError): |
159
|
|
|
num_digits(123, base="2") |
160
|
|
|
|
161
|
|
|
def test_num_digits_bad_base_type_float(self): |
|
|
|
|
162
|
|
|
""" Test that :func:`lib.digital.num_digits` raises a ``TypeError`` for a non-``int`` value for `base` |
|
|
|
|
163
|
|
|
(``float``) |
164
|
|
|
""" |
165
|
|
|
num_digits = self.get_import() |
166
|
|
|
with pytest.raises(TypeError): |
167
|
|
|
num_digits(123, base=2.0) |
168
|
|
|
|
169
|
|
|
def test_num_digits_bad_base_negative(self): |
|
|
|
|
170
|
|
|
""" Test that :func:`lib.digital.num_digits` raises a ``ValueError`` for a negative value for `base` """ |
|
|
|
|
171
|
|
|
num_digits = self.get_import() |
172
|
|
|
with pytest.raises(ValueError): |
173
|
|
|
num_digits(123, base=-2) |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
class TestIsPandigital(object): |
|
|
|
|
177
|
|
|
""" A collection of positive and negative unit tests for the :func:`lib.digital.is_pandigital` function """ |
|
|
|
|
178
|
|
|
|
179
|
|
|
@classmethod |
180
|
|
|
def get_import(cls): |
181
|
|
|
""" Get and return the :func:`lib.digital.is_pandigital` function |
182
|
|
|
|
183
|
|
|
.. note:: this isolates the import so any error/exception is raised by individual unit tests. |
|
|
|
|
184
|
|
|
|
185
|
|
|
:return: the :func:`lib.digital.is_pandigital` function |
186
|
|
|
""" |
187
|
|
|
from lib.digital import is_pandigital |
188
|
|
|
return is_pandigital |
189
|
|
|
|
190
|
|
|
@pytest.mark.parametrize("value,d,expected_answer", |
191
|
|
|
[(123, 3, True), (200, 3, False), (123, 4, False), ([1, 25, 43], 5, True), |
|
|
|
|
192
|
|
|
([1, 2, 2], 3, False), ([1, 2, 3, 4], 3, False)]) |
193
|
|
|
def test_is_pandigital_correctness(self, value: Union[int, List[int]], d: int, expected_answer: int): |
|
|
|
|
194
|
|
|
""" Test the correctness of :func:`lib.digital.is_pandigital` using known answer tests |
195
|
|
|
|
196
|
|
|
:param value: the input value |
197
|
|
|
:param d: parameter in `d`-pandigital |
198
|
|
|
:param expected_answer: the expected answer |
199
|
|
|
:raises AssertionError: if :func:`lib.digital.is_pandigital` returns the wrong type |
200
|
|
|
:raises AssertionError: if :func:`lib.digital.is_pandigital` returns the wrong value |
201
|
|
|
""" |
202
|
|
|
|
203
|
|
|
is_pandigital = self.get_import() |
204
|
|
|
computed_answer = is_pandigital(value, d) |
205
|
|
|
assert isinstance(computed_answer, is_pandigital.__annotations__["return"]), "wrong type" |
206
|
|
|
assert computed_answer == expected_answer, "wrong answer" |
207
|
|
|
|
208
|
|
|
def test_is_pandigital_bad_int_n_type_str(self): |
|
|
|
|
209
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `n` (``str``) |
|
|
|
|
210
|
|
|
""" |
211
|
|
|
is_pandigital = self.get_import() |
212
|
|
|
with pytest.raises(TypeError): |
213
|
|
|
is_pandigital("123", 3) |
214
|
|
|
|
215
|
|
|
def test_is_pandigital_bad_int_n_type_float(self): |
|
|
|
|
216
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `n` |
|
|
|
|
217
|
|
|
(``float``) |
218
|
|
|
""" |
219
|
|
|
is_pandigital = self.get_import() |
220
|
|
|
with pytest.raises(TypeError): |
221
|
|
|
is_pandigital(123.0, 3) |
222
|
|
|
|
223
|
|
|
def test_is_pandigital_bad_list_n_type_str(self): |
|
|
|
|
224
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `n` (``str``) |
|
|
|
|
225
|
|
|
""" |
226
|
|
|
is_pandigital = self.get_import() |
227
|
|
|
with pytest.raises(TypeError): |
228
|
|
|
is_pandigital([1, 2, "3"], 3) |
229
|
|
|
|
230
|
|
|
def test_is_pandigital_bad_list_n_type_float(self): |
|
|
|
|
231
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `n` |
|
|
|
|
232
|
|
|
(``float``) |
233
|
|
|
""" |
234
|
|
|
is_pandigital = self.get_import() |
235
|
|
|
with pytest.raises(TypeError): |
236
|
|
|
is_pandigital([1, 2.3], 3) |
237
|
|
|
|
238
|
|
|
def test_is_pandigital_bad_int_n_negative(self): |
|
|
|
|
239
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `n` """ |
|
|
|
|
240
|
|
|
is_pandigital = self.get_import() |
241
|
|
|
with pytest.raises(ValueError): |
242
|
|
|
is_pandigital(-123, 3) |
243
|
|
|
|
244
|
|
|
def test_is_pandigital_bad_list_n_negative(self): |
|
|
|
|
245
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `n` """ |
|
|
|
|
246
|
|
|
is_pandigital = self.get_import() |
247
|
|
|
with pytest.raises(ValueError): |
248
|
|
|
is_pandigital([-1, 2, 3], 3) |
249
|
|
|
|
250
|
|
|
def test_is_pandigital_bad_d_type_str(self): |
|
|
|
|
251
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `d` (``str``) |
|
|
|
|
252
|
|
|
""" |
253
|
|
|
is_pandigital = self.get_import() |
254
|
|
|
with pytest.raises(TypeError): |
255
|
|
|
is_pandigital(123, "3") |
256
|
|
|
|
257
|
|
|
def test_is_pandigital_bad_d_type_float(self): |
|
|
|
|
258
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `d` |
|
|
|
|
259
|
|
|
(``float``) |
260
|
|
|
""" |
261
|
|
|
is_pandigital = self.get_import() |
262
|
|
|
with pytest.raises(TypeError): |
263
|
|
|
is_pandigital(123, 3.0) |
264
|
|
|
|
265
|
|
|
def test_is_pandigital_bad_d_negative(self): |
|
|
|
|
266
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `d` """ |
|
|
|
|
267
|
|
|
is_pandigital = self.get_import() |
268
|
|
|
with pytest.raises(ValueError): |
269
|
|
|
is_pandigital(123, -3) |
270
|
|
|
|
271
|
|
|
def test_is_pandigital_bad_lower_type_str(self): |
|
|
|
|
272
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `lower` |
|
|
|
|
273
|
|
|
(``str``) |
274
|
|
|
""" |
275
|
|
|
is_pandigital = self.get_import() |
276
|
|
|
with pytest.raises(TypeError): |
277
|
|
|
is_pandigital([1, 2, 3], 3, lower="10") |
278
|
|
|
|
279
|
|
|
def test_is_pandigital_bad_lower_type_float(self): |
|
|
|
|
280
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `lower` |
|
|
|
|
281
|
|
|
(``float``) |
282
|
|
|
""" |
283
|
|
|
is_pandigital = self.get_import() |
284
|
|
|
with pytest.raises(TypeError): |
285
|
|
|
is_pandigital([1, 2, 3], 3, lower=10.0) |
286
|
|
|
|
287
|
|
|
def test_is_pandigital_bad_lower_negative(self): |
|
|
|
|
288
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `lower` """ |
|
|
|
|
289
|
|
|
is_pandigital = self.get_import() |
290
|
|
|
with pytest.raises(ValueError): |
291
|
|
|
is_pandigital(123, 3, lower=-10) |
292
|
|
|
|
293
|
|
|
def test_is_pandigital_bad_base_type_str(self): |
|
|
|
|
294
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `base` |
|
|
|
|
295
|
|
|
(``str``) |
296
|
|
|
""" |
297
|
|
|
is_pandigital = self.get_import() |
298
|
|
|
with pytest.raises(TypeError): |
299
|
|
|
is_pandigital(123, 3, base="10") |
300
|
|
|
|
301
|
|
|
def test_is_pandigital_bad_base_type_float(self): |
|
|
|
|
302
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `base` |
|
|
|
|
303
|
|
|
(``float``) |
304
|
|
|
""" |
305
|
|
|
is_pandigital = self.get_import() |
306
|
|
|
with pytest.raises(TypeError): |
307
|
|
|
is_pandigital(123, 3, base=2.0) |
308
|
|
|
|
309
|
|
|
def test_is_pandigital_bad_base_negative(self): |
|
|
|
|
310
|
|
|
""" Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `base` """ |
|
|
|
|
311
|
|
|
is_pandigital = self.get_import() |
312
|
|
|
with pytest.raises(ValueError): |
313
|
|
|
is_pandigital(123, 3, base=-10) |
314
|
|
|
|
315
|
|
|
|
316
|
|
|
class TestIsPalindrome(object): |
|
|
|
|
317
|
|
|
""" A collection of positive and negative unit tests for the :func:`lib.digital.is_palindrome` function """ |
|
|
|
|
318
|
|
|
|
319
|
|
|
@classmethod |
320
|
|
|
def get_import(cls): |
321
|
|
|
""" Get and return the :func:`lib.digital.is_palindrome` function |
322
|
|
|
|
323
|
|
|
.. note:: this isolates the import so any error/exception is raised by individual unit tests. |
|
|
|
|
324
|
|
|
|
325
|
|
|
:return: the :func:`lib.digital.is_palindrome` function |
326
|
|
|
""" |
327
|
|
|
from lib.digital import is_palindrome |
328
|
|
|
return is_palindrome |
329
|
|
|
|
330
|
|
|
@pytest.mark.parametrize("value,base,expected_answer", [(121, 10, True), (123, 10, False), (5, 2, True)]) |
|
|
|
|
331
|
|
|
def test_is_palindrome_correctness(self, value: int, base: int, expected_answer: int): |
332
|
|
|
""" Test the correctness of :func:`lib.digital.is_palindrome` using known answer tests |
333
|
|
|
|
334
|
|
|
:param value: the input value |
335
|
|
|
:param base: consider `value` in the given `base` |
336
|
|
|
:param expected_answer: the expected answer |
337
|
|
|
:raises AssertionError: if :func:`lib.digital.is_palindrome` returns the wrong type |
338
|
|
|
:raises AssertionError: if :func:`lib.digital.is_palindrome` returns the wrong value |
339
|
|
|
""" |
340
|
|
|
|
341
|
|
|
is_palindrome = self.get_import() |
342
|
|
|
computed_answer = is_palindrome(value, base=base) |
343
|
|
|
assert isinstance(computed_answer, is_palindrome.__annotations__["return"]), "wrong type" |
344
|
|
|
assert computed_answer == expected_answer, "wrong answer" |
345
|
|
|
|
346
|
|
|
def test_is_palindrome_bad_n_type_str(self): |
|
|
|
|
347
|
|
|
""" Test that :func:`lib.digital.is_palindrome` raises a ``TypeError`` for a non-``int`` value for `n` (``str``) |
|
|
|
|
348
|
|
|
""" |
349
|
|
|
is_palindrome = self.get_import() |
350
|
|
|
with pytest.raises(TypeError): |
351
|
|
|
is_palindrome("123") |
352
|
|
|
|
353
|
|
|
def test_is_palindrome_bad_n_type_float(self): |
|
|
|
|
354
|
|
|
""" Test that :func:`lib.digital.is_palindrome` raises a ``TypeError`` for a non-``int`` value for `n` |
|
|
|
|
355
|
|
|
(``float``) |
356
|
|
|
""" |
357
|
|
|
is_palindrome = self.get_import() |
358
|
|
|
with pytest.raises(TypeError): |
359
|
|
|
is_palindrome(123.0) |
360
|
|
|
|
361
|
|
|
def test_is_palindrome_bad_n_negative(self): |
|
|
|
|
362
|
|
|
""" Test that :func:`lib.digital.is_palindrome` raises a ``ValueError`` for a negative value for `n` """ |
|
|
|
|
363
|
|
|
is_palindrome = self.get_import() |
364
|
|
|
with pytest.raises(ValueError): |
365
|
|
|
is_palindrome(-123) |
366
|
|
|
|
367
|
|
|
def test_is_palindrome_bad_base_type_str(self): |
|
|
|
|
368
|
|
|
""" Test that :func:`lib.digital.is_palindrome` raises a ``TypeError`` for a non-``int`` value for `base` |
|
|
|
|
369
|
|
|
(``str``) |
370
|
|
|
""" |
371
|
|
|
is_palindrome = self.get_import() |
372
|
|
|
with pytest.raises(TypeError): |
373
|
|
|
is_palindrome(123, base="2") |
374
|
|
|
|
375
|
|
|
def test_is_palindrome_bad_base_type_float(self): |
|
|
|
|
376
|
|
|
""" Test that :func:`lib.digital.is_palindrome` raises a ``TypeError`` for a non-``int`` value for `base` |
|
|
|
|
377
|
|
|
(``float``) |
378
|
|
|
""" |
379
|
|
|
is_palindrome = self.get_import() |
380
|
|
|
with pytest.raises(TypeError): |
381
|
|
|
is_palindrome(123, base=2.0) |
382
|
|
|
|
383
|
|
|
def test_is_palindrome_bad_base_negative(self): |
|
|
|
|
384
|
|
|
""" Test that :func:`lib.digital.is_palindrome` raises a ``ValueError`` for a negative value for `base` """ |
|
|
|
|
385
|
|
|
is_palindrome = self.get_import() |
386
|
|
|
with pytest.raises(ValueError): |
387
|
|
|
is_palindrome(123, base=-2) |
388
|
|
|
|
389
|
|
|
@pytest.mark.parametrize("base", [1, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15, 200]) |
390
|
|
|
def test_is_palindrome_unsupported_base(self, base: int): |
|
|
|
|
391
|
|
|
""" Test that :func:`lib.digital.is_palindrome` raises a ``ValueError`` for unsupported values of `base` |
|
|
|
|
392
|
|
|
|
393
|
|
|
:param base: consider `value` in the given `base` |
394
|
|
|
""" |
395
|
|
|
|
396
|
|
|
is_palindrome = self.get_import() |
397
|
|
|
with pytest.raises(ValueError): |
398
|
|
|
is_palindrome(111, base=base) |
399
|
|
|
|