tests.unit.test_numbertheory
Module¶
This module contains all unit tests for the lib.numbertheory
package.
tests.unit.test_numbertheory
– Unit Tests¶
-
tests.unit.test_numbertheory.
test_divisor_count_bad_n_type_float
()¶ Test that
lib.numbertheory.divisor_count()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_divisor_count_bad_n_type_str
()¶ Test that
lib.numbertheory.divisor_count()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_divisor_count_bad_n_zero
()¶ Test that
lib.numbertheory.divisor_count()
raises aValueError
for a non-positive value for n
-
tests.unit.test_numbertheory.
test_divisor_count_correctness
(value, expected_answer)¶ Test the correctness of
lib.numbertheory.divisor_count()
using known answer testsParameters: - value (
int
) – the input value - expected_answer (
bool
) – the expected answer
Raises: - AssertionError – if
lib.numbertheory.divisor_count()
returns the wrong type - AssertionError – if
lib.numbertheory.divisor_count()
returns the wrong value
- value (
-
tests.unit.test_numbertheory.
test_divisor_sum_aliquot_bad_n_type_float
()¶ Test that
lib.numbertheory.divisor_sum_aliquot()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_divisor_sum_aliquot_bad_n_type_str
()¶ Test that
lib.numbertheory.divisor_sum_aliquot()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_divisor_sum_aliquot_bad_n_zero
()¶ Test that
lib.numbertheory.divisor_sum_aliquot()
raises aValueError
for a non-positive value for n
-
tests.unit.test_numbertheory.
test_divisor_sum_aliquot_correctness
(value, expected_answer)¶ Test the correctness of
lib.numbertheory.divisor_sum_aliquot()
using known answer testsParameters: - value (
int
) – the input value - expected_answer (
bool
) – the expected answer
Raises: - AssertionError – if
lib.numbertheory.divisor_sum_aliquot()
returns the wrong type - AssertionError – if
lib.numbertheory.divisor_sum_aliquot()
returns the wrong value
- value (
-
tests.unit.test_numbertheory.
test_divisor_sum_bad_n_type_float
()¶ Test that
lib.numbertheory.divisor_sum()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_divisor_sum_bad_n_type_str
()¶ Test that
lib.numbertheory.divisor_sum()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_divisor_sum_bad_n_zero
()¶ Test that
lib.numbertheory.divisor_sum()
raises aValueError
for a non-positive value for n
-
tests.unit.test_numbertheory.
test_divisor_sum_correctness
(value, expected_answer)¶ Test the correctness of
lib.numbertheory.divisor_sum()
using known answer testsParameters: - value (
int
) – the input value - expected_answer (
bool
) – the expected answer
Raises: - AssertionError – if
lib.numbertheory.divisor_sum()
returns the wrong type - AssertionError – if
lib.numbertheory.divisor_sum()
returns the wrong value
- value (
-
tests.unit.test_numbertheory.
test_divisors_sieve_bad_aggregate_invalid
()¶ Test that
lib.numbertheory.divisors_sieve()
raises aValueError
for invalid value of aggregate
-
tests.unit.test_numbertheory.
test_divisors_sieve_bad_aggregate_type_float
()¶ Test that
lib.numbertheory.divisors_sieve()
raises aTypeError
for a non-str
value for aggregate (float
)
-
tests.unit.test_numbertheory.
test_divisors_sieve_bad_upper_bound_negative
()¶ Test that
lib.numbertheory.divisors_sieve()
raises aValueError
for \(\mbox{upper_bound} \lt 0\)
-
tests.unit.test_numbertheory.
test_divisors_sieve_bad_upper_bound_type_float
()¶ Test that
lib.numbertheory.divisors_sieve()
raises aTypeError
for a non-int
value for upper_bound (float
)
-
tests.unit.test_numbertheory.
test_divisors_sieve_bad_upper_bound_type_str
()¶ Test that
lib.numbertheory.divisors_sieve()
raises aTypeError
for a non-int
value for upper_bound (str
)
-
tests.unit.test_numbertheory.
test_divisors_sieve_correctness
(upper_bound, proper, aggregate, expected_answer)¶ Test the correctness of
lib.numbertheory.divisors_sieve()
using known answer testsParameters: - upper_bound (
int
) – the upper bound of the sieve - proper (
bool
) – whether to consider just proper divisors or not - aggregate (
Optional
[str
]) – the aggregation function to apply - expected_answer (
Union
[set
,int
]) – the expected answer
Raises: - AssertionError – if
lib.numbertheory.divisors_sieve()
returns the wrong type - AssertionError – if
lib.numbertheory.divisors_sieve()
returns the wrong value
- upper_bound (
-
tests.unit.test_numbertheory.
test_divisors_sieve_correctness_not_proper
()¶ Test the correctness of the divisors prime sieve
lib.numbertheory.divisors_sieve()
The divisors yielded by this sieve are tested to ensure that they do divide the given integer \(n\), up to some moderate bound on \(n\). Additionally, it is checked that \(1\) is included as a divisor of along with \(n\) itself.
Raises: - AssertionError – if
lib.numbertheory.divisors_sieve()
yields the wrong type - AssertionError – if
lib.numbertheory.divisors_sieve()
yields the wrong value
- AssertionError – if
-
tests.unit.test_numbertheory.
test_divisors_sieve_correctness_proper
()¶ Test the correctness of the divisors prime sieve
lib.numbertheory.divisors_sieve()
The divisors yielded by this sieve are tested to ensure that they do divide the given integer \(n\), up to some moderate bound on \(n\). Additionally, it is checked that \(1\) is included as a proper divisor of \(n\) and that \(n\) is not.
Raises: - AssertionError – if
lib.numbertheory.divisors_sieve()
yields the wrong type - AssertionError – if
lib.numbertheory.divisors_sieve()
yields the wrong value
- AssertionError – if
-
tests.unit.test_numbertheory.
test_factor_bad_n_type_float
()¶ Test that
lib.numbertheory.factor()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_factor_bad_n_type_str
()¶ Test that
lib.numbertheory.factor()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_factor_correctness
(value, expected_answer)¶ Test the correctness of
lib.numbertheory.factor()
with known-answer-testsRaises: - AssertionError – if
lib.numbertheory.factor()
returns the wrong type - AssertionError – if
lib.numbertheory.factor()
returns the wrong value
- AssertionError – if
-
tests.unit.test_numbertheory.
test_factor_correctness_negative
(value, expected_answer)¶ Test the correctness of
lib.numbertheory.factor()
with known-answer-testsEach value is factored. This factorisation is combined with a factor of \(-1\) to give the expected factorisation of \(-value\). This negative value is then factored, and the two results are checked for equality.
Raises: - AssertionError – if
lib.numbertheory.factor()
returns the wrong type - AssertionError – if
lib.numbertheory.factor()
returns the wrong value - AssertionError – if
lib.numbertheory.factor()
doesn’t include a factor of \(-1\)
- AssertionError – if
-
tests.unit.test_numbertheory.
test_factor_correctness_random
()¶ Test the correctness of
lib.numbertheory.factor()
with known-answer-testsA random integer is built as a product of several small primes (selected with replacement); this random integer has a known factorisation.
lib.numbertheory.factor()
is used to factor the constructed number and it is compared to the known and expected factorisation.Raises: - AssertionError – if
lib.numbertheory.factor()
returns the wrong type - AssertionError – if
lib.numbertheory.factor()
returns the wrong value
- AssertionError – if
-
tests.unit.test_numbertheory.
test_is_even_bad_n_type_float
()¶ Test that
lib.numbertheory.is_even()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_is_even_bad_n_type_str
()¶ Test that
lib.numbertheory.is_even()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_is_even_correctness
(value, expected_answer)¶ Test the correctness of
lib.numbertheory.is_even()
using known answer testsParameters: - value (
int
) – the input value - expected_answer (
bool
) – the expected answer
Raises: - AssertionError – if
lib.numbertheory.is_even()
returns the wrong type - AssertionError – if
lib.numbertheory.is_even()
returns the wrong value
- value (
-
tests.unit.test_numbertheory.
test_is_odd_bad_n_type_float
()¶ Test that
lib.numbertheory.is_odd()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_is_odd_bad_n_type_str
()¶ Test that
lib.numbertheory.is_odd()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_is_odd_correctness
(value, expected_answer)¶ Test the correctness of
lib.numbertheory.is_odd()
using known answer testsParameters: - value (
int
) – the input value - expected_answer (
bool
) – the expected answer
Raises: - AssertionError – if
lib.numbertheory.is_odd()
returns the wrong type - AssertionError – if
lib.numbertheory.is_odd()
returns the wrong value
- value (
-
tests.unit.test_numbertheory.
test_is_probably_prime_bad_k_type_float
()¶ Test that
lib.numbertheory.is_probably_prime()
raises aTypeError
for a non-int
value for k (float
)
-
tests.unit.test_numbertheory.
test_is_probably_prime_bad_k_type_str
()¶ Test that
lib.numbertheory.is_probably_prime()
raises aTypeError
for a non-int
value for k (str
)
-
tests.unit.test_numbertheory.
test_is_probably_prime_bad_n_type_float
()¶ Test that
lib.numbertheory.is_probably_prime()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_is_probably_prime_bad_n_type_str
()¶ Test that
lib.numbertheory.is_probably_prime()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_is_probably_prime_correctness
()¶ Test the correctness of
lib.numbertheory.is_probably_prime()
Raises: - AssertionError – if
lib.numbertheory.is_probably_prime()
returns the wrong type - AssertionError – if
lib.numbertheory.is_probably_prime()
returns the wrong value
- AssertionError – if
-
tests.unit.test_numbertheory.
test_is_square_bad_n_type_float
()¶ Test that
lib.numbertheory.is_square()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_is_square_bad_n_type_str
()¶ Test that
lib.numbertheory.is_square()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_is_square_correctness
(value, expected_answer)¶ Test the correctness of
lib.numbertheory.is_square()
using known answer testsParameters: - value (
int
) – the input value - expected_answer (
bool
) – the expected answer
Raises: - AssertionError – if
lib.numbertheory.is_square()
returns the wrong type - AssertionError – if
lib.numbertheory.is_square()
returns the wrong value
- value (
-
tests.unit.test_numbertheory.
test_miller_rabin_bad_k_type_float
()¶ Test that
lib.numbertheory.miller_rabin()
raises aTypeError
for a non-int
value for k (float
)
-
tests.unit.test_numbertheory.
test_miller_rabin_bad_k_type_str
()¶ Test that
lib.numbertheory.miller_rabin()
raises aTypeError
for a non-int
value for k (str
)
-
tests.unit.test_numbertheory.
test_miller_rabin_bad_k_zero
()¶ Test that
lib.numbertheory.miller_rabin()
raises aValueError
for \(k=0\)
-
tests.unit.test_numbertheory.
test_miller_rabin_bad_n_too_small
()¶ Test that
lib.numbertheory.miller_rabin()
raises aValueError
for too small a value for n
-
tests.unit.test_numbertheory.
test_miller_rabin_bad_n_type_float
()¶ Test that
lib.numbertheory.miller_rabin()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_miller_rabin_bad_n_type_str
()¶ Test that
lib.numbertheory.miller_rabin()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_perfect_power_exponent_bad_n_type_float
()¶ Test that
lib.numbertheory.perfect_power_exponent()
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_numbertheory.
test_perfect_power_exponent_bad_n_type_str
()¶ Test that
lib.numbertheory.perfect_power_exponent()
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_numbertheory.
test_perfect_power_exponent_bad_n_zero
()¶ Test that
lib.numbertheory.perfect_power_exponent()
raises aValueError
for \(n=0\)
-
tests.unit.test_numbertheory.
test_perfect_power_exponent_correctness_not_square_free
(square_free)¶ Test the correctness of
lib.numbertheory.perfect_power_exponent()
for non square-free inputsRaises: - AssertionError – if
lib.numbertheory.perfect_power_exponent()
returns the wrong type - AssertionError – if
lib.numbertheory.perfect_power_exponent()
returns the wrong value
- AssertionError – if
-
tests.unit.test_numbertheory.
test_perfect_power_exponent_correctness_square_free
(square_free)¶ Test the correctness of
lib.numbertheory.perfect_power_exponent()
for square-free inputsRaises: - AssertionError – if
lib.numbertheory.perfect_power_exponent()
returns the wrong type - AssertionError – if
lib.numbertheory.perfect_power_exponent()
returns the wrong value
- AssertionError – if
-
tests.unit.test_numbertheory.
test_prime_sieve_bad_upper_bound_negative
()¶ Test that
lib.numbertheory.prime_sieve()
raises aValueError
for \(upper\_bound \lt 0\)
-
tests.unit.test_numbertheory.
test_prime_sieve_bad_upper_bound_too_big
()¶ Test that
lib.numbertheory.prime_sieve()
raises aValueError
for \(\mbox{upper_bound} \ge 10^{16}\)
-
tests.unit.test_numbertheory.
test_prime_sieve_bad_upper_bound_type_float
()¶ Test that
lib.numbertheory.prime_sieve()
raises aTypeError
for a non-int
value for upper_bound (float
)
-
tests.unit.test_numbertheory.
test_prime_sieve_bad_upper_bound_type_str
()¶ Test that
lib.numbertheory.prime_sieve()
raises aTypeError
for a non-int
value for upper_bound (str
)
-
tests.unit.test_numbertheory.
test_prime_sieve_correctness
(siever)¶ - Test the correctness of all prime sieves in
lib.numbertheory()
including: lib.numbertheory.primality.prime_sieve()
lib.numbertheory.primality.eratosthenes()
lib.numbertheory.primality.segmented_eratosthenes()
The integers yielded by these sieves are tested for primality, up to some moderate bound.
Raises: - AssertionError – if
siever(upper_bound)
yields the wrong type - AssertionError – if
siever(upper_bound)
yields the wrong value
- Test the correctness of all prime sieves in
-
tests.unit.test_numbertheory.
test_prime_sieve_correctness_bound
(upper_bound)¶ - Test the correctness of all prime sieves in
lib.numbertheory
including: lib.numbertheory.primality.prime_sieve()
lib.numbertheory.primality.eratosthenes()
lib.numbertheory.primality.segmented_eratosthenes()
The integers yielded by these sieves are tested for primality, up to some moderate bound. The parameter upper_bound is set to various values to ensure all sieves are utilised.
Raises: - AssertionError – if
lib.numbertheory.prime_sieve()
yields the wrong type - AssertionError – if
lib.numbertheory.prime_sieve()
yields the wrong value
- Test the correctness of all prime sieves in