tests.unit.test_digital Module

This module contains all unit tests for the lib.digital module.

tests.unit.test_digital – Unit Tests

class tests.unit.test_digital.TestDigitSum

Bases: object

A collection of positive and negative unit tests for the lib.digital.digit_sum() function

classmethod get_import()

Get and return the lib.digital.digit_sum() function

Note

this isolates the import so any error/exception is raised by individual unit tests.

Returns:the lib.digital.digit_sum() function
test_digit_sum_bad_base_negative()

Test that lib.digital.digit_sum() raises a ValueError for a negative value for base

test_digit_sum_bad_base_type_float()

Test that lib.digital.digit_sum() raises a TypeError for a non-int value for base (float)

test_digit_sum_bad_base_type_str()

Test that lib.digital.digit_sum() raises a TypeError for a non-int value for base (str)

test_digit_sum_bad_n_negative()

Test that lib.digital.digit_sum() raises a ValueError for a negative value for n

test_digit_sum_bad_n_type_float()

Test that lib.digital.digit_sum() raises a TypeError for a non-int value for n (float)

test_digit_sum_bad_n_type_str()

Test that lib.digital.digit_sum() raises a TypeError for a non-int value for n (str)

test_digit_sum_correctness(value, expected_answer)

Test the correctness of lib.digital.digit_sum() using known answer tests

Parameters:
  • value (int) – the input value
  • expected_answer (int) – the expected answer
Raises:
class tests.unit.test_digital.TestDigitsOf

Bases: object

A collection of positive and negative unit tests for the lib.digital.digits_of() function

classmethod get_import()

Get and return the lib.digital.digits_of() function

Note

this isolates the import so any error/exception is raised by individual unit tests.

Returns:the lib.digital.digits_of() function
test_digits_of_bad_base_negative()

Test that lib.digital.digits_of() raises a ValueError for a negative value for base

test_digits_of_bad_base_type_float()

Test that lib.digital.digits_of() raises a TypeError for a non-int value for base (float)

test_digits_of_bad_base_type_str()

Test that lib.digital.digits_of() raises a TypeError for a non-int value for base (str)

test_digits_of_bad_n_negative()

Test that lib.digital.digits_of() raises a ValueError for a negative value for n

test_digits_of_bad_n_type_float()

Test that lib.digital.digits_of() raises a TypeError for a non-int value for n (float)

test_digits_of_bad_n_type_str()

Test that lib.digital.digits_of() raises a TypeError for a non-int value for n (str)

test_digits_of_correctness(n, base, expected_answer)

Test the correctness of lib.digital.digits_of() using known answer tests

Parameters:
  • n (int) – the input integer
  • base (int) – the base to build digits in
  • expected_answer (int) – the expected answer
Raises:
class tests.unit.test_digital.TestDigitsToNum

Bases: object

A collection of positive and negative unit tests for the lib.digital.digits_to_num() function

classmethod get_import()

Get and return the lib.digital.digits_to_sum() function

Note

this isolates the import so any error/exception is raised by individual unit tests.

Returns:the lib.digital.digits_to_num() function
test_digits_to_num_bad_base_negative()

Test that lib.digital.digits_to_num() raises a ValueError for a negative value for base

test_digits_to_num_bad_base_type_float()

Test that lib.digital.digits_to_num() raises a TypeError for a non-int value for base (float)

test_digits_to_num_bad_base_type_str()

Test that lib.digital.digits_to_num() raises a TypeError for a non-int value for base (str)

test_digits_to_num_bad_digits_negative_element()

Test that lib.digital.digits_to_num() raises a ValueError for a negative value in digits

test_digits_to_num_bad_digits_type_float()

Test that lib.digital.digits_to_num() raises a TypeError for a non-list value for digits (float)

test_digits_to_num_bad_digits_type_list_of_float()

Test that lib.digital.digits_to_num() raises a TypeError for a list of non-int values for digits (list of float)

test_digits_to_num_bad_digits_type_list_of_str()

Test that lib.digital.digits_to_num() raises a TypeError for a list of non-int values for digits (list of str)

test_digits_to_num_bad_digits_type_str()

Test that lib.digital.digits_to_num() raises a TypeError for a non-list value for digits (str)

test_digits_to_num_correctness(digits, base, expected_answer)

Test the correctness of lib.digital.digits_to_num() using known answer tests

Parameters:
  • digits (List[int]) – the input digits
  • base (int) – the base to build digits in
  • expected_answer (int) – the expected answer
Raises:
class tests.unit.test_digital.TestIsPalindrome

Bases: object

A collection of positive and negative unit tests for the lib.digital.is_palindrome() function

classmethod get_import()

Get and return the lib.digital.is_palindrome() function

Note

this isolates the import so any error/exception is raised by individual unit tests.

Returns:the lib.digital.is_palindrome() function
test_is_palindrome_bad_base_negative()

Test that lib.digital.is_palindrome() raises a ValueError for a negative value for base

test_is_palindrome_bad_base_type_float()

Test that lib.digital.is_palindrome() raises a TypeError for a non-int value for base (float)

test_is_palindrome_bad_base_type_str()

Test that lib.digital.is_palindrome() raises a TypeError for a non-int value for base (str)

test_is_palindrome_bad_n_negative()

Test that lib.digital.is_palindrome() raises a ValueError for a negative value for n

test_is_palindrome_bad_n_type_float()

Test that lib.digital.is_palindrome() raises a TypeError for a non-int value for n (float)

test_is_palindrome_bad_n_type_str()

Test that lib.digital.is_palindrome() raises a TypeError for a non-int value for n (str)

test_is_palindrome_correctness(value, base, expected_answer)

Test the correctness of lib.digital.is_palindrome() using known answer tests

Parameters:
  • value (int) – the input value
  • base (int) – consider value in the given base
  • expected_answer (int) – the expected answer
Raises:
test_is_palindrome_unsupported_base(base)

Test that lib.digital.is_palindrome() raises a ValueError for unsupported values of base

Parameters:base (int) – consider value in the given base
class tests.unit.test_digital.TestIsPandigital

Bases: object

A collection of positive and negative unit tests for the lib.digital.is_pandigital() function

classmethod get_import()

Get and return the lib.digital.is_pandigital() function

Note

this isolates the import so any error/exception is raised by individual unit tests.

Returns:the lib.digital.is_pandigital() function
test_is_pandigital_bad_base_negative()

Test that lib.digital.is_pandigital() raises a ValueError for a negative value for base

test_is_pandigital_bad_base_type_float()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for base (float)

test_is_pandigital_bad_base_type_str()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for base (str)

test_is_pandigital_bad_d_negative()

Test that lib.digital.is_pandigital() raises a ValueError for a negative value for d

test_is_pandigital_bad_d_type_float()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for d (float)

test_is_pandigital_bad_d_type_str()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for d (str)

test_is_pandigital_bad_int_n_negative()

Test that lib.digital.is_pandigital() raises a ValueError for a negative value for n

test_is_pandigital_bad_int_n_type_float()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for n (float)

test_is_pandigital_bad_int_n_type_str()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for n (str)

test_is_pandigital_bad_list_n_negative()

Test that lib.digital.is_pandigital() raises a ValueError for a negative value for n

test_is_pandigital_bad_list_n_type_float()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for n (float)

test_is_pandigital_bad_list_n_type_str()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for n (str)

test_is_pandigital_bad_lower_negative()

Test that lib.digital.is_pandigital() raises a ValueError for a negative value for lower

test_is_pandigital_bad_lower_type_float()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for lower (float)

test_is_pandigital_bad_lower_type_str()

Test that lib.digital.is_pandigital() raises a TypeError for a non-int value for lower (str)

test_is_pandigital_correctness(value, d, expected_answer)

Test the correctness of lib.digital.is_pandigital() using known answer tests

Parameters:
  • value (Union[int, List[int]]) – the input value
  • d (int) – parameter in d-pandigital
  • expected_answer (int) – the expected answer
Raises:
class tests.unit.test_digital.TestNumDigits

Bases: object

A collection of positive and negative unit tests for the lib.digital.num_digits() function

classmethod get_import()

Get and return the lib.digital.num_digits() function

Note

this isolates the import so any error/exception is raised by individual unit tests.

Returns:the lib.digital.num_digits() function
test_num_digits_bad_base_negative()

Test that lib.digital.num_digits() raises a ValueError for a negative value for base

test_num_digits_bad_base_type_float()

Test that lib.digital.num_digits() raises a TypeError for a non-int value for base (float)

test_num_digits_bad_base_type_str()

Test that lib.digital.num_digits() raises a TypeError for a non-int value for base (str)

test_num_digits_bad_n_negative()

Test that lib.digital.num_digits() raises a ValueError for a negative value for n

test_num_digits_bad_n_type_float()

Test that lib.digital.num_digits() raises a TypeError for a non-int value for n (float)

test_num_digits_bad_n_type_str()

Test that lib.digital.num_digits() raises a TypeError for a non-int value for n (str)

test_num_digits_correctness_kat(value, expected_answer)

Test the correctness of lib.digital.num_digits() using known answer tests

Parameters:
  • value (int) – the input value
  • expected_answer (int) – the expected answer
Raises:
test_num_digits_correctness_random()

Test the correctness of lib.digital.num_digits() using random inputs with predictable answers

That is, generate a random length (n) and a random integer of that length (x). Then, check that lib.digital.num_digits() evaluated at x equals n.

Raises: