Skip to content

Refactor cycle_sort #2072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2020
Merged

Conversation

l3str4nge
Copy link
Member

Describe your change:

  • fix function return value, because it wasn't list
  • added algorithm source url
  • added doctests
  • added typehints
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

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 have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Comment on lines +8 to +20
"""
>>> cycle_sort([4, 3, 2, 1])
[1, 2, 3, 4]

>>> cycle_sort([-4, 20, 0, -50, 100, -1])
[-50, -4, -1, 0, 20, 100]

>>> cycle_sort([-.1, -.2, 1.3, -.8])
[-0.8, -0.2, -0.1, 1.3]

>>> cycle_sort([])
[]
"""
Copy link
Member

Choose a reason for hiding this comment

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

Can we please break this into two PRs? The first PR should add the tests (lines 8 thru 20) and once that lands, the second PR could refactor the code.

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

Can we please break this into two PRs? The first PR should add the tests (lines 8 thru 20) and once that lands, the second PR could refactor the code.

@l3str4nge
Copy link
Member Author

Sure but it's worth it? Refactor consist only removing boilerplate code and variable names.

@cclauss
Copy link
Member

cclauss commented Jun 5, 2020

Yes. It is. This is a great habit to get into. Add tests first and make sure the code works as you expected. Once the tests pass make your changes and make sure that the tests continue to pass. This is the way that the pros always do it.

@l3str4nge l3str4nge requested a review from cclauss June 5, 2020 06:51
@cclauss cclauss merged commit 20b21e5 into TheAlgorithms:master Jun 5, 2020
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Refactor cycle_sort

* Undo changes to keep only doctests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants