Skip to content

tests: parametrize sorts/ over a shared input battery (follow-up to #13231) - #15185

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:tests/parametrize-sorts
Sep 4, 2026
Merged

tests: parametrize sorts/ over a shared input battery (follow-up to #13231)#15185
cclauss merged 1 commit into
TheAlgorithms:masterfrom
priya-sundaram-dev:tests/parametrize-sorts

Conversation

@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Describe your change:

Follow-up to #13231 (thanks @cclauss). That PR started a tests/ directory with a pytest for heap_sort; here I extend it into a parameterized suite so a single test covers the whole family of general-purpose comparison sorts in sorts/.

Each of these algorithms implements the same contract — return the input in non-decreasing order, i.e. agree with the built-in sorted — so test_sort_matches_builtin runs every one against a shared battery of inputs, including exactly the cases you suggested:

sort([10, -10, -1, 1, 0]) # negativessort([1.1, -1.1, -1, 1, 0]) # floatssort("Python!") # strings

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) -> collection interface. Domain-restricted sorts are intentionally excluded and the reason is documented in the module docstring (counting_sort/radix_sort/pigeon_sort are integer-only, bead_sort needs non-negative ints, dutch_national_flag_sort expects 0/1/2, bitonic_sort needs a power-of-two length, topological_sort is graph-based, stalin_sort/wiggle_sort don'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.py raises IndexError on an empty list.
  • sorts/tree_sort.py silently 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).

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

This is a test-only change (extends the new tests/ directory), so none of the four boxes above apply.

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

🤖 #ABotWroteThis

@algorithms-keeperalgorithms-keeperBot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Sep 4, 2026
@priya-sundaram-devpriya-sundaram-dev mentioned this pull request Sep 4, 2026
5 tasks
@cclauss
cclauss enabled auto-merge (squash) September 4, 2026 18:56

@cclausscclauss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@algorithms-keeperalgorithms-keeperBot removed the awaiting reviews This PR is ready to be reviewed label Sep 4, 2026
@cclauss
cclauss merged commit 9cac6fb into TheAlgorithms:masterSep 4, 2026
5 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementThis PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@priya-sundaram-dev@cclauss