Skip to content

Commit 438f337

Browse files
committed
fix(sorts): validate bucket count in bucket_sort
1 parent 22899ed commit 438f337

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

sorts/bucket_sort.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
from __future__ import annotations
3232

3333

34-
def bucket_sort(my_list: list, bucket_count: int = 10) -> list:
34+
def bucket_sort(
35+
my_list: list[int | float], bucket_count: int = 10
36+
) -> list[int | float]:
3537
"""
3638
>>> data = [-1, 2, -5, 0]
3739
>>> bucket_sort(data) == sorted(data)
@@ -65,6 +67,10 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list:
6567
True
6668
>>> bucket_sort([1]) == [1]
6769
True
70+
>>> bucket_sort([1, 2, 3], 2.5)
71+
Traceback (most recent call last):
72+
...
73+
TypeError: bucket_count must be an integer
6874
>>> data = [-1.1, -1.5, -3.4, 2.5, 3.6, -3.3]
6975
>>> bucket_sort(data) == sorted(data)
7076
True
@@ -73,6 +79,8 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list:
7379
True
7480
"""
7581

82+
if not isinstance(bucket_count, int):
83+
raise TypeError("bucket_count must be an integer")
7684
if len(my_list) == 0 or bucket_count <= 0:
7785
return []
7886

0 commit comments

Comments
 (0)