2
2
3
3
def test_Trie ():
4
4
5
- strings = ["A" , "to" , "tea" , "ted" , "ten" , "i" , "in" , "inn" ]
5
+ strings = ["A" , "to" , "tea" , "ted" , "ten" , "i" ,
6
+ "in" , "inn" , "Amfn" , "snbr" ]
6
7
trie = Trie ()
7
8
for string in strings :
8
9
trie .insert (string )
9
10
11
+ prefix_strings = ["te" , "t" , "Am" , "snb" ]
12
+
10
13
for string in strings :
14
+ assert trie .is_inserted (string )
15
+
16
+ for string in strings [::- 1 ]:
17
+ assert trie .is_inserted (string )
18
+
19
+ for string in prefix_strings :
11
20
assert trie .is_present (string )
21
+ assert not trie .is_inserted (string )
12
22
13
23
assert sorted (trie .strings_with_prefix ("t" )) == ['tea' , 'ted' , 'ten' , 'to' ]
14
24
assert sorted (trie .strings_with_prefix ("te" )) == ["tea" , "ted" , "ten" ]
@@ -23,7 +33,17 @@ def test_Trie():
23
33
trie .delete (string )
24
34
for present in strings :
25
35
if present == string :
26
- assert not trie .is_present (present )
36
+ assert not trie .is_inserted (present )
27
37
else :
28
38
assert trie .is_present (present )
39
+ assert trie .is_inserted (present )
29
40
strings .remove (string )
41
+
42
+ prefix_strings_1 = ["dict" , "dicts" , "dicts_lists_tuples" ]
43
+ trie_1 = Trie ()
44
+
45
+ for i in range (len (prefix_strings_1 )):
46
+ trie_1 .insert (prefix_strings_1 [i ])
47
+ for j in range (i + 1 ):
48
+ assert trie_1 .is_inserted (prefix_strings_1 [j ])
49
+ assert trie_1 .is_present (prefix_strings_1 [j ])
0 commit comments