added type hints and doctests to arithmetic_analysis/bisection.py by spamegg1 · Pull Request #2241 · TheAlgorithms/Python · GitHub
Skip to content

added type hints and doctests to arithmetic_analysis/bisection.py - #2241

Merged
cclauss merged 5 commits into
TheAlgorithms:masterfrom
spamegg1:master
Jul 27, 2020
Merged

cclauss merged 5 commits into
TheAlgorithms:masterfrom
spamegg1:master

Conversation

@spamegg1

Copy link
Copy Markdown
Contributor

continuing in line with #2128

Describe your change:

  • Fix a bug or typo in an existing algorithm?

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

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.

Why remove this code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I thought I was supposed to move all tests into the doctest. I guess I misunderstood. I can put it back in for sure.

Comment thread arithmetic_analysis/bisection.py Outdated
print("couldn't find root in [a,b]")
return
# then this algorithm can't find the root
print("couldn't find root in [", a, ",", b, "]")

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.

CONTRIBUTING.md says that algorithmic functions should not print. Please raise an exception instead of returning None.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, got it.

Put back print statement at the end, replaced algorithm's print statement with an exception.
@TravisBuddy

Copy link
Copy Markdown

Hey @spamegg1,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: c68a55b0-d005-11ea-81e3-a59d363db46c

Removed unnecessary type import "Optional"
Comment thread arithmetic_analysis/bisection.py Outdated
>>> bisection(lambda x: x ** 2 - 4 * x + 3, 4, 1000)
Traceback (most recent call last):
...
Exception: could not find root in given interval.

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.

ValueError please, not generic Exception.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK.

spamegg1 added 2 commits July 27, 2020 15:44
Replaced generic Exception with ValueError.
@spamegg1

Copy link
Copy Markdown
Contributor Author

My first time ever going through this CI process, I apologize for the mistakes and my too many commits. Thank you for your patience.

@TravisBuddy

Copy link
Copy Markdown

Travis tests have failed

Hey @spamegg1,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 1d5a89d0-d008-11ea-81e3-a59d363db46c

@spamegg1

spamegg1 commented Jul 27, 2020

Copy link
Copy Markdown
Contributor Author

Getting conflicting messages from Travis. It says tests failed, mentions a log but no link to it? And all checks have passed? I got the green check mark. Anyway, let me know what I should do.

@cclauss cclauss 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 work! Thanks.

@cclauss
cclauss merged commit bd74f20 into TheAlgorithms:master Jul 27, 2020
@spamegg1

Copy link
Copy Markdown
Contributor Author

Whew. That was quite stressful! I'll need a bit more practice with it. Thanks a lot, @cclauss

@NumberPiOso

Copy link
Copy Markdown
Contributor

Getting conflicting messages from Travis. It says tests failed, mentions a log but no link to it? And all checks have passed? I got the green check mark. Anyway, let me know what I should do.

May you explain please what was the issue ?

@cclauss

cclauss commented Jul 31, 2020

Copy link
Copy Markdown
Member

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
…eAlgorithms#2241)

* added type hints and doctests to arithmetic_analysis/bisection.py

continuing in line with TheAlgorithms#2128

* modified arithmetic_analysis/bisection.py

Put back print statement at the end, replaced algorithm's print statement with an exception.

* modified arithmetic_analysis/bisection.py

Removed unnecessary type import "Optional"

* modified arithmetic_analysis/bisection.py

Replaced generic Exception with ValueError.

* modified arithmetic_analysis/bisection.py

fixed 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.

4 participants