Skip to content

Commit 2cafc34

Browse files
committed
fix: reject non-integer bucket counts
Signed-off-by: ahmadalguydi <ahmadalgaidy@hotmail.com>
1 parent eea1bac commit 2cafc34

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

sorts/bucket_sort.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list:
6363
>>> data = [5.5, 2.2, -1.1, 3.3, 0.0]
6464
>>> bucket_sort(data) == sorted(data)
6565
True
66+
>>> bucket_sort(data, 2.5)
67+
Traceback (most recent call last):
68+
TypeError: bucket_count must be an integer
6669
>>> bucket_sort([1]) == [1]
6770
True
6871
>>> 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:
7376
True
7477
"""
7578

79+
if not isinstance(bucket_count, int) or isinstance(bucket_count, bool):
80+
raise TypeError("bucket_count must be an integer")
81+
7682
if len(my_list) == 0 or bucket_count <= 0:
7783
return []
7884

0 commit comments

Comments
 (0)