tests.unit.test_digital   F
last analyzed

Complexity

Total Complexity 123

Size/Duplication

Total Lines 564
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 275
dl 0
loc 564
rs 2
c 0
b 0
f 0
wmc 123

61 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 TestIsPandigital.test_is_pandigital_bad_int_n_negative() 0 5 2
A TestIsPalindrome.test_is_palindrome_bad_base_type_str() 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 TestIsPandigital.test_is_pandigital_bad_list_n_type_float() 0 7 2
A TestDigitsOf.test_digits_of_bad_base_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 TestDigitSum.test_digit_sum_bad_base_type_float() 0 7 2
A TestNumDigits.test_num_digits_bad_n_negative() 0 5 2
A TestDigitsOf.test_digits_of_bad_base_type_str() 0 6 2
A TestIsPandigital.test_is_pandigital_bad_lower_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 TestDigitsToNum.test_digits_to_num_bad_digits_type_str() 0 7 2
A TestDigitsOf.test_digits_of_bad_n_type_str() 0 5 2
A TestIsPandigital.get_import() 0 10 1
A TestDigitsToNum.test_digits_to_num_bad_digits_negative_element() 0 6 2
A TestIsPalindrome.test_is_palindrome_bad_base_type_float() 0 7 2
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 TestDigitsToNum.test_digits_to_num_bad_digits_type_list_of_str() 0 7 2
A TestIsPalindrome.get_import() 0 10 1
A TestDigitSum.test_digit_sum_correctness() 0 14 3
A TestDigitsOf.test_digits_of_bad_n_type_float() 0 6 2
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 TestDigitsToNum.test_digits_to_num_bad_base_negative() 0 5 2
A TestDigitsOf.get_import() 0 10 1
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 TestIsPalindrome.test_is_palindrome_bad_n_type_str() 0 6 2
A TestIsPandigital.test_is_pandigital_bad_base_type_str() 0 7 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 TestDigitsToNum.test_digits_to_num_bad_digits_type_float() 0 7 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 TestDigitsToNum.test_digits_to_num_correctness() 0 16 3
A TestIsPandigital.test_is_pandigital_bad_d_negative() 0 5 2
A TestDigitsToNum.test_digits_to_num_bad_base_type_float() 0 7 2
A TestIsPandigital.test_is_pandigital_bad_lower_type_str() 0 7 2
A TestDigitsToNum.test_digits_to_num_bad_base_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 TestDigitsToNum.test_digits_to_num_bad_digits_type_list_of_float() 0 7 2
A TestDigitsOf.test_digits_of_bad_n_negative() 0 5 2
A TestDigitsToNum.get_import() 0 10 1
A TestIsPandigital.test_is_pandigital_bad_base_type_float() 0 7 2
A TestDigitsOf.test_digits_of_bad_base_negative() 0 5 2
A TestNumDigits.test_num_digits_bad_base_type_float() 0 7 2
A TestDigitsOf.test_digits_of_correctness() 0 16 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 TestDigitsOf(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.digits_of` 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.digits_of` 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.digits_of` function
25
        """
26
        from lib.digital import digits_of
27
        return digits_of
28
29
    @pytest.mark.parametrize("n,base,expected_answer", [(10, 10, [1, 0]), (1579, 10, [1, 5, 7, 9]), (7, 2, [1, 1, 1]),
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...
30
                                                        (10, 2, [1, 0, 1, 0]), (0, 9, [0])])
31
    def test_digits_of_correctness(self, n: int, base: int, expected_answer: int):
0 ignored issues
show
Coding Style Naming introduced by
The name n 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...
32
        """ Test the correctness of :func:`lib.digital.digits_of` using known answer tests
33
34
        :param n: the input integer
35
        :param base: the base to build digits in
36
        :param expected_answer: the expected answer
37
        :raises AssertionError: if :func:`lib.digital.digits_of` returns the wrong type
38
        :raises AssertionError: if :func:`lib.digital.digits_of` returns the wrong value
39
        """
40
41
        digits_of = self.get_import()
42
        computed_answer = digits_of(n, base=base)
43
        # assert isinstance(computed_answer, digits_of.__annotations__["return"]), "wrong type"
44
        assert computed_answer == expected_answer, "wrong answer"
45
46
    def test_digits_of_bad_n_type_str(self):
47
        """ Test that :func:`lib.digital.digits_of` 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...
48
        digits_of = self.get_import()
49
        with pytest.raises(TypeError):
50
            digits_of("123")
51
52
    def test_digits_of_bad_n_type_float(self):
53
        """ Test that :func:`lib.digital.digits_of` 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...
54
        """
55
        digits_of = self.get_import()
56
        with pytest.raises(TypeError):
57
            digits_of(123.0)
58
59
    def test_digits_of_bad_n_negative(self):
60
        """ Test that :func:`lib.digital.digits_of` 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...
61
        digits_of = self.get_import()
62
        with pytest.raises(ValueError):
63
            digits_of(-123)
64
65
    def test_digits_of_bad_base_type_str(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_of_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...
66
        """ Test that :func:`lib.digital.digits_of` 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...
67
        """
68
        digits_of = self.get_import()
69
        with pytest.raises(TypeError):
70
            digits_of(123, base="2")
71
72
    def test_digits_of_bad_base_type_float(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_of_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...
73
        """ Test that :func:`lib.digital.digits_of` 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...
74
        (``float``)
75
        """
76
        digits_of = self.get_import()
77
        with pytest.raises(TypeError):
78
            digits_of(123, base=2.0)
79
80
    def test_digits_of_bad_base_negative(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_of_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...
81
        """ Test that :func:`lib.digital.digits_of` 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...
82
        digits_of = self.get_import()
83
        with pytest.raises(ValueError):
84
            digits_of(123, base=-2)
85
86
87
class TestDigitsToNum(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
88
    """ A collection of positive and negative unit tests for the :func:`lib.digital.digits_to_num` 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...
89
90
    @classmethod
91
    def get_import(cls):
92
        """ Get and return the :func:`lib.digital.digits_to_sum` function
93
94
        .. 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...
95
96
        :return: the :func:`lib.digital.digits_to_num` function
97
        """
98
        from lib.digital import digits_to_num
99
        return digits_to_num
100
101
    @pytest.mark.parametrize("digits,base,expected_answer", [([1, 2, 3], 10, 123), ([3, 2, 1], 10, 321), ([7], 10, 7),
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...
102
                                                             ([1, 0, 1, 0], 2, 10), ([1, 1, 1], 2, 7)])
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...
103
    def test_digits_to_num_correctness(self, digits: List[int], base: int, expected_answer: int):
104
        """ Test the correctness of :func:`lib.digital.digits_to_num` using known answer tests
105
106
        :param digits: the input digits
107
        :param base: the base to build digits in
108
        :param expected_answer: the expected answer
109
        :raises AssertionError: if :func:`lib.digital.digits_to_num` returns the wrong type
110
        :raises AssertionError: if :func:`lib.digital.digits_to_num` returns the wrong value
111
        """
112
113
        digits_to_num = self.get_import()
114
        computed_answer = digits_to_num(digits, base=base)
115
        assert isinstance(computed_answer, digits_to_num.__annotations__["return"]), "wrong type"
116
        assert computed_answer == expected_answer, "wrong answer"
117
118
    def test_digits_to_num_bad_digits_type_str(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_to_num_bad_digits_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...
119
        """ Test that :func:`lib.digital.digits_to_num` raises a ``TypeError`` for a non-``list`` value for `digits`
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...
120
        (``str``)
121
        """
122
        digits_to_num = self.get_import()
123
        with pytest.raises(TypeError):
124
            digits_to_num("123")
125
126
    def test_digits_to_num_bad_digits_type_float(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_to_num_bad_digits_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...
127
        """ Test that :func:`lib.digital.digits_to_num` raises a ``TypeError`` for a non-``list`` value for `digits`
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...
128
        (``float``)
129
        """
130
        digits_to_num = self.get_import()
131
        with pytest.raises(TypeError):
132
            digits_to_num(123.0)
133
134
    def test_digits_to_num_bad_digits_type_list_of_str(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_to_num_bad_digits_type_list_of_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...
135
        """ Test that :func:`lib.digital.digits_to_num` raises a ``TypeError`` for a list of non-``int`` values for
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...
136
        `digits` (list of ``str``)
137
        """
138
        digits_to_num = self.get_import()
139
        with pytest.raises(TypeError):
140
            digits_to_num(["123"])
141
142
    def test_digits_to_num_bad_digits_type_list_of_float(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_to_num_bad_digits_type_list_of_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...
143
        """ Test that :func:`lib.digital.digits_to_num` raises a ``TypeError`` for a list of non-``int`` values for
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...
144
        `digits` (list of ``float``)
145
        """
146
        digits_to_num = self.get_import()
147
        with pytest.raises(TypeError):
148
            digits_to_num([123.0])
149
150
    def test_digits_to_num_bad_digits_negative_element(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_to_num_bad_digits_negative_element 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...
151
        """ Test that :func:`lib.digital.digits_to_num` raises a ``ValueError`` for a negative value in `digits`
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...
152
        """
153
        digits_to_num = self.get_import()
154
        with pytest.raises(ValueError):
155
            digits_to_num([-1, 2, 3])
156
157
    def test_digits_to_num_bad_base_type_str(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_to_num_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...
158
        """ Test that :func:`lib.digital.digits_to_num` 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...
159
        (``str``)
160
        """
161
        digits_to_num = self.get_import()
162
        with pytest.raises(TypeError):
163
            digits_to_num([1, 2, 3], base="2")
164
165
    def test_digits_to_num_bad_base_type_float(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_to_num_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...
166
        """ Test that :func:`lib.digital.digits_to_num` 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...
167
        (``float``)
168
        """
169
        digits_to_num = self.get_import()
170
        with pytest.raises(TypeError):
171
            digits_to_num([1, 2, 3], base=2.0)
172
173
    def test_digits_to_num_bad_base_negative(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_digits_to_num_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...
174
        """ Test that :func:`lib.digital.digits_to_num` 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...
175
        digits_to_num = self.get_import()
176
        with pytest.raises(ValueError):
177
            digits_to_num(123, base=-2)
178
179
180
class TestDigitSum(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
181
    """ 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...
182
183
    @classmethod
184
    def get_import(cls):
185
        """ Get and return the :func:`lib.digital.digit_sum` function
186
187
        .. 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...
188
189
        :return: the :func:`lib.digital.digit_sum` function
190
        """
191
        from lib.digital import digit_sum
192
        return digit_sum
193
194
    @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...
195
    def test_digit_sum_correctness(self, value: int, expected_answer: int):
196
        """ Test the correctness of :func:`lib.digital.digit_sum` using known answer tests
197
198
        :param value: the input value
199
        :param expected_answer: the expected answer
200
        :raises AssertionError: if :func:`lib.digital.digit_sum` returns the wrong type
201
        :raises AssertionError: if :func:`lib.digital.digit_sum` returns the wrong value
202
        """
203
204
        digit_sum = self.get_import()
205
        computed_answer = digit_sum(value)
206
        assert isinstance(computed_answer, digit_sum.__annotations__["return"]), "wrong type"
207
        assert computed_answer == expected_answer, "wrong answer"
208
209
    def test_digit_sum_bad_n_type_str(self):
210
        """ 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...
211
        digit_sum = self.get_import()
212
        with pytest.raises(TypeError):
213
            digit_sum("123")
214
215
    def test_digit_sum_bad_n_type_float(self):
216
        """ 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...
217
        """
218
        digit_sum = self.get_import()
219
        with pytest.raises(TypeError):
220
            digit_sum(123.0)
221
222
    def test_digit_sum_bad_n_negative(self):
223
        """ 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...
224
        digit_sum = self.get_import()
225
        with pytest.raises(ValueError):
226
            digit_sum(-123)
227
228
    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...
229
        """ 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...
230
        """
231
        digit_sum = self.get_import()
232
        with pytest.raises(TypeError):
233
            digit_sum(123, base="2")
234
235
    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...
236
        """ 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...
237
        (``float``)
238
        """
239
        digit_sum = self.get_import()
240
        with pytest.raises(TypeError):
241
            digit_sum(123, base=2.0)
242
243
    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...
244
        """ 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...
245
        digit_sum = self.get_import()
246
        with pytest.raises(ValueError):
247
            digit_sum(123, base=-2)
248
249
250
class TestNumDigits(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
251
    """ 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...
252
253
    @classmethod
254
    def get_import(cls):
255
        """ Get and return the :func:`lib.digital.num_digits` function
256
257
        .. 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...
258
259
        :return: the :func:`lib.digital.num_digits` function
260
        """
261
        from lib.digital import num_digits
262
        return num_digits
263
264
    @pytest.mark.parametrize("value,expected_answer",
265
                             [(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...
266
    def test_num_digits_correctness_kat(self, value: int, expected_answer: int):
267
        """ Test the correctness of :func:`lib.digital.num_digits` using known answer tests
268
269
        :param value: the input value
270
        :param expected_answer: the expected answer
271
        :raises AssertionError: if :func:`lib.digital.num_digits` returns the wrong type
272
        :raises AssertionError: if :func:`lib.digital.num_digits` returns the wrong value
273
        """
274
275
        num_digits = self.get_import()
276
        computed_answer = num_digits(value)
277
        assert isinstance(computed_answer, num_digits.__annotations__["return"]), "wrong type"
278
        assert computed_answer == expected_answer, "wrong answer"
279
280
    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...
281
        """ 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...
282
283
        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...
284
        :func:`lib.digital.num_digits` evaluated at `x` equals  `n`.
285
286
        :raises AssertionError: if :func:`lib.digital.num_digits` returns the wrong type
287
        :raises AssertionError: if :func:`lib.digital.num_digits` returns the wrong value
288
        """
289
290
        from random import randint
291
        num_digits = self.get_import()
292
        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...
293
            digit_len = randint(1, 50)  # a moderate but arbitrary length (n)
294
            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...
295
            computed_answer = num_digits(random_integer)
296
            assert isinstance(computed_answer, num_digits.__annotations__["return"]), "wrong type"
297
            assert computed_answer == digit_len, "wrong answer"
298
299
    def test_num_digits_bad_n_type_str(self):
300
        """ 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...
301
        """
302
        num_digits = self.get_import()
303
        with pytest.raises(TypeError):
304
            num_digits("123")
305
306
    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...
307
        """ 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...
308
        """
309
        num_digits = self.get_import()
310
        with pytest.raises(TypeError):
311
            num_digits(123.0)
312
313
    def test_num_digits_bad_n_negative(self):
314
        """ 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...
315
        num_digits = self.get_import()
316
        with pytest.raises(ValueError):
317
            num_digits(-123)
318
319
    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...
320
        """ 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...
321
        """
322
        num_digits = self.get_import()
323
        with pytest.raises(TypeError):
324
            num_digits(123, base="2")
325
326
    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...
327
        """ 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...
328
        (``float``)
329
        """
330
        num_digits = self.get_import()
331
        with pytest.raises(TypeError):
332
            num_digits(123, base=2.0)
333
334
    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...
335
        """ 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...
336
        num_digits = self.get_import()
337
        with pytest.raises(ValueError):
338
            num_digits(123, base=-2)
339
340
341
class TestIsPandigital(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
342
    """ 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...
343
344
    @classmethod
345
    def get_import(cls):
346
        """ Get and return the :func:`lib.digital.is_pandigital` function
347
348
        .. 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...
349
350
        :return: the :func:`lib.digital.is_pandigital` function
351
        """
352
        from lib.digital import is_pandigital
353
        return is_pandigital
354
355
    @pytest.mark.parametrize("value,d,expected_answer",
356
                             [(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...
357
                              ([1, 2, 2], 3, False), ([1, 2, 3, 4], 3, False)])
358
    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...
359
        """ Test the correctness of :func:`lib.digital.is_pandigital` using known answer tests
360
361
        :param value: the input value
362
        :param d: parameter in `d`-pandigital
363
        :param expected_answer: the expected answer
364
        :raises AssertionError: if :func:`lib.digital.is_pandigital` returns the wrong type
365
        :raises AssertionError: if :func:`lib.digital.is_pandigital` returns the wrong value
366
        """
367
368
        is_pandigital = self.get_import()
369
        computed_answer = is_pandigital(value, d)
370
        assert isinstance(computed_answer, is_pandigital.__annotations__["return"]), "wrong type"
371
        assert computed_answer == expected_answer, "wrong answer"
372
373
    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...
374
        """ 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...
375
        """
376
        is_pandigital = self.get_import()
377
        with pytest.raises(TypeError):
378
            is_pandigital("123", 3)
379
380
    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...
381
        """ 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...
382
        (``float``)
383
        """
384
        is_pandigital = self.get_import()
385
        with pytest.raises(TypeError):
386
            is_pandigital(123.0, 3)
387
388
    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...
389
        """ 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...
390
        """
391
        is_pandigital = self.get_import()
392
        with pytest.raises(TypeError):
393
            is_pandigital([1, 2, "3"], 3)
394
395
    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...
396
        """ 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...
397
        (``float``)
398
        """
399
        is_pandigital = self.get_import()
400
        with pytest.raises(TypeError):
401
            is_pandigital([1, 2.3], 3)
402
403
    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...
404
        """ 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...
405
        is_pandigital = self.get_import()
406
        with pytest.raises(ValueError):
407
            is_pandigital(-123, 3)
408
409
    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...
410
        """ 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...
411
        is_pandigital = self.get_import()
412
        with pytest.raises(ValueError):
413
            is_pandigital([-1, 2, 3], 3)
414
415
    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...
416
        """ 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...
417
        """
418
        is_pandigital = self.get_import()
419
        with pytest.raises(TypeError):
420
            is_pandigital(123, "3")
421
422
    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...
423
        """ 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...
424
        (``float``)
425
        """
426
        is_pandigital = self.get_import()
427
        with pytest.raises(TypeError):
428
            is_pandigital(123, 3.0)
429
430
    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...
431
        """ 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...
432
        is_pandigital = self.get_import()
433
        with pytest.raises(ValueError):
434
            is_pandigital(123, -3)
435
436
    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...
437
        """ 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...
438
        (``str``)
439
        """
440
        is_pandigital = self.get_import()
441
        with pytest.raises(TypeError):
442
            is_pandigital([1, 2, 3], 3, lower="10")
443
444
    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...
445
        """ 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...
446
        (``float``)
447
        """
448
        is_pandigital = self.get_import()
449
        with pytest.raises(TypeError):
450
            is_pandigital([1, 2, 3], 3, lower=10.0)
451
452
    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...
453
        """ 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...
454
        is_pandigital = self.get_import()
455
        with pytest.raises(ValueError):
456
            is_pandigital(123, 3, lower=-10)
457
458
    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...
459
        """ 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...
460
        (``str``)
461
        """
462
        is_pandigital = self.get_import()
463
        with pytest.raises(TypeError):
464
            is_pandigital(123, 3, base="10")
465
466
    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...
467
        """ 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...
468
        (``float``)
469
        """
470
        is_pandigital = self.get_import()
471
        with pytest.raises(TypeError):
472
            is_pandigital(123, 3, base=2.0)
473
474
    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...
475
        """ 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...
476
        is_pandigital = self.get_import()
477
        with pytest.raises(ValueError):
478
            is_pandigital(123, 3, base=-10)
479
480
481
class TestIsPalindrome(object):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
482
    """ 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...
483
484
    @classmethod
485
    def get_import(cls):
486
        """ Get and return the :func:`lib.digital.is_palindrome` function
487
488
        .. 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...
489
490
        :return: the :func:`lib.digital.is_palindrome` function
491
        """
492
        from lib.digital import is_palindrome
493
        return is_palindrome
494
495
    @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...
496
    def test_is_palindrome_correctness(self, value: int, base: int, expected_answer: int):
497
        """ Test the correctness of :func:`lib.digital.is_palindrome` using known answer tests
498
499
        :param value: the input value
500
        :param base: consider `value` in the given `base`
501
        :param expected_answer: the expected answer
502
        :raises AssertionError: if :func:`lib.digital.is_palindrome` returns the wrong type
503
        :raises AssertionError: if :func:`lib.digital.is_palindrome` returns the wrong value
504
        """
505
506
        is_palindrome = self.get_import()
507
        computed_answer = is_palindrome(value, base=base)
508
        assert isinstance(computed_answer, is_palindrome.__annotations__["return"]), "wrong type"
509
        assert computed_answer == expected_answer, "wrong answer"
510
511
    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...
512
        """ 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...
513
        """
514
        is_palindrome = self.get_import()
515
        with pytest.raises(TypeError):
516
            is_palindrome("123")
517
518
    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...
519
        """ 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...
520
        (``float``)
521
        """
522
        is_palindrome = self.get_import()
523
        with pytest.raises(TypeError):
524
            is_palindrome(123.0)
525
526
    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...
527
        """ 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...
528
        is_palindrome = self.get_import()
529
        with pytest.raises(ValueError):
530
            is_palindrome(-123)
531
532
    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...
533
        """ 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...
534
        (``str``)
535
        """
536
        is_palindrome = self.get_import()
537
        with pytest.raises(TypeError):
538
            is_palindrome(123, base="2")
539
540
    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...
541
        """ 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...
542
        (``float``)
543
        """
544
        is_palindrome = self.get_import()
545
        with pytest.raises(TypeError):
546
            is_palindrome(123, base=2.0)
547
548
    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...
549
        """ 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...
550
        is_palindrome = self.get_import()
551
        with pytest.raises(ValueError):
552
            is_palindrome(123, base=-2)
553
554
    @pytest.mark.parametrize("base", [1, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15, 200])
555
    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...
556
        """ 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...
557
558
        :param base: consider `value` in the given `base`
559
        """
560
561
        is_palindrome = self.get_import()
562
        with pytest.raises(ValueError):
563
            is_palindrome(111, base=base)
564