Skip to content

Commit d739ccc

Browse files
committed
test: cover introsort heap fallback range boundaries
1 parent d57fc7c commit d739ccc

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎tests/test_sorts.py‎

Lines changed: 12 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 intro_sort as intro_sort_range
3738
from sorts.intro_sort import sort as intro_sort
3839
from sorts.iterative_merge_sort import iter_merge_sort
3940
from sorts.merge_insertion_sort import merge_insertion_sort
@@ -63,6 +64,17 @@ def test_heap_sort() -> None:
6364
assert heap_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5]
6465

6566

67+
@pytest.mark.parametrize("max_depth", [0, 1])
68+
def test_intro_sort_heap_fallback_preserves_surrounding_items(max_depth: int) -> None:
69+
collection = [100, *range(40, 0, -1), -100]
70+
expected = [100, *range(1, 41), -100]
71+
72+
result = intro_sort_range(collection, 1, 41, 16, max_depth)
73+
74+
assert result is collection
75+
assert collection == expected
76+
77+
6678
SORTS = (
6779
binary_insertion_sort,
6880
bubble_sort_iterative,

0 commit comments

Comments
 (0)