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

tests.unit.test_numbertheory   F

Complexity

Total Complexity 112

Size/Duplication

Total Lines 499
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 197
dl 0
loc 499
rs 1.5789
c 0
b 0
f 0
wmc 112

48 Functions

Rating   Name   Duplication   Size   Complexity  
A test_divisor_count_bad_n_type_float() 0 6 2
A test_divisor_sum_correctness() 0 13 3
A test_is_probably_prime_correctness() 0 15 4
A test_is_probably_prime_bad_n_type_str() 0 6 2
A test_is_even_bad_n_type_str() 0 4 2
A test_perfect_power_exponent_bad_n_type_str() 0 6 2
A test_miller_rabin_bad_n_type_float() 0 6 2
A test_is_even_correctness() 0 13 3
A test_divisor_count_bad_n_type_str() 0 6 2
A test_divisor_sum_aliquot_bad_n_zero() 0 5 2
A test_perfect_power_exponent_bad_n_type_float() 0 6 2
A test_miller_rabin_bad_n_type_str() 0 5 2
A test_miller_rabin_bad_n_too_small() 0 4 2
A test_is_even_bad_n_type_float() 0 5 2
A test_sieve_correctness_bound() 0 18 4
A test_miller_rabin_bad_k_zero() 0 4 2
A test_divisor_count_bad_n_zero() 0 4 2
A test_divisor_sum_aliquot_bad_n_type_float() 0 6 2
A test_divisor_count_correctness() 0 13 3
B test_factor_correctness_random() 0 24 3
A test_is_odd_bad_n_type_float() 0 4 2
A test_sieve_bad_upper_bound_type_str() 0 6 2
A test_divisor_sum_aliquot_correctness() 0 13 3
A test_perfect_power_exponent_correctness_square_free() 0 11 3
A test_factor_bad_n_type_str() 0 4 2
A test_is_square_bad_n_type_str() 0 5 2
A test_sieve_bad_upper_bound_negative() 0 4 2
A test_is_odd_bad_n_type_str() 0 4 2
A test_sieve_bad_upper_bound_too_big() 0 5 2
A test_perfect_power_exponent_bad_n_zero() 0 4 2
A test_is_probably_prime_bad_k_type_float() 0 6 2
A test_divisor_sum_bad_n_type_float() 0 6 2
A test_divisor_sum_bad_n_zero() 0 4 2
A test_miller_rabin_bad_k_type_float() 0 6 2
A test_is_probably_prime_bad_n_type_float() 0 6 2
A test_factor_correctness_negative() 0 20 4
A test_is_square_bad_n_type_float() 0 5 2
A test_perfect_power_exponent_correctness_not_square_free() 0 12 3
A test_is_probably_prime_bad_k_type_str() 0 6 2
A test_is_square_correctness() 0 13 3
A test_miller_rabin_bad_k_type_str() 0 5 2
A test_factor_correctness() 0 11 2
A test_factor_bad_n_type_float() 0 4 2
A test_divisor_sum_bad_n_type_str() 0 5 2
A test_divisor_sum_aliquot_bad_n_type_str() 0 6 2
A test_sieve_correctness() 0 17 3
A test_is_odd_correctness() 0 13 3
A test_sieve_bad_upper_bound_type_float() 0 6 2

How to fix   Complexity   

Complexity

Complex classes like tests.unit.test_numbertheory 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_numbertheory` -- Unit Tests
3
=================================================
4
5
.. module:: tests.unit.test_numbertheory
6
   :synopsis: Unit tests for the lib.numbertheory package.
7
8
.. moduleauthor:: Bill Maroney <[email protected]>
9
"""
10
11
from collections import Counter
12
from itertools import takewhile
13
import pytest
14
from random import choice, randint
0 ignored issues
show
introduced by
standard import "from random import choice, randint" should be placed before "import pytest"
Loading history...
15
16
from lib.util import load_dataset
17
from lib.numbertheory import is_even, is_odd, is_square
18
from lib.numbertheory import divisor_count, divisor_sum, divisor_sum_aliquot
19
from lib.numbertheory import is_probably_prime, sieve
20
from lib.numbertheory.primality import miller_rabin, eratosthenes, segmented_eratosthenes
21
from lib.numbertheory import factor
22
from lib.numbertheory.factorisation import perfect_power_exponent
23
24
25
@pytest.mark.parametrize("value,expected_answer", [(0, True), (1, False), (200, True), (-123, False), (-24, True)])
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...
26
def test_is_even_correctness(value: int, expected_answer: bool):
27
    """ Test the correctness of :func:`lib.numbertheory.is_even` using known answer tests
28
29
    :param value: the input value
30
    :param expected_answer: the expected answer
31
    :raises AssertionError: if :func:`lib.numbertheory.is_even` returns the wrong type
32
    :raises AssertionError: if :func:`lib.numbertheory.is_even` returns the wrong value
33
    """
34
35
    computed_answer = is_even(value)
36
    assert isinstance(computed_answer, is_even.__annotations__["return"]), "wrong type"
37
    assert computed_answer == expected_answer, "wrong answer"
38
39
40
def test_is_even_bad_n_type_str():
41
    """ Test that :func:`lib.numbertheory.is_even` 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 (119/100).

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

Loading history...
42
    with pytest.raises(TypeError):
43
        is_even("123")
44
45
46
def test_is_even_bad_n_type_float():
47
    """ Test that :func:`lib.numbertheory.is_even` 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 (117/100).

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

Loading history...
48
    """
49
    with pytest.raises(TypeError):
50
        is_even(123.0)
51
52
53
@pytest.mark.parametrize("value,expected_answer", [(0, False), (1, True), (200, False), (-123, True), (-24, False)])
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...
54
def test_is_odd_correctness(value: int, expected_answer: bool):
55
    """ Test the correctness of :func:`lib.numbertheory.is_odd` using known answer tests
56
57
    :param value: the input value
58
    :param expected_answer: the expected answer
59
    :raises AssertionError: if :func:`lib.numbertheory.is_odd` returns the wrong type
60
    :raises AssertionError: if :func:`lib.numbertheory.is_odd` returns the wrong value
61
    """
62
63
    computed_answer = is_odd(value)
64
    assert isinstance(computed_answer, is_odd.__annotations__["return"]), "wrong type"
65
    assert computed_answer == expected_answer, "wrong answer"
66
67
68
def test_is_odd_bad_n_type_str():
69
    """ Test that :func:`lib.numbertheory.is_odd` 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 (118/100).

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

Loading history...
70
    with pytest.raises(TypeError):
71
        is_odd("123")
72
73
74
def test_is_odd_bad_n_type_float():
75
    """ Test that :func:`lib.numbertheory.is_odd` 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 (120/100).

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

Loading history...
76
    with pytest.raises(TypeError):
77
        is_odd(123.0)
78
79
80
@pytest.mark.parametrize("value,expected_answer", [(0, True), (1, True), (122, False), (16, True), (10000, True)])
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...
81
def test_is_square_correctness(value: int, expected_answer: bool):
82
    """ Test the correctness of :func:`lib.numbertheory.is_square` using known answer tests
83
84
    :param value: the input value
85
    :param expected_answer: the expected answer
86
    :raises AssertionError: if :func:`lib.numbertheory.is_square` returns the wrong type
87
    :raises AssertionError: if :func:`lib.numbertheory.is_square` returns the wrong value
88
    """
89
90
    computed_answer = is_square(value)
91
    assert isinstance(computed_answer, is_square.__annotations__["return"]), "wrong type"
92
    assert computed_answer == expected_answer, "wrong answer"
93
94
95
def test_is_square_bad_n_type_str():
96
    """ Test that :func:`lib.numbertheory.is_square` 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...
97
    """
98
    with pytest.raises(TypeError):
99
        is_square("123")
100
101
102
def test_is_square_bad_n_type_float():
103
    """ Test that :func:`lib.numbertheory.is_square` 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...
104
    """
105
    with pytest.raises(TypeError):
106
        is_square(123.0)
107
108
109
@pytest.mark.parametrize("value,expected_answer", [(1, 1), (17, 2), (10, 4), (30, 8), (275, 6), (10000, 25)])
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...
110
def test_divisor_count_correctness(value: int, expected_answer: bool):
111
    """ Test the correctness of :func:`lib.numbertheory.divisor_count` using known answer tests
112
113
    :param value: the input value
114
    :param expected_answer: the expected answer
115
    :raises AssertionError: if :func:`lib.numbertheory.divisor_count` returns the wrong type
116
    :raises AssertionError: if :func:`lib.numbertheory.divisor_count` returns the wrong value
117
    """
118
119
    computed_answer = divisor_count(value)
120
    assert isinstance(computed_answer, divisor_count.__annotations__["return"]), "wrong type"
121
    assert computed_answer == expected_answer, "wrong answer"
122
123
124
def test_divisor_count_bad_n_type_str():
0 ignored issues
show
Coding Style Naming introduced by
The name test_divisor_count_bad_n_type_str does not conform to the function 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...
125
    """ Test that :func:`lib.numbertheory.divisor_count` 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 (111/100).

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

Loading history...
126
    (``str``)
127
    """
128
    with pytest.raises(TypeError):
129
        divisor_count("123")
130
131
132
def test_divisor_count_bad_n_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_divisor_count_bad_n_type_float does not conform to the function 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...
133
    """ Test that :func:`lib.numbertheory.divisor_count` 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 (111/100).

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

Loading history...
134
    (``float``)
135
    """
136
    with pytest.raises(TypeError):
137
        divisor_count(123.0)
138
139
140
def test_divisor_count_bad_n_zero():
141
    """ Test that :func:`lib.numbertheory.divisor_count` raises a ``ValueError`` for a non-positive value for `n` """
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...
142
    with pytest.raises(ValueError):
143
        divisor_count(0)
144
145
146
@pytest.mark.parametrize("value,expected_answer", [(1, 1), (17, 18), (10, 18), (30, 72), (275, 372), (10000, 24211)])
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...
147
def test_divisor_sum_correctness(value: int, expected_answer: bool):
148
    """ Test the correctness of :func:`lib.numbertheory.divisor_sum` using known answer tests
149
150
    :param value: the input value
151
    :param expected_answer: the expected answer
152
    :raises AssertionError: if :func:`lib.numbertheory.divisor_sum` returns the wrong type
153
    :raises AssertionError: if :func:`lib.numbertheory.divisor_sum` returns the wrong value
154
    """
155
156
    computed_answer = divisor_sum(value)
157
    assert isinstance(computed_answer, divisor_sum.__annotations__["return"]), "wrong type"
158
    assert computed_answer == expected_answer, "wrong answer"
159
160
161
def test_divisor_sum_bad_n_type_str():
162
    """ Test that :func:`lib.numbertheory.divisor_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 (119/100).

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

Loading history...
163
    """
164
    with pytest.raises(TypeError):
165
        divisor_sum("123")
166
167
168
def test_divisor_sum_bad_n_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_divisor_sum_bad_n_type_float does not conform to the function 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...
169
    """ Test that :func:`lib.numbertheory.divisor_sum` 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 (109/100).

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

Loading history...
170
    (``float``)
171
    """
172
    with pytest.raises(TypeError):
173
        divisor_sum(123.0)
174
175
176
def test_divisor_sum_bad_n_zero():
177
    """ Test that :func:`lib.numbertheory.divisor_sum` raises a ``ValueError`` for a non-positive value for `n` """
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...
178
    with pytest.raises(ValueError):
179
        divisor_sum(0)
180
181
182
@pytest.mark.parametrize("value,expected_answer", [(1, 0), (17, 1), (10, 8), (30, 42), (275, 97), (10000, 14211)])
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...
183
def test_divisor_sum_aliquot_correctness(value: int, expected_answer: bool):
0 ignored issues
show
Coding Style Naming introduced by
The name test_divisor_sum_aliquot_correctness does not conform to the function 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...
184
    """ Test the correctness of :func:`lib.numbertheory.divisor_sum_aliquot` using known answer 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...
185
186
    :param value: the input value
187
    :param expected_answer: the expected answer
188
    :raises AssertionError: if :func:`lib.numbertheory.divisor_sum_aliquot` returns the wrong type
189
    :raises AssertionError: if :func:`lib.numbertheory.divisor_sum_aliquot` returns the wrong value
190
    """
191
192
    computed_answer = divisor_sum_aliquot(value)
193
    assert isinstance(computed_answer, divisor_sum_aliquot.__annotations__["return"]), "wrong type"
194
    assert computed_answer == expected_answer, "wrong answer"
195
196
197
def test_divisor_sum_aliquot_bad_n_type_str():
0 ignored issues
show
Coding Style Naming introduced by
The name test_divisor_sum_aliquot_bad_n_type_str does not conform to the function 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...
198
    """ Test that :func:`lib.numbertheory.divisor_sum_aliquot` 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 (117/100).

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

Loading history...
199
    (``str``)
200
    """
201
    with pytest.raises(TypeError):
202
        divisor_sum_aliquot("123")
203
204
205
def test_divisor_sum_aliquot_bad_n_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_divisor_sum_aliquot_bad_n_type_float does not conform to the function 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...
206
    """ Test that :func:`lib.numbertheory.divisor_sum_aliquot` 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 (117/100).

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

Loading history...
207
    (``float``)
208
    """
209
    with pytest.raises(TypeError):
210
        divisor_sum_aliquot(123.0)
211
212
213
def test_divisor_sum_aliquot_bad_n_zero():
0 ignored issues
show
Coding Style Naming introduced by
The name test_divisor_sum_aliquot_bad_n_zero does not conform to the function 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...
214
    """ Test that :func:`lib.numbertheory.divisor_sum_aliquot` raises a ``ValueError`` for a non-positive value for `n`
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...
215
    """
216
    with pytest.raises(ValueError):
217
        divisor_sum_aliquot(0)
218
219
220
def test_is_probably_prime_correctness():
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_probably_prime_correctness does not conform to the function 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...
221
    """ Test the correctness of :func:`lib.numbertheory.is_probably_prime`
222
223
    :raises AssertionError: if :func:`lib.numbertheory.is_probably_prime` returns the wrong type
224
    :raises AssertionError: if :func:`lib.numbertheory.is_probably_prime` returns the wrong value
225
    """
226
227
    primes = load_dataset("general", "primes", data_type=int)
228
    primes = set(primes)
229
    upper_limit = 1000  # artificial cap to limit the run-time of this test
230
    max_prime = min(upper_limit, max(primes))
231
    for n in range(1, max_prime + 1):
0 ignored issues
show
Coding Style Naming introduced by
The name n does not conform to the variable 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...
232
        computed_answer = is_probably_prime(n, k=5)
233
        assert isinstance(computed_answer, is_probably_prime.__annotations__["return"]), "wrong type"
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...
234
        assert (n in primes) == computed_answer, "wrong answer"
235
236
237
def test_is_probably_prime_bad_n_type_str():
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_probably_prime_bad_n_type_str does not conform to the function 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...
238
    """ Test that :func:`lib.numbertheory.is_probably_prime` 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 (115/100).

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

Loading history...
239
    (``str``)
240
    """
241
    with pytest.raises(TypeError):
242
        is_probably_prime("2")
243
244
245
def test_is_probably_prime_bad_n_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_probably_prime_bad_n_type_float does not conform to the function 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...
246
    """ Test that :func:`lib.numbertheory.is_probably_prime` 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 (115/100).

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

Loading history...
247
    (``float``)
248
    """
249
    with pytest.raises(TypeError):
250
        is_probably_prime(2.4)
251
252
253
def test_miller_rabin_bad_n_type_str():
0 ignored issues
show
Coding Style Naming introduced by
The name test_miller_rabin_bad_n_type_str does not conform to the function 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...
254
    """ Test that :func:`lib.numbertheory.miller_rabin` 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...
255
    """
256
    with pytest.raises(TypeError):
257
        miller_rabin("2")
258
259
260
def test_miller_rabin_bad_n_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_miller_rabin_bad_n_type_float does not conform to the function 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...
261
    """ Test that :func:`lib.numbertheory.miller_rabin` 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...
262
    (``float``)
263
    """
264
    with pytest.raises(TypeError):
265
        miller_rabin(2.4)
266
267
268
def test_miller_rabin_bad_n_too_small():
0 ignored issues
show
Coding Style Naming introduced by
The name test_miller_rabin_bad_n_too_small does not conform to the function 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...
269
    """ Test that :func:`lib.numbertheory.miller_rabin` raises a ``ValueError`` for too small a value for `n` """
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...
270
    with pytest.raises(ValueError):
271
        miller_rabin(2)
272
273
274
def test_is_probably_prime_bad_k_type_str():
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_probably_prime_bad_k_type_str does not conform to the function 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...
275
    """ Test that :func:`lib.numbertheory.is_probably_prime` raises a ``TypeError`` for a non-``int`` value for `k`
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...
276
    (``str``)
277
    """
278
    with pytest.raises(TypeError):
279
        is_probably_prime(2, "14")
280
281
282
def test_is_probably_prime_bad_k_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_is_probably_prime_bad_k_type_float does not conform to the function 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...
283
    """ Test that :func:`lib.numbertheory.is_probably_prime` raises a ``TypeError`` for a non-``int`` value for `k`
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...
284
    (``float``)
285
    """
286
    with pytest.raises(TypeError):
287
        is_probably_prime(2, 12.3)
288
289
290
def test_miller_rabin_bad_k_type_str():
0 ignored issues
show
Coding Style Naming introduced by
The name test_miller_rabin_bad_k_type_str does not conform to the function 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...
291
    """ Test that :func:`lib.numbertheory.miller_rabin` raises a ``TypeError`` for a non-``int`` value for `k` (``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...
292
    """
293
    with pytest.raises(TypeError):
294
        miller_rabin(2, "14")
295
296
297
def test_miller_rabin_bad_k_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_miller_rabin_bad_k_type_float does not conform to the function 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...
298
    """ Test that :func:`lib.numbertheory.miller_rabin` raises a ``TypeError`` for a non-``int`` value for `k`
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...
299
    (``float``)
300
    """
301
    with pytest.raises(TypeError):
302
        miller_rabin(2, 12.3)
303
304
305
def test_miller_rabin_bad_k_zero():
306
    """ Test that :func:`lib.numbertheory.miller_rabin` raises a ``ValueError`` for :math:`k=0` """
307
    with pytest.raises(ValueError):
308
        miller_rabin(9, 0)
309
310
311
@pytest.mark.parametrize("siever", [sieve, eratosthenes, segmented_eratosthenes])
312
def test_sieve_correctness(siever):
313
    """ Test the correctness of all sieves in :func:`lib.numbertheory` including:
314
        * :func:`lib.numbertheory.primality.sieve`
315
        * :func:`lib.numbertheory.primality.eratosthenes`
316
        * :func:`lib.numbertheory.primality.segmented_eratosthenes`
317
318
    The integers yielded by these sieves are tested for primality, up to some moderate bound.
319
320
    :raises AssertionError: if ``siever(upper_bound)`` yields the wrong type
321
    :raises AssertionError: if ``siever(upper_bound)`` yields the wrong value
322
    """
323
324
    for p in siever(upper_bound=100):
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable 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...
325
        computed_answer = is_probably_prime(p)
326
        # assert isinstance(computed_answer, sieve.__annotations__["return"]), "wrong type"
327
        assert computed_answer is True, "wrong answer"
328
329
330
@pytest.mark.parametrize("upper_bound", [100, 10 ** 5, 10 ** 8, 10 ** 10])
331
def test_sieve_correctness_bound(upper_bound):
332
    """ Test the correctness of all sieves in :mod:`lib.numbertheory` including:
333
        * :func:`lib.numbertheory.primality.sieve`
334
        * :func:`lib.numbertheory.primality.eratosthenes`
335
        * :func:`lib.numbertheory.primality.segmented_eratosthenes`
336
337
    The integers yielded by these sieves are tested for primality, up to some moderate bound. The parameter
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...
338
    `upper_bound` is set to various values to ensure all sieves are utilised.
339
340
    :raises AssertionError: if :func:`lib.numbertheory.sieve` yields the wrong type
341
    :raises AssertionError: if :func:`lib.numbertheory.sieve` yields the wrong value
342
    """
343
344
    for p in takewhile(lambda _p: _p <= 100, sieve(upper_bound)):
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable 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...
345
        computed_answer = is_probably_prime(p)
346
        # assert isinstance(computed_answer, sieve.__annotations__["return"]), "wrong type"
347
        assert computed_answer is True, "wrong answer"
348
349
350
def test_sieve_bad_upper_bound_type_str():
0 ignored issues
show
Coding Style Naming introduced by
The name test_sieve_bad_upper_bound_type_str does not conform to the function 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...
351
    """ Test that :func:`lib.numbertheory.sieve` raises a ``TypeError`` for a non-``int`` value for `upper_bound`
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...
352
    (``str``)
353
    """
354
    with pytest.raises(TypeError):
355
        sieve("123")
356
357
358
def test_sieve_bad_upper_bound_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_sieve_bad_upper_bound_type_float does not conform to the function 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 that :func:`lib.numbertheory.sieve` raises a ``TypeError`` for a non-``int`` value for `upper_bound`
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...
360
    (``float``)
361
    """
362
    with pytest.raises(TypeError):
363
        sieve(12.3)
364
365
366
def test_sieve_bad_upper_bound_negative():
0 ignored issues
show
Coding Style Naming introduced by
The name test_sieve_bad_upper_bound_negative does not conform to the function 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...
367
    """ Test that :func:`lib.numbertheory.sieve` raises a ``ValueError`` for :math:`\\mbox{upper_bound} \lt 0` """
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \l was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
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...
368
    with pytest.raises(ValueError):
369
        sieve(-14)
370
371
372
def test_sieve_bad_upper_bound_too_big():
0 ignored issues
show
Coding Style Naming introduced by
The name test_sieve_bad_upper_bound_too_big does not conform to the function 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...
373
    """ Test that :func:`lib.numbertheory.sieve` raises a ``ValueError`` for :math:`\\mbox{upper_bound} \ge 10^{16}` """
0 ignored issues
show
Bug introduced by
A suspicious escape sequence \g was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
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...
374
    too_big = 10 ** 20
375
    with pytest.raises(ValueError):
376
        sieve(upper_bound=too_big)
377
378
379
@pytest.mark.parametrize("value,expected_answer", [(0, {0: 1}), (1, {1: 1}), (16, {2: 4})])
380
def test_factor_correctness(value, expected_answer):
381
    """ Test the correctness of :func:`lib.numbertheory.factor` with known-answer-tests
382
383
    :raises AssertionError: if :func:`lib.numbertheory.factor` returns the wrong type
384
    :raises AssertionError: if :func:`lib.numbertheory.factor` returns the wrong value
385
    """
386
387
    computed_value = factor(value)
388
    # assert isinstance(computed_value, factor.__annotations__["return"]), "wrong type"
389
    assert computed_value == expected_answer, "wrong value"
390
391
392
@pytest.mark.parametrize("value,expected_answer", [(16, {2: 4}), (35, {5: 1, 7: 1}), (1001, {7: 1, 11: 1, 13: 1})])
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...
393
def test_factor_correctness_negative(value, expected_answer):
0 ignored issues
show
Coding Style Naming introduced by
The name test_factor_correctness_negative does not conform to the function 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...
394
    """ Test the correctness of :func:`lib.numbertheory.factor` with known-answer-tests
395
396
    Each `value` is factored. This factorisation is combined with a factor of :math:`-1` to give the expected
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...
397
    factorisation of :math:`-value`. This negative value is then factored, and the two results are checked for equality.
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...
398
399
    :raises AssertionError: if :func:`lib.numbertheory.factor` returns the wrong type
400
    :raises AssertionError: if :func:`lib.numbertheory.factor` returns the wrong value
401
    :raises AssertionError: if :func:`lib.numbertheory.factor` doesn't include a factor of :math:`-1`
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...
402
    """
403
404
    computed_value = factor(value)
405
    # assert isinstance(computed_value, factor.__annotations__["return"]), "wrong type"
406
    assert computed_value == expected_answer, "wrong value"
407
    computed_value_negative = factor(-1 * value)
408
    # assert isinstance(computed_value_negative, factor.__annotations__["return"]), "wrong type"
409
    assert -1 not in computed_value.keys(), "missing factor of -1"
410
    computed_value[-1] = 1
411
    assert computed_value == computed_value_negative, "wrong value"
412
413
414
def test_factor_correctness_random():
415
    """ Test the correctness of :func:`lib.numbertheory.factor` with known-answer-tests
416
417
    A random integer is built as a product of several small primes (selected with replacement); this random integer has
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...
418
    a known factorisation. :func:`lib.numbertheory.factor` is used to factor the constructed number and it is compared
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...
419
    to the known and expected factorisation.
420
421
    :raises AssertionError: if :func:`lib.numbertheory.factor` returns the wrong type
422
    :raises AssertionError: if :func:`lib.numbertheory.factor` returns the wrong value
423
    """
424
425
    # First, build a random integer as a product of several small primes (selected with replacement)
426
    primes = load_dataset("general", "primes", data_type=int)
427
    value, factorisation = 1, Counter()
428
    while value < 10 ** 6:
429
        p = choice(primes)
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable 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...
430
        value *= p
431
        factorisation[p] += 1
432
    factorisation = dict(factorisation)
433
434
    # Factor the constructed integer and check that it matches the construction
435
    computed_value = factor(value)
436
    # assert isinstance(computed_value_negative, factor.__annotations__["return"]), "wrong type"
437
    assert computed_value == factorisation, "wrong value"
438
439
440
def test_factor_bad_n_type_str():
441
    """ Test that :func:`lib.numbertheory.factor` 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 (118/100).

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

Loading history...
442
    with pytest.raises(TypeError):
443
        factor("123")
444
445
446
def test_factor_bad_n_type_float():
447
    """ Test that :func:`lib.numbertheory.factor` 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 (120/100).

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

Loading history...
448
    with pytest.raises(TypeError):
449
        factor(145.678)
450
451
452
@pytest.mark.parametrize("square_free", [6, 35, 77])
453
def test_perfect_power_exponent_correctness_square_free(square_free):
0 ignored issues
show
Coding Style Naming introduced by
The name test_perfect_power_expon...correctness_square_free does not conform to the function 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...
454
    """ Test the correctness of :func:`lib.numbertheory.perfect_power_exponent` for square-free inputs
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

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

Loading history...
455
456
    :raises AssertionError: if :func:`lib.numbertheory.perfect_power_exponent` returns the wrong type
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...
457
    :raises AssertionError: if :func:`lib.numbertheory.perfect_power_exponent` returns the wrong value
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

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

Loading history...
458
    """
459
460
    computed_value = perfect_power_exponent(square_free)
461
    assert isinstance(computed_value, perfect_power_exponent.__annotations__["return"]), "wrong type"
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...
462
    assert computed_value == 1, "wrong value"
463
464
465
@pytest.mark.parametrize("square_free", [6, 35, 77])
466
def test_perfect_power_exponent_correctness_not_square_free(square_free):
0 ignored issues
show
Coding Style Naming introduced by
The name test_perfect_power_expon...ectness_not_square_free does not conform to the function 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 the correctness of :func:`lib.numbertheory.perfect_power_exponent` for **non** square-free inputs
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...
468
469
    :raises AssertionError: if :func:`lib.numbertheory.perfect_power_exponent` returns the wrong type
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...
470
    :raises AssertionError: if :func:`lib.numbertheory.perfect_power_exponent` returns the wrong value
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

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

Loading history...
471
    """
472
473
    exponent = randint(2, 10)  # force each square-free number to be a perfect power
474
    computed_value = perfect_power_exponent(square_free ** exponent)
475
    assert isinstance(computed_value, perfect_power_exponent.__annotations__["return"]), "wrong type"
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...
476
    assert computed_value == exponent, "wrong value"
477
478
479
def test_perfect_power_exponent_bad_n_type_str():
0 ignored issues
show
Coding Style Naming introduced by
The name test_perfect_power_exponent_bad_n_type_str does not conform to the function 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...
480
    """ Test that :func:`lib.numbertheory.perfect_power_exponent` 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 (120/100).

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

Loading history...
481
    (``str``)
482
    """
483
    with pytest.raises(TypeError):
484
        perfect_power_exponent("123")
485
486
487
def test_perfect_power_exponent_bad_n_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_perfect_power_exponent_bad_n_type_float does not conform to the function 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...
488
    """ Test that :func:`lib.numbertheory.perfect_power_exponent` 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 (120/100).

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

Loading history...
489
    (``float``)
490
    """
491
    with pytest.raises(TypeError):
492
        perfect_power_exponent(145.678)
493
494
495
def test_perfect_power_exponent_bad_n_zero():
0 ignored issues
show
Coding Style Naming introduced by
The name test_perfect_power_exponent_bad_n_zero does not conform to the function 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...
496
    """ Test that :func:`lib.numbertheory.perfect_power_exponent` raises a ``ValueError`` for :math:`n=0` """
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...
497
    with pytest.raises(ValueError):
498
        perfect_power_exponent(0)
499