diff --git a/sorts/bucket_sort.py b/sorts/bucket_sort.py index 893c7ff3a23a..627ac161de9a 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -63,6 +63,9 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: >>> data = [5.5, 2.2, -1.1, 3.3, 0.0] >>> bucket_sort(data) == sorted(data) True + >>> bucket_sort(data, 2.5) + Traceback (most recent call last): + TypeError: bucket_count must be an integer >>> bucket_sort([1]) == [1] True >>> data = [-1.1, -1.5, -3.4, 2.5, 3.6, -3.3] @@ -73,6 +76,9 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: True """ + if not isinstance(bucket_count, int) or isinstance(bucket_count, bool): + raise TypeError("bucket_count must be an integer") + if len(my_list) == 0 or bucket_count <= 0: return []