Skip to content

Commit 4b2c606

Browse files
authored
Add test function for RadixNode operations
Added a test function for the RadixNode class to validate insertion, search, and deletion of words.
1 parent ff5b7fe commit 4b2c606

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

data_structures/trie/radix_tree.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ def print_tree(self, height: int = 0) -> None:
198198
value.print_tree(height + 1)
199199

200200

201+
def test_trie() -> None:
202+
words = "banana bananas bandana band apple all beast".split()
203+
root = RadixNode()
204+
root.insert_many(words)
205+
206+
assert all(root.find(word) for word in words)
207+
assert not root.find("bandanas")
208+
assert not root.find("apps")
209+
root.delete("all")
210+
assert not root.find("all")
211+
root.delete("banana")
212+
assert not root.find("banana")
213+
assert root.find("bananas")
214+
215+
201216
class TestRadixNode(unittest.TestCase):
202217
def test_trie(self) -> None:
203218
words = "banana bananas bandana band apple all beast".split()

0 commit comments

Comments
 (0)