Skip to content

Commit ea035e3

Browse files
committed
test: cover introsort heap sort range boundaries and default end
1 parent cf45d4c commit ea035e3

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎tests/test_sorts.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from sorts.gnome_sort import gnome_sort
3535
from sorts.heap_sort import heap_sort
3636
from sorts.insertion_sort import insertion_sort
37+
from sorts.intro_sort import heap_sort as intro_heap_sort
3738
from sorts.intro_sort import intro_sort as intro_sort_range
3839
from sorts.intro_sort import sort as intro_sort
3940
from sorts.iterative_merge_sort import iter_merge_sort
@@ -64,6 +65,22 @@ def test_heap_sort() -> None:
6465
assert heap_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
6566

6667

68+
@pytest.mark.parametrize(
69+
("start", "end"),
70+
[(start, end) for start in range(7) for end in [None, *range(start, 7)]],
71+
)
72+
def test_intro_heap_sort_range(start: int, end: int | None) -> None:
73+
collection = [100, 4, 1, 3, 1, -100]
74+
expected = collection[:start] + sorted(collection[start:end])
75+
if end is not None:
76+
expected += collection[end:]
77+
78+
result = intro_heap_sort(collection, start, end)
79+
80+
assert result is collection
81+
assert collection == expected
82+
83+
6784
@pytest.mark.parametrize("max_depth", [0, 1])
6885
def test_intro_sort_heap_fallback_preserves_surrounding_items(max_depth: int) -> None:
6986
collection = [100, *range(40, 0, -1), -100]

0 commit comments

Comments
 (0)