-
-
Notifications
You must be signed in to change notification settings - Fork 46.2k
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
BST and RSA doctest #8693
BST and RSA doctest #8693
Conversation
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.
LGTM
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.
Few Suggestions :-
-
Handle potential errors: Currently, if there are any errors during the key file generation, the program will terminate abruptly. It would be helpful to handle potential errors more gracefully by catching exceptions and providing appropriate error messages to the user.
-
Consider using a different random number generator: The code uses the random module for generating
random
numbers. In cryptography, it's generally recommended to use a cryptographically secure random number generator (CSPRNG) for generating cryptographic keys. Consider using a CSPRNG from a cryptographic library such assecrets
module in Python orcryptography
library.
Hi @rohan472000, thanks for the review.
|
r""" | ||
A binary search Tree | ||
|
||
Example | ||
8 | ||
/ \ | ||
3 10 | ||
/ \ \ | ||
1 6 14 | ||
/ \ / | ||
4 7 13 | ||
|
||
>>> t = BinarySearchTree() | ||
>>> t.insert(8, 3, 6, 1, 10, 14, 13, 4, 7) | ||
>>> print(" ".join(repr(i.value) for i in t.traversal_tree())) | ||
8 3 1 6 4 7 10 14 13 | ||
>>> print(" ".join(repr(i.value) for i in t.traversal_tree(postorder))) | ||
1 4 7 6 3 13 14 10 8 | ||
>>> t.remove(20) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Value 20 not found | ||
>>> BinarySearchTree().search(6) | ||
Traceback (most recent call last): | ||
... | ||
IndexError: Warning: Tree is empty! please use another. | ||
|
||
Other example: | ||
|
||
>>> testlist = (8, 3, 6, 1, 10, 14, 13, 4, 7) | ||
>>> t = BinarySearchTree() | ||
>>> for i in testlist: | ||
... t.insert(i) | ||
|
||
Prints all the elements of the list in order traversal | ||
>>> print(t) | ||
{'8': ({'3': (1, {'6': (4, 7)})}, {'10': (None, {'14': (13, None)})})} | ||
|
||
Test existence | ||
>>> t.search(6) is not None | ||
True | ||
>>> t.search(-1) is not None | ||
False | ||
|
||
>>> t.search(6).is_right | ||
True | ||
>>> t.search(1).is_right | ||
False | ||
|
||
>>> t.get_max().value | ||
14 | ||
>>> t.get_min().value | ||
1 | ||
>>> t.empty() | ||
False | ||
>>> for i in testlist: | ||
... t.remove(i) | ||
>>> t.empty() | ||
True | ||
""" |
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.
I don't know if doctest.testmod
will run these doctests since they're not contained in any function or class. @cclauss Where should these examples go?
Also use 'is' instead of '==' Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
* rsa key doctest * move doctest to module docstring * all tests to doctest * moved is_right to property * is right test * fixed rsa doctest import * Test error when deleting non-existing element * fixing ruff EM102 * convert property 'is_right' to one-liner Also use 'is' instead of '==' Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com> * child instead of children Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com> * remove type hint * Update data_structures/binary_tree/binary_search_tree.py --------- Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.