|
| 1 | +import unittest |
| 2 | + |
1 | 3 | """
|
2 | 4 | A Radix Tree is a data structure that represents a space-optimized
|
3 | 5 | trie (prefix tree) in whicheach node that is the only child is merged
|
4 | 6 | with its parent [https://en.wikipedia.org/wiki/Radix_tree]
|
5 | 7 | """
|
6 |
| -import unittest |
7 | 8 |
|
8 | 9 | class RadixNode:
|
9 | 10 | def __init__(self, prefix: str = "", is_leaf: bool = False) -> None:
|
@@ -204,30 +205,29 @@ def test_trie(self) -> None:
|
204 | 205 | root = RadixNode()
|
205 | 206 | root.insert_many(words)
|
206 | 207 |
|
207 |
| - self.assertTrue(all(root.find(word) for word in words)) |
208 |
| - self.assertFalse(root.find("bandanas")) |
209 |
| - self.assertFalse(root.find("apps")) |
| 208 | + assert all(root.find(word) for word in words) |
| 209 | + assert not root.find("bandanas") |
| 210 | + assert not root.find("apps") |
210 | 211 | root.delete("all")
|
211 |
| - self.assertFalse(root.find("all")) |
| 212 | + assert not root.find("all") |
212 | 213 | root.delete("banana")
|
213 |
| - self.assertFalse(root.find("banana")) |
214 |
| - self.assertTrue(root.find("bananas")) |
215 |
| - |
| 214 | + assert not root.find("banana") |
| 215 | + assert root.find("bananas") |
216 | 216 |
|
217 | 217 | def test_trie_2(self) -> None:
|
218 | 218 | '''
|
219 | 219 | now add a new test case which inserts
|
220 | 220 | foobbb, fooaaa, foo in the given order and checks for different assertions
|
221 |
| - ''' |
| 221 | + ''' |
222 | 222 | words = "foobbb fooaaa foo".split()
|
223 | 223 | root = RadixNode()
|
224 | 224 | root.insert_many(words)
|
225 | 225 |
|
226 |
| - self.assertTrue(all(root.find(word) for word in words)) |
| 226 | + assert all(root.find(word) for word in words) |
227 | 227 | root.delete("foo")
|
228 |
| - self.assertFalse(root.find("foo")) |
229 |
| - self.assertTrue(root.find("foobbb")) |
230 |
| - self.assertTrue(root.find("fooaaa")) |
| 228 | + assert not root.find("foo") |
| 229 | + assert root.find("foobbb") |
| 230 | + assert root.find("fooaaa") |
231 | 231 |
|
232 | 232 | if __name__ == "__main__":
|
233 | 233 | unittest.main()
|
0 commit comments