Skip to content
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

Add type hints and tests. #2461

Merged
merged 13 commits into from Nov 14, 2020
Merged

Conversation

@NumberPiOso
Copy link
Contributor

@NumberPiOso NumberPiOso commented Sep 22, 2020

Continuing in line with #2128.

Add type hints and doctests corrected some little changes things that are not Python idiomatic.

Describe your change:

  • 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}.
NumberPiOso and others added 2 commits Sep 22, 2020
Sort collection and remove the assertion logic.

Co-authored-by: Christian Clauss <cclauss@me.com>
print(f"Iterative search: {target} found at positions: {result1}")
print(f"Recursive search: {target} found at positions: {result2}")
Comment on lines 165 to 166

This comment has been minimized.

@cclauss

cclauss Sep 22, 2020
Member

Does this provide the right answer if the user inputs an out-of-order list?

This comment has been minimized.

@NumberPiOso

NumberPiOso Sep 22, 2020
Author Contributor

It does not, I think it is better to return to the assert_sorted logic.

This comment has been minimized.

@cclauss

cclauss Sep 22, 2020
Member

OK but let's do it inline. We don't need a separate function.

This comment has been minimized.

@NumberPiOso

NumberPiOso Sep 22, 2020
Author Contributor

I guess my error could be avoided by testing that part of the code, however the use of inputs make it hard to test. Do you know any way that the main could be tested ?

This comment has been minimized.

@cclauss

cclauss Sep 22, 2020
Member

Sure.

def perform_searches(collection: List[int], target: int) -> None:
    # put lines 159, 160, and 162-168 under this function and
    # then you can test `perform_searches()` all day long.

This comment has been minimized.

@NumberPiOso

NumberPiOso Sep 24, 2020
Author Contributor

Ok, I guess thats the same than testing each one of the two searches functions.
I meant something to try to test different user inputs via the input function, not when the collection is already defined.

@53jk1
53jk1 approved these changes Oct 22, 2020
@cclauss
Copy link
Member

@cclauss cclauss commented Oct 23, 2020

Please resolve conflicts.

NumberPiOso and others added 6 commits Oct 29, 2020
github-actions github-actions
github-actions github-actions
…into ternary_sear
@NumberPiOso
Copy link
Contributor Author

@NumberPiOso NumberPiOso commented Nov 4, 2020

Good to go ! @cclauss

sorry for the delay.

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Nov 11, 2020

Hey, if possible can you update the variable names to snake_case and make some of the parameter names descriptive (the ones which are of length 1).

@NumberPiOso
Copy link
Contributor Author

@NumberPiOso NumberPiOso commented Nov 14, 2020

I hope we are good to go.

@dhruvmanila

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Yes! Thank you for your contribution! :)

@dhruvmanila dhruvmanila merged commit c6dd975 into TheAlgorithms:master Nov 14, 2020
2 checks passed
2 checks passed
pre-commit
Details
Travis CI - Pull Request Build Passed
Details
@NumberPiOso NumberPiOso deleted the NumberPiOso:ternary_sear branch Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.