Skip to content

Commit f77c2ff

Browse files
committed
Added validation to confirm the number of buckets is an integer.
1 parent 25bcced commit f77c2ff

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

sorts/bucket_sort.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,19 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list:
7171
>>> data = [9, 2, 7, 1, 5]
7272
>>> bucket_sort(data) == sorted(data)
7373
True
74+
>>> data = [12, 7 , 22, 11, 4]
75+
>>> bucket_sort(data, 2.5)
76+
Traceback (most recent call last):
77+
...
78+
TypeError: bucket_count must be an integer
7479
"""
7580

7681
if len(my_list) == 0 or bucket_count <= 0:
7782
return []
7883

84+
if not isinstance(bucket_count, int):
85+
raise TypeError("bucket_count must be an integer")
86+
7987
min_value, max_value = min(my_list), max(my_list)
8088
if min_value == max_value:
8189
return my_list

0 commit comments

Comments
 (0)