|
34 | 34 | from sorts.gnome_sort import gnome_sort |
35 | 35 | from sorts.heap_sort import heap_sort |
36 | 36 | from sorts.insertion_sort import insertion_sort |
| 37 | +from sorts.intro_sort import heap_sort as intro_heap_sort |
37 | 38 | from sorts.intro_sort import intro_sort as intro_sort_range |
38 | 39 | from sorts.intro_sort import sort as intro_sort |
39 | 40 | from sorts.iterative_merge_sort import iter_merge_sort |
@@ -64,6 +65,22 @@ def test_heap_sort() -> None: |
64 | 65 | assert heap_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] |
65 | 66 |
|
66 | 67 |
|
| 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 | + |
67 | 84 | @pytest.mark.parametrize("max_depth", [0, 1]) |
68 | 85 | def test_intro_sort_heap_fallback_preserves_surrounding_items(max_depth: int) -> None: |
69 | 86 | collection = [100, *range(40, 0, -1), -100] |
|
0 commit comments