-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Added doctest to heap.py #11129
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
Added doctest to heap.py #11129
Conversation
Hey @cclauss , @tianyizheng02 can you please review this PR I am unable to make more contributions as I have reached the limit of 5 open PR |
return the parent index of given child | ||
|
||
>>> h = Heap() | ||
>>> h.build_max_heap([103, 9, 1, 7, 11, 15, 25, 201, 209, 107, 5]) |
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.
Let's test with zero, negative integers, floating point numbers, and strings.
Let's test h.parent_index(12)
which is NOT in the heap.
We want to test how the algorithm works but also how it fails when given bad input.
@cclauss done with the changes |
hey @cclauss can you review this please. Thanks! |
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.
These tests prove that parent heap is buggy. It returns None
when it should be raising a ValueError and it returns float
when its type hints promised that it would only return int | None
. These bugs should be fixed in a future pull request.
* Added doctest to heap.py * Update heap.py
* Added doctest to heap.py * Update heap.py
Describe your change:
Contributes to #9943
Checklist: