Skip to content

Added doctests to OddEvenTraposition #2152

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 25, 2020

Conversation

l3str4nge
Copy link
Member

Describe your change:

Added missing doctests. Refactor will be in second PR

  • 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}.

@l3str4nge l3str4nge requested a review from cclauss June 24, 2020 14:27
Copy link
Member

@ruppysuppy ruppysuppy left a comment

Choose a reason for hiding this comment

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

if arr[i + 1] < arr[i]:
                arr[i], arr[i + 1] = arr[i + 1], arr[i]

can be replaced by:

if arr[i + 1] < arr[i]: arr[i], arr[i + 1] = arr[i + 1], arr[i]


>>> OddEvenTransposition([-.1, 1.1, .1, -2.9])
[-2.9, -0.1, 0.1, 1.1]
"""
for i in range(0, len(arr)):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for i in range(0, len(arr)):
for i in range(len(arr)):

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR is mainly for doctests. Refactoring will be in other as @cclauss suggested before.

@cclauss
Copy link
Member

cclauss commented Jun 25, 2020

Please change main() to use arr as the variable name instead of shadowing Python’s builtin list.

Perhaps replace the first four lines of main() with:

    arr = list(range(10, 0, -1))

@l3str4nge l3str4nge requested a review from cclauss June 25, 2020 06:22
@cclauss
Copy link
Member

cclauss commented Jun 25, 2020

You already have my approval.

@l3str4nge
Copy link
Member Author

So can I merge?

@cclauss
Copy link
Member

cclauss commented Jun 25, 2020

Squash and merge

@l3str4nge l3str4nge merged commit 9e2206e into TheAlgorithms:master Jun 25, 2020
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Added doctests

* Change __main__ content
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.

3 participants