Skip to content

#9943 Improve coverage special_numbers #12414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions maths/special_numbers/bell_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def bell_numbers(max_set_length: int) -> list[int]:
list: A list of Bell numbers for sets of lengths from 0 to max_set_length.

Examples:
>>> bell_numbers(-2)
Traceback (most recent call last):
...
ValueError: max_set_length must be non-negative
>>> bell_numbers(0)
[1]
>>> bell_numbers(1)
Expand Down
6 changes: 5 additions & 1 deletion maths/special_numbers/hamming_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def hamming(n_element: int) -> list:
:param n_element: The number of elements on the list
:return: The nth element of the list

>>> hamming(-5)
Traceback (most recent call last):
...
ValueError: n_element should be a positive number
>>> hamming(5)
[1, 2, 3, 4, 5]
>>> hamming(10)
Expand All @@ -22,7 +26,7 @@ def hamming(n_element: int) -> list:
"""
n_element = int(n_element)
if n_element < 1:
my_error = ValueError("a should be a positive number")
my_error = ValueError("n_element should be a positive number")
raise my_error

hamming_list = [1]
Expand Down
8 changes: 8 additions & 0 deletions maths/special_numbers/harshad_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def int_to_base(number: int, base: int) -> str:
Where 'base' ranges from 2 to 36.

Examples:
>>> int_to_base(0, 21)
'0'
>>> int_to_base(23, 2)
'10111'
>>> int_to_base(58, 5)
Expand All @@ -26,6 +28,10 @@ def int_to_base(number: int, base: int) -> str:
Traceback (most recent call last):
...
ValueError: 'base' must be between 2 and 36 inclusive
>>> int_to_base(-99, 16)
Traceback (most recent call last):
...
ValueError: number must be a positive integer
"""

if base < 2 or base > 36:
Expand Down Expand Up @@ -101,6 +107,8 @@ def harshad_numbers_in_base(limit: int, base: int) -> list[str]:
Traceback (most recent call last):
...
ValueError: 'base' must be between 2 and 36 inclusive
>>> harshad_numbers_in_base(-12, 6)
[]
"""

if base < 2 or base > 36:
Expand Down
Loading