Passed
Push — master ( 418baa...6d90d6 )
by Bill
02:03
created

tests.unit.test_digital   F

Complexity

Total Complexity 88

Size/Duplication

Total Lines 399
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 196
dl 0
loc 399
rs 1.5789
c 0
b 0
f 0
wmc 88

43 Methods

Rating   Name   Duplication   Size   Complexity  
A TestIsPalindrome.test_is_palindrome_bad_base_negative() 0 5 2
A TestIsPalindrome.test_is_palindrome_bad_n_type_float() 0 7 2
A TestIsPandigital.test_is_pandigital_bad_list_n_negative() 0 5 2
A TestDigitSum.get_import() 0 10 1
A TestIsPalindrome.test_is_palindrome_bad_base_type_str() 0 7 2
A TestIsPandigital.test_is_pandigital_bad_int_n_negative() 0 5 2
A TestIsPandigital.test_is_pandigital_bad_list_n_type_float() 0 7 2
A TestDigitSum.test_digit_sum_bad_n_type_str() 0 5 2
A TestIsPandigital.test_is_pandigital_bad_int_n_type_float() 0 7 2
A TestNumDigits.test_num_digits_bad_n_type_float() 0 6 2
A TestIsPandigital.test_is_pandigital_bad_d_type_float() 0 7 2
A TestNumDigits.test_num_digits_bad_n_negative() 0 5 2
A TestIsPandigital.test_is_pandigital_bad_lower_type_float() 0 7 2
A TestDigitSum.test_digit_sum_bad_base_type_float() 0 7 2
A TestIsPalindrome.test_is_palindrome_unsupported_base() 0 10 2
A TestIsPalindrome.test_is_palindrome_correctness() 0 15 3
A TestDigitSum.test_digit_sum_bad_n_type_float() 0 6 2
A TestIsPalindrome.test_is_palindrome_bad_base_type_float() 0 7 2
A TestIsPandigital.get_import() 0 10 1
A TestDigitSum.test_digit_sum_bad_n_negative() 0 5 2
A TestIsPandigital.test_is_pandigital_bad_list_n_type_str() 0 6 2
A TestNumDigits.get_import() 0 10 1
A TestIsPalindrome.get_import() 0 10 1
A TestDigitSum.test_digit_sum_correctness() 0 14 3
A TestDigitSum.test_digit_sum_bad_base_type_str() 0 6 2
A TestNumDigits.test_num_digits_correctness_kat() 0 15 3
A TestIsPalindrome.test_is_palindrome_bad_n_negative() 0 5 2
A TestIsPandigital.test_is_pandigital_bad_d_type_str() 0 6 2
A TestIsPandigital.test_is_pandigital_bad_int_n_type_str() 0 6 2
A TestIsPandigital.test_is_pandigital_bad_base_type_str() 0 7 2
A TestIsPalindrome.test_is_palindrome_bad_n_type_str() 0 6 2
A TestIsPandigital.test_is_pandigital_correctness() 0 17 3
A TestNumDigits.test_num_digits_bad_base_type_str() 0 6 2
A TestNumDigits.test_num_digits_bad_base_negative() 0 5 2
A TestDigitSum.test_digit_sum_bad_base_negative() 0 5 2
A TestIsPandigital.test_is_pandigital_bad_base_negative() 0 5 2
A TestNumDigits.test_num_digits_correctness_random() 0 18 4
A TestIsPandigital.test_is_pandigital_bad_d_negative() 0 5 2
A TestIsPandigital.test_is_pandigital_bad_lower_type_str() 0 7 2
A TestIsPandigital.test_is_pandigital_bad_lower_negative() 0 5 2
A TestNumDigits.test_num_digits_bad_n_type_str() 0 6 2
A TestIsPandigital.test_is_pandigital_bad_base_type_float() 0 7 2
A TestNumDigits.test_num_digits_bad_base_type_float() 0 7 2

How to fix   Complexity   

Complexity

Complex classes like tests.unit.test_digital often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
16
    """ A collection of positive and negative unit tests for the :func:`lib.digital.digit_sum` function """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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)])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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``) """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digit_sum_bad_base_type_str does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
64
        """ Test that :func:`lib.digital.digit_sum` raises a ``TypeError`` for a non-``int`` value for `base` (``str``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (119/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digit_sum_bad_base_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
71
        """ Test that :func:`lib.digital.digit_sum` raises a ``TypeError`` for a non-``int`` value for `base`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digit_sum_bad_base_negative does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
79
        """ Test that :func:`lib.digital.digit_sum` raises a ``ValueError`` for a negative value for `base` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
80
        digit_sum = self.get_import()
81
        with pytest.raises(ValueError):
82
            digit_sum(123, base=-2)
83
84
85
class TestNumDigits(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
86
    """ A collection of positive and negative unit tests for the :func:`lib.digital.num_digits` function """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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)])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_num_digits_correctness_random does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
116
        """ Test the correctness of :func:`lib.digital.num_digits` using random inputs with predictable answers
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
117
118
        That is, generate a random length (`n`) and a random integer of that length (`x`). Then, check that
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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
0 ignored issues
show
Unused Code introduced by
The variable i seems to be unused.
Loading history...
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)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_num_digits_bad_n_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
142
        """ Test that :func:`lib.digital.num_digits` raises a ``TypeError`` for a non-``int`` value for `n` (``float``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (119/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_num_digits_bad_base_type_str does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
155
        """ Test that :func:`lib.digital.num_digits` raises a ``TypeError`` for a non-``int`` value for `base` (``str``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_num_digits_bad_base_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
162
        """ Test that :func:`lib.digital.num_digits` raises a ``TypeError`` for a non-``int`` value for `base`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_num_digits_bad_base_negative does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
170
        """ Test that :func:`lib.digital.num_digits` raises a ``ValueError`` for a negative value for `base` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
171
        num_digits = self.get_import()
172
        with pytest.raises(ValueError):
173
            num_digits(123, base=-2)
174
175
176
class TestIsPandigital(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
177
    """ A collection of positive and negative unit tests for the :func:`lib.digital.is_pandigital` function """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style Naming introduced by
The name d does not conform to the argument naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_int_n_type_str does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
209
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `n` (``str``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_int_n_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
216
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `n`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_list_n_type_str does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
224
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `n` (``str``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_list_n_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
231
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `n`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_int_n_negative does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
239
        """ Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `n` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_list_n_negative does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
245
        """ Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `n` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_d_type_str does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
251
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `d` (``str``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_d_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
258
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `d`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_d_negative does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
266
        """ Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `d` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_lower_type_str does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
272
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `lower`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (114/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_lower_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
280
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `lower`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (114/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_lower_negative does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
288
        """ Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `lower` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_base_type_str does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
294
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `base`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_base_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
302
        """ Test that :func:`lib.digital.is_pandigital` raises a ``TypeError`` for a non-``int`` value for `base`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_pandigital_bad_base_negative does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
310
        """ Test that :func:`lib.digital.is_pandigital` raises a ``ValueError`` for a negative value for `base` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (115/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
311
        is_pandigital = self.get_import()
312
        with pytest.raises(ValueError):
313
            is_pandigital(123, 3, base=-10)
314
315
316
class TestIsPalindrome(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
317
    """ A collection of positive and negative unit tests for the :func:`lib.digital.is_palindrome` function """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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)])
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_palindrome_bad_n_type_str does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
347
        """ Test that :func:`lib.digital.is_palindrome` raises a ``TypeError`` for a non-``int`` value for `n` (``str``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (120/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_palindrome_bad_n_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
354
        """ Test that :func:`lib.digital.is_palindrome` raises a ``TypeError`` for a non-``int`` value for `n`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_palindrome_bad_n_negative does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
362
        """ Test that :func:`lib.digital.is_palindrome` raises a ``ValueError`` for a negative value for `n` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_palindrome_bad_base_type_str does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
368
        """ Test that :func:`lib.digital.is_palindrome` raises a ``TypeError`` for a non-``int`` value for `base`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_palindrome_bad_base_type_float does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
376
        """ Test that :func:`lib.digital.is_palindrome` raises a ``TypeError`` for a non-``int`` value for `base`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_palindrome_bad_base_negative does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
384
        """ Test that :func:`lib.digital.is_palindrome` raises a ``ValueError`` for a negative value for `base` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (115/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_palindrome_unsupported_base does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
391
        """ Test that :func:`lib.digital.is_palindrome` raises a ``ValueError`` for unsupported values of `base`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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