Skip to content

Commit c32e7f3

Browse files
committed
test: adjust test_sorts.py for rec_insertion_sort's None-returning in-place contract
rec_insertion_sort no longer fits the shared SORTS battery (which asserts on a returned value), so it's removed from that tuple and given its own parametrized in-place test (checked against sorted()) plus its own non-comparable-items rejection test.
1 parent a07324c commit c32e7f3

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

tests/test_sorts.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
``bead_sort`` needs non-negative integers, ``dutch_national_flag_sort`` expects
1313
0/1/2, ``bitonic_sort`` needs a power-of-two length, ``topological_sort`` works
1414
on a graph, and ``stalin_sort``/``wiggle_sort`` deliberately do not fully sort).
15+
``rec_insertion_sort`` is also left out of the battery: it sorts in place and
16+
returns ``None`` rather than the sorted collection, so it is exercised
17+
separately below.
1518
"""
1619

1720
from dataclasses import dataclass
@@ -67,7 +70,6 @@ def test_heap_sort() -> None:
6770
odd_even_sort,
6871
patience_sort,
6972
quick_sort,
70-
rec_insertion_sort,
7173
selection_sort,
7274
shell_sort,
7375
stooge_sort,
@@ -110,6 +112,14 @@ def test_sort_matches_builtin(sort, case) -> None:
110112
assert list(sort(list(case))) == sorted(case)
111113

112114

115+
@pytest.mark.parametrize("case", CASES, ids=repr)
116+
def test_rec_insertion_sort(case) -> None:
117+
"""``rec_insertion_sort`` sorts in place and returns ``None``."""
118+
collection = list(case)
119+
assert rec_insertion_sort(collection, len(collection)) is None
120+
assert collection == sorted(case)
121+
122+
113123
@pytest.mark.parametrize(
114124
"sort",
115125
[
@@ -123,11 +133,15 @@ def test_sort_matches_builtin(sort, case) -> None:
123133
gnome_sort,
124134
insertion_sort,
125135
merge_sort,
126-
rec_insertion_sort,
127136
selection_sort,
128137
],
129138
ids=lambda f: f.__name__,
130139
)
131140
def test_sort_rejects_non_comparable_items(sort) -> None:
132141
with pytest.raises(TypeError):
133142
sort([1, "a"])
143+
144+
145+
def test_rec_insertion_sort_rejects_non_comparable_items() -> None:
146+
with pytest.raises(TypeError):
147+
rec_insertion_sort([1, "a"], 2)

0 commit comments

Comments
 (0)