tests.unit.test_sequence
Module¶
This module contains all unit tests for the lib.sequence
module.
tests.unit.test_sequence
– Unit Tests¶
-
tests.unit.test_sequence.
test_continued_fraction
()¶ FIXME: unit tests still to be defined
-
tests.unit.test_sequence.
test_divisors_bad_n_type_float
()¶ Test that
lib.sequence.Divisors
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_sequence.
test_divisors_bad_n_type_str
()¶ Test that
lib.sequence.Divisors
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_sequence.
test_divisors_bad_n_zero
()¶ Test that
lib.sequence.Divisors
raises aValueError
for \(\mbox{n} = 0\)
-
tests.unit.test_sequence.
test_divisors_bad_proper_type_float
()¶ Test that
lib.sequence.Divisors
raises aTypeError
for a non-bool
value for proper (float
)
-
tests.unit.test_sequence.
test_divisors_bad_proper_type_str
()¶ Test that
lib.sequence.Divisors
raises aTypeError
for a non-bool
value for proper (str
)
-
tests.unit.test_sequence.
test_divisors_correctness
(n, proper, expected_answer)¶ Test the correctness of
lib.sequence.Divisors
using known answer testsParameters: - n (
int
) – the input value - proper (
bool
) – whether to only consider proper divisors or not - expected_answer (
Set
[int
]) – the expected answer
Raises: - AssertionError – if
lib.sequence.Divisors
produces the wrong type - AssertionError – if
lib.sequence.Divisors
produces the wrong value
- n (
-
tests.unit.test_sequence.
test_divisors_correctness_in
(n, proper, d, expected_answer)¶ Test the correctness of membership tests for
lib.sequence.Divisors
instances using known answer testsParameters: - n (
int
) – the input value - proper (
bool
) – whether to only consider proper divisors or not - d (
int
) – the input divisor - expected_answer (
bool
) – whether \(d\) is a [proper] divisor of \(n\)
Raises: - AssertionError – if
lib.sequence.Divisors
produces the wrong value for proper =False
- AssertionError – if
lib.sequence.Divisors
produces the wrong value for proper =True
- n (
-
tests.unit.test_sequence.
test_divisors_correctness_len
(n, n_divisors)¶ Test the correctness of length calculations of
lib.sequence.Divisors
instances using known answer testsParameters: - n (
int
) – the input value - n_divisors (
int
) – the expected number of divisors (all, not proper)
Raises: - AssertionError – if
lib.sequence.Divisors
produces the wrong value for proper =False
- AssertionError – if
lib.sequence.Divisors
produces the wrong value for proper =True
- n (
-
tests.unit.test_sequence.
test_divisors_in_bad_item_type_str
()¶ Test that
lib.sequence.Divisors
raises aTypeError
for a non-int
value for item (str
)
-
tests.unit.test_sequence.
test_divisorsrange_bad_proper_type_float
()¶ Test that
lib.sequence.DivisorsRange
raises aTypeError
for a non-bool
value for proper (float
)
-
tests.unit.test_sequence.
test_divisorsrange_bad_proper_type_str
()¶ Test that
lib.sequence.DivisorsRange
raises aTypeError
for a non-bool
value for proper (str
)
-
tests.unit.test_sequence.
test_divisorsrange_bad_upper_bound_type_float
()¶ Test that
lib.sequence.DivisorsRange
raises aTypeError
for a non-int
value for upper_bound (float
)
-
tests.unit.test_sequence.
test_divisorsrange_bad_upper_bound_type_str
()¶ Test that
lib.sequence.DivisorsRange
raises aTypeError
for a non-int
value for upper_bound (str
)
-
tests.unit.test_sequence.
test_divisorsrange_bad_upper_bound_zero
()¶ Test that
lib.sequence.DivisorsRange
raises aValueError
for \(upper\_bound = 0\)
-
tests.unit.test_sequence.
test_divisorsrange_correctness
(proper)¶ Test the correctness of
lib.sequence.DivisorsRange
using known answer testsThe 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.
Parameters: proper (
bool
) – whether to only consider proper divisors or notRaises: - AssertionError – if
lib.sequence.DivisorsRange
produces the wrong type - AssertionError – if
lib.sequence.DivisorsRange
produces the wrong value
- AssertionError – if
-
tests.unit.test_sequence.
test_factorials_correctness_batch
()¶ Test the correctness of
lib.sequence.Factorials
using known data
-
tests.unit.test_sequence.
test_factorials_correctness_getitem
(n, n_factorial)¶ Test the correctness of indexing
lib.sequence.Factorials
instances using known answer testsParameters: - n (
int
) – the input value - n_factorial (
int
) – the expected answer
Raises: - AssertionError – if
lib.sequence.Factorials
produces the wrong type - AssertionError – if
lib.sequence.Factorials
produces the wrong value
- n (
-
tests.unit.test_sequence.
test_factorials_correctness_in
(x, is_factorial)¶ Test the correctness of membership tests for
lib.sequence.Factorials
instances using known answer testsParameters: - x (
int
) – the input value - is_factorial (
bool
) – whether \(x = N!\) \(\exists N \in \mathbb{N}\) (i.e. \(x\) is factorial)
Raises: - AssertionError – if
lib.sequence.Factorials
produces the wrong type - AssertionError – if
lib.sequence.Factorials
produces the wrong value
- x (
-
tests.unit.test_sequence.
test_factorials_getitem_bad_item_negative
()¶ Test that
lib.sequence.Factorials
raises aValueError
for an index \(\mbox{item} \lt 0\)
-
tests.unit.test_sequence.
test_factorials_getitem_bad_item_type_float
()¶ Test that
lib.sequence.Factorials
raises aTypeError
for a non-int
value for an index item (float
)
-
tests.unit.test_sequence.
test_factorials_getitem_bad_item_type_str
()¶ Test that
lib.sequence.Factorials
raises aTypeError
for a non-int
value for an index item (str
)
-
tests.unit.test_sequence.
test_factorials_in_bad_item_type_str
()¶ Test that
lib.sequence.Factorials
raises aTypeError
for a non-int
value for x (str
)
-
tests.unit.test_sequence.
test_factorials_len
()¶ Test that
len
oflib.sequence.Factorials
instances raises aTypeError
-
tests.unit.test_sequence.
test_fibonaccis_correctness_batch
()¶ Test the correctness of
lib.sequence.Fibonaccis
using known data
-
tests.unit.test_sequence.
test_fibonaccis_correctness_getitem
(n, nth_fibonacci)¶ Test the correctness of
lib.sequence.Fibonaccis
using known answer testsParameters: - n (
int
) – the input value - nth_fibonacci (
int
) – the expected answer
Raises: - AssertionError – if
lib.sequence.Fibonaccis
produces the wrong type - AssertionError – if
lib.sequence.Fibonaccis
produces the wrong value
- n (
-
tests.unit.test_sequence.
test_fibonaccis_correctness_in
(x, is_fibonacci)¶ Test the correctness of membership tests for
lib.sequence.Fibonaccis
instances using known answer testsParameters: - x (
int
) – the input value - is_fibonacci (
bool
) – whether \(x\) is a Fibonacci number or not
Raises: - AssertionError – if
lib.sequence.Fibonaccis
produces the wrong type - AssertionError – if
lib.sequence.Fibonaccis
produces the wrong value
- x (
-
tests.unit.test_sequence.
test_fibonaccis_getitem_bad_item_negative
()¶ Test that
lib.sequence.Fibonaccis
raises aValueError
for an index \(\mbox{item} \lt 0\)
-
tests.unit.test_sequence.
test_fibonaccis_getitem_bad_item_type_float
()¶ Test that
lib.sequence.Fibonaccis
raises aTypeError
for a non-int
value for an index item (float
)
-
tests.unit.test_sequence.
test_fibonaccis_getitem_bad_item_type_str
()¶ Test that
lib.sequence.Fibonaccis
raises aTypeError
for a non-int
value for an index item (str
)
-
tests.unit.test_sequence.
test_fibonaccis_in_bad_item_type_str
()¶ Test that
lib.sequence.Fibonaccis
raises aTypeError
for a non-int
value for x (str
)
-
tests.unit.test_sequence.
test_fibonaccis_len
()¶ Test that
len
oflib.sequence.Fibonaccis
instances raises aTypeError
-
tests.unit.test_sequence.
test_figurates_in
()¶ Test that membership tests for
lib.sequence.Figurates
instances raises aNotImplementedError
-
tests.unit.test_sequence.
test_figurates_len
()¶ Test that
len
oflib.sequence.Figurates
instances raises aTypeError
-
tests.unit.test_sequence.
test_figurates_next
()¶ Test that iteration over
lib.sequence.Figurates
instances raises aNotImplementedError
-
tests.unit.test_sequence.
test_hexagonals_correctness_getitem
(n, nth_hexagonal)¶ Test the correctness of
lib.sequence.Hexagonals
using known answer testsParameters: - n (
int
) – the input value - nth_hexagonal (
int
) – the expected answer
Raises: - AssertionError – if
lib.sequence.Hexagonals
produces the wrong type - AssertionError – if
lib.sequence.Hexagonals
produces the wrong value
- n (
-
tests.unit.test_sequence.
test_hexagonals_correctness_in
(x, expected_answer)¶ Test the correctness of membership tests for
lib.sequence.Hexagonals
instances using known answer testsParameters: - x (
int
) – the input value - expected_answer (
bool
) – whether \(x\) is a hexagonal number or not
Raises: - AssertionError – if
lib.sequence.Hexagonals
produces the wrong type - AssertionError – if
lib.sequence.Hexagonals
produces the wrong value
- x (
-
tests.unit.test_sequence.
test_hexagonals_correctness_iter
()¶ Test the correctness of iteration over
lib.sequence.Hexagonals
instances using known answer testsRaises: - AssertionError – if
lib.sequence.Hexagonals
produces the wrong type - AssertionError – if
lib.sequence.Hexagonals
produces the wrong value
- AssertionError – if
-
tests.unit.test_sequence.
test_hexagonals_getitem_bad_item_type_float
()¶ Test that
lib.sequence.Hexagonals
raises aTypeError
for a non-int
value for an index item (float
)
-
tests.unit.test_sequence.
test_hexagonals_getitem_bad_item_type_str
()¶ Test that
lib.sequence.Hexagonals
raises aTypeError
for a non-int
value for an index item (str
)
-
tests.unit.test_sequence.
test_hexagonals_in_bad_item_type_float
()¶ Test that membership tests for
lib.sequence.Hexagonals
instances raise aTypeError
for a non-int
value (float
)
-
tests.unit.test_sequence.
test_hexagonals_in_bad_item_type_str
()¶ Test that membership tests for
lib.sequence.Hexagonals
instances raise aTypeError
for a non-int
value (str
)
-
tests.unit.test_sequence.
test_hexagonals_len
()¶ Test that
len
oflib.sequence.Hexagonals
instances raises aTypeError
-
tests.unit.test_sequence.
test_pandigitals_bad_n_negative
()¶ Test that
lib.sequence.Pandigitals
raises aValueError
for \(\mbox{n} \lt 0\)
-
tests.unit.test_sequence.
test_pandigitals_bad_n_type_float
()¶ Test that
lib.sequence.Pandigitals
raises aTypeError
for a non-int
value for n (float
)
-
tests.unit.test_sequence.
test_pandigitals_bad_n_type_str
()¶ Test that
lib.sequence.Pandigitals
raises aTypeError
for a non-int
value for n (str
)
-
tests.unit.test_sequence.
test_pandigitals_correctness
(n, n_pandigitals)¶ Test the correctness of
lib.sequence.Pandigitals
using known answer testsParameters: - n (
int
) – the input value - n_pandigitals (
Set
[int
]) – the expected answer
Raises: - AssertionError – if
lib.sequence.Pandigitals
produces the wrong type - AssertionError – if
lib.sequence.Pandigitals
produces the wrong value
- n (
-
tests.unit.test_sequence.
test_pandigitals_correctness_len
(n, n_pandigitals)¶ Test the correctness of length calculations of
lib.sequence.Pandigitals
instances using known answer testsParameters: - n (
int
) – the input value - n_pandigitals (
Set
[int
]) – the expected number of \(n\)-pandigitals
Raises: AssertionError – if
lib.sequence.Pandigitals
produces the wrong value- n (
-
tests.unit.test_sequence.
test_pentagonals_correctness_getitem
(n, nth_pentagonal)¶ Test the correctness of
lib.sequence.Pentagonals
using known answer testsParameters: - n (
int
) – the input value - nth_pentagonal (
int
) – the expected answer
Raises: - AssertionError – if
lib.sequence.Pentagonals
produces the wrong type - AssertionError – if
lib.sequence.Pentagonals
produces the wrong value
- n (
-
tests.unit.test_sequence.
test_pentagonals_correctness_in
(x, expected_answer)¶ Test the correctness of membership tests for
lib.sequence.Pentagonals
instances using known answer testsParameters: - x (
int
) – the input value - expected_answer (
bool
) – whether \(x\) is a pentagonal number or not
Raises: - AssertionError – if
lib.sequence.Pentagonals
produces the wrong type - AssertionError – if
lib.sequence.Pentagonals
produces the wrong value
- x (
-
tests.unit.test_sequence.
test_pentagonals_correctness_iter
()¶ Test the correctness of iteration over
lib.sequence.Pentagonals
instances using known answer testsRaises: - AssertionError – if
lib.sequence.Pentagonals
produces the wrong type - AssertionError – if
lib.sequence.Pentagonals
produces the wrong value
- AssertionError – if
-
tests.unit.test_sequence.
test_pentagonals_getitem_bad_item_type_float
()¶ Test that
lib.sequence.Pentagonals
raises aTypeError
for a non-int
value for an index item (float
)
-
tests.unit.test_sequence.
test_pentagonals_getitem_bad_item_type_str
()¶ Test that
lib.sequence.Pentagonals
raises aTypeError
for a non-int
value for an index item (str
)
-
tests.unit.test_sequence.
test_pentagonals_in_bad_item_type_float
()¶ Test that membership tests for
lib.sequence.Pentagonals
instances raise aTypeError
for a non-int
value (float
)
-
tests.unit.test_sequence.
test_pentagonals_in_bad_item_type_str
()¶ Test that membership tests for
lib.sequence.Pentagonals
instances raise aTypeError
for a non-int
value (str
)
-
tests.unit.test_sequence.
test_pentagonals_len
()¶ Test that
len
oflib.sequence.Pentagonals
instances raises aTypeError
-
tests.unit.test_sequence.
test_primes_bad_n_primes_float
()¶ Test that
lib.sequence.Primes()
raises aTypeError
for a non-int
value for n_primes (float
)
-
tests.unit.test_sequence.
test_primes_bad_n_primes_negative
()¶ Test that
lib.sequence.Primes()
raises aValueError
for \(\mbox{n_primes} \lt 0\)
-
tests.unit.test_sequence.
test_primes_bad_n_primes_str
()¶ Test that
lib.sequence.Primes()
raises aTypeError
for a non-int
value for n_primes (str
)
-
tests.unit.test_sequence.
test_primes_bad_upper_bound_float
()¶ Test that
lib.sequence.Primes()
raises aTypeError
for a non-int
value for upper_bound (float
)
-
tests.unit.test_sequence.
test_primes_bad_upper_bound_str
()¶ Test that
lib.sequence.Primes()
raises aTypeError
for a non-int
value for upper_bound (str
)
-
tests.unit.test_sequence.
test_primes_bad_upper_bound_zero
()¶ Test that
lib.sequence.Primes()
raises aValueError
for \(\mbox{upper_bound} = 0\)
-
tests.unit.test_sequence.
test_primes_correctness_batch
()¶ Test the correctness of
lib.sequence.Primes
using known data
-
tests.unit.test_sequence.
test_primes_correctness_n_primes
()¶ Test the correctness of
lib.sequence.Primes
(with n_primes) using known answer tests
-
tests.unit.test_sequence.
test_primes_correctness_n_primes_edge_case
()¶ Test the edge case where the estimate for \(p_n\) based on n_primes doesn’t hold (\(n \le 3\))
-
tests.unit.test_sequence.
test_primes_correctness_n_primes_iter
()¶ Test the correctness of iteration over
lib.sequence.Primes
(with n_primes) using known answer testsRaises: - AssertionError – if
lib.sequence.Primes
produces the wrong type - AssertionError – if
lib.sequence.Primes
produces the wrong value
- AssertionError – if
-
tests.unit.test_sequence.
test_primes_correctness_upper_bound
()¶ Test the correctness of
lib.sequence.Primes
(with upper_bound) using known answer tests
-
tests.unit.test_sequence.
test_primes_correctness_upper_bound_iter
()¶ Test the correctness of iteration over
lib.sequence.Primes
(with upper_bound) using known answer testsRaises: - AssertionError – if
lib.sequence.Primes
produces the wrong type - AssertionError – if
lib.sequence.Primes
produces the wrong value
- AssertionError – if
-
tests.unit.test_sequence.
test_primes_len
()¶ Test that
len
oflib.sequence.Primes
instances raises aTypeError
-
tests.unit.test_sequence.
test_sqrt_expansion
()¶ FIXME: unit tests still to be defined
-
tests.unit.test_sequence.
test_triangulars_correctness_getitem
(n, nth_triangular)¶ Test the correctness of
lib.sequence.Triangulars
using known answer testsParameters: - n (
int
) – the input value - nth_triangular (
int
) – the expected answer
Raises: - AssertionError – if
lib.sequence.Triangulars
produces the wrong type - AssertionError – if
lib.sequence.Triangulars
produces the wrong value
- n (
-
tests.unit.test_sequence.
test_triangulars_correctness_in
(x, expected_answer)¶ Test the correctness of membership tests for
lib.sequence.Triangulars
instances using known answer testsParameters: - x (
int
) – the input value - expected_answer (
bool
) – whether \(x\) is a triangular number or not
Raises: - AssertionError – if
lib.sequence.Triangulars
produces the wrong type - AssertionError – if
lib.sequence.Triangulars
produces the wrong value
- x (
-
tests.unit.test_sequence.
test_triangulars_correctness_iter
()¶ Test the correctness of iteration over
lib.sequence.Triangulars
instances using known answer testsRaises: - AssertionError – if
lib.sequence.Triangulars
produces the wrong type - AssertionError – if
lib.sequence.Triangulars
produces the wrong value
- AssertionError – if
-
tests.unit.test_sequence.
test_triangulars_getitem_bad_item_type_float
()¶ Test that
lib.sequence.Triangulars
raises aTypeError
for a non-int
value for an index item (float
)
-
tests.unit.test_sequence.
test_triangulars_getitem_bad_item_type_str
()¶ Test that
lib.sequence.Triangulars
raises aTypeError
for a non-int
value for an index item (str
)
-
tests.unit.test_sequence.
test_triangulars_in_bad_item_type_float
()¶ Test that membership tests for
lib.sequence.Triangulars
instances raise aTypeError
for a non-int
value (float
)
-
tests.unit.test_sequence.
test_triangulars_in_bad_item_type_str
()¶ Test that membership tests for
lib.sequence.Triangulars
instances raise aTypeError
for a non-int
value (str
)
-
tests.unit.test_sequence.
test_triangulars_len
()¶ Test that
len
oflib.sequence.Triangulars
instances raises aTypeError