sorts: make odd_even_sort support comparable items - #15307
Closed
deerred643-star wants to merge 2 commits into
Closed
deerred643-star wants to merge 2 commits into
deerred643-star wants to merge 2 commits into
Conversation
- make odd_even_sort generic over comparable item types - rewrite the two > comparisons as < so the algorithm only relies on __lt__, which is what the Comparable protocol guarantees - add non-integer doctest coverage (str, float) and a TypeError doctest for mixed non-comparable items - add odd_even_sort to test_sort_rejects_non_comparable_items - fix the docstring :param: name, which did not match the actual argument Ref TheAlgorithms#15234
Member
|
Please only fix one sort so we can have good first issues for others on October 1st. |
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 free
to 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.
Part of #15234
Summary
odd_even_sortgeneric over comparable item types ([T: Comparable])>comparisons as<so the algorithm only relies on__lt__, which is what theComparableprotocol guaranteesstr,float) and aTypeErrordoctest for mixed non-comparable itemsodd_even_sorttotest_sort_rejects_non_comparable_items:param:name, which did not match the actual argumentThe algorithm itself is unchanged: same odd/even phase loop, same swap logic, same complexity.
Tests
python -m doctest -v sorts/odd_even_sort.pypython -m pytest tests/test_sorts.pyruff check sorts/odd_even_sort.py tests/test_sorts.py