Uh oh!
There was an error while loading. Please reload this page.
tests: parametrize sorts/ over a shared input battery (follow-up to #13231) - #15185
Merged
cclauss merged 1 commit intoSep 4, 2026
Merged
Conversation
5 tasks
cclauss
enabled auto-merge (squash)
September 4, 2026 18:56
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Follow-up to #13231 (thanks @cclauss). That PR started a
tests/directory with a pytest forheap_sort; here I extend it into a parameterized suite so a single test covers the whole family of general-purpose comparison sorts insorts/.Each of these algorithms implements the same contract — return the input in non-decreasing order, i.e. agree with the built-in
sorted— sotest_sort_matches_builtinruns every one against a shared battery of inputs, including exactly the cases you suggested:plus empty / single-element / duplicate-heavy / already-sorted / reverse-sorted lists. That's 20 sorts × 9 inputs = 180 assertions (plus the original
test_heap_sort, kept intact), and all pass.Coverage is a curated list of the sorts that share the plain
sort(collection) -> collectioninterface. Domain-restricted sorts are intentionally excluded and the reason is documented in the module docstring (counting_sort/radix_sort/pigeon_sortare integer-only,bead_sortneeds non-negative ints,dutch_national_flag_sortexpects 0/1/2,bitonic_sortneeds a power-of-two length,topological_sortis graph-based,stalin_sort/wiggle_sortdon't fully sort).Two real bugs surfaced while building this (left out of the green suite; happy to fix in separate PRs if you'd like):
sorts/tim_sort.pyraisesIndexErroron an empty list.sorts/tree_sort.pysilently drops duplicates ([3,3,1,2,2,1]→[1,2,3]), because its BST insert ignores equal keys.This PR only touches
tests/test_sorts.py(no algorithm files changed).Checklist:
🤖 #ABotWroteThis