Skip to content

Add delete to trie.py + tests #1177

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

Merged
merged 4 commits into from
Sep 13, 2019
Merged

Conversation

ksangeet9ap
Copy link
Contributor

@ksangeet9ap ksangeet9ap commented Sep 10, 2019

Hi, Thank you for this awesome repository. @cclauss kindly review the changes.

@ksangeet9ap
Copy link
Contributor Author

@cclauss Can you review the pull request?

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

Looks good to me. A few additional test ideas.


for key, value in node.nodes.items():
print_words(value, word + key)


def test():
words = ['banana', 'bananas', 'bandana', 'band', 'apple', 'all', 'beast']
words = ["banana", "bananas", "bandana", "band", "apple", "all", "beast"]
root = TrieNode()
root.insert_many(words)
Copy link
Member

@cclauss cclauss Sep 13, 2019

Choose a reason for hiding this comment

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

Could we test that len(the whole tree) == len(words)?

Could we add a test: assert all(root.find(word) for word in words)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you elaborate on how to go about this?

Copy link
Member

Choose a reason for hiding this comment

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

Let's forget the first request because this implementation does not have a __len__() method or a visit() method that would facilitate the creation of that test.

Copy link
Member

@cclauss cclauss Sep 13, 2019

Choose a reason for hiding this comment

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

assert all(root.find(word) for word in words) will ensure that we can find() each word that we just added.

Copy link
Member

Choose a reason for hiding this comment

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

@cclauss
Copy link
Member

cclauss commented Sep 13, 2019

While we are modifying this file, can you please remove the comments __ # noqa: E999 This syntax is Python 3 only__ because this repo does not support legacy Python.

@ksangeet9ap
Copy link
Contributor Author

ksangeet9ap commented Sep 13, 2019

Will do. @cclauss Do I need to add the test assert all(root.find(word) for word in words)?

@@ -56,20 +84,27 @@ def print_words(node: TrieNode, word: str): # noqa: E999 This syntax is Python
:return: None
"""
if node.is_leaf:
print(word, end=' ')
print(word, end=" ")

for key, value in node.nodes.items():
print_words(value, word + key)


def test():
Copy link
Member

@cclauss cclauss Sep 13, 2019

Choose a reason for hiding this comment

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

Unfortunately, our Travis CI automated tests are not finding the test() function. Can you try renaming this function to test_trie() in an attempt to satisfy https://docs.pytest.org/en/latest/goodpractices.html#test-discovery

Copy link
Contributor Author

@ksangeet9ap ksangeet9ap Sep 13, 2019

Choose a reason for hiding this comment

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

@cclauss Made some changes for Travis CI to detect the tests. Kindly review them. Referenced from data_structures/binary_tree/red_black_tree.py

@cclauss cclauss merged commit 768700b into TheAlgorithms:master Sep 13, 2019
@cclauss
Copy link
Member

cclauss commented Sep 13, 2019

Awesome work! Thanks for your contribution.

@ksangeet9ap
Copy link
Contributor Author

Thank you @cclauss for the help.

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Add delete to trie.py + tests

* Minor fixes + tests

* Remove noqa comments + modify tests for Travis CI to detect

* Minor improvement
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.

3 participants