-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Perfect square using binary search #2351
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
Perfect square using binary search #2351
Conversation
>>> perfect_square_binary_search(0) | ||
True | ||
>>> perfect_square_binary_search(10) | ||
False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests for -1, 1.1, "a", None, []?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I first add input validation inside the function, or should I just include those tests ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write the tests first and see how your function deals with unexpected input. The trick is to not write validation code if you don't have to. If your function is already going to raise an IndexError, TypeError, ValueError, etc. then you have no work to do. Just look for cases where your code would silently fail or would deliver nonsense results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.Thank you so much !
Things should be good now.
* Add perfect_square_binary_search * Update tests * Add tests
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.