Skip to content

Commit ace0391

Browse files
Add unit tests for comparable items and TypeError in slowsort
1 parent a6d20ad commit ace0391

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎tests/test_sorts.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,23 @@ def test_sort_matches_builtin(sort, case) -> None:
128128
def test_sort_rejects_non_comparable_items(sort) -> None:
129129
with pytest.raises(TypeError):
130130
sort([1, "a"])
131+
import pytest
132+
from sorts.slowsort import slowsort
133+
134+
135+
def test_slowsort_comparable_types():
136+
# Test with strings
137+
words = ["banana", "apple", "cherry", "date"]
138+
slowsort(words)
139+
assert words == ["apple", "banana", "cherry", "date"]
140+
141+
# Test with floats and negative numbers
142+
floats = [3.14, -1.0, 2.5, 0.0]
143+
slowsort(floats)
144+
assert floats == [-1.0, 0.0, 2.5, 3.14]
145+
146+
147+
def test_slowsort_type_error_on_incomparable():
148+
mixed = [1, "a"]
149+
with pytest.raises(TypeError):
150+
slowsort(mixed)

0 commit comments

Comments
 (0)