@@ -69,6 +69,13 @@ describe('Trie', () => {
6969      expect ( trie . startsWith ( 'do' ) ) . toEqual ( true ) ; 
7070    } ) ; 
7171
72+     it ( 'should match full words if partial is set' ,  ( )  =>  { 
73+       expect ( trie . search ( 'dogs' ,  { 
74+         partial : true , 
75+       } ) ) . toEqual ( true ) ; 
76+       expect ( trie . startsWith ( 'dogs' ) ) . toEqual ( true ) ; 
77+     } ) ; 
78+ 
7279    it ( 'should not match non existing words' ,  ( )  =>  { 
7380      expect ( trie . search ( 'doors' ) ) . toEqual ( false ) ; 
7481    } ) ; 
@@ -129,5 +136,53 @@ describe('Trie', () => {
129136        expect ( words ) . toEqual ( [ ] ) ; 
130137      } ) ; 
131138    } ) ; 
139+ 
140+     describe ( 'remove' ,  ( )  =>  { 
141+       it ( 'should remove a word' ,  ( )  =>  { 
142+         trie  =  new  Trie ( ) ; 
143+         trie . insert ( 'a' ) ; 
144+         expect ( trie . remove ( 'a' ) ) . toEqual ( true ) ; 
145+         expect ( trie . getAllWords ( ) ) . toEqual ( [ ] ) ; 
146+       } ) ; 
147+ 
148+       it ( 'should remove word and keep other words' ,  ( )  =>  { 
149+         trie  =  new  Trie ( ) ; 
150+         trie . insert ( 'a' ) ; 
151+         trie . insert ( 'ab' ) ; 
152+         expect ( trie . remove ( 'a' ) ) . toEqual ( true ) ; 
153+         expect ( trie . getAllWords ( ) ) . toEqual ( [ 'ab' ] ) ; 
154+       } ) ; 
155+ 
156+       it ( 'should remove surrounding word' ,  ( )  =>  { 
157+         trie  =  new  Trie ( ) ; 
158+         trie . insert ( 'a' ) ; 
159+         trie . insert ( 'ab' ) ; 
160+         expect ( trie . remove ( 'ab' ) ) . toEqual ( true ) ; 
161+         expect ( trie . getAllWords ( ) ) . toEqual ( [ 'a' ] ) ; 
162+       } ) ; 
163+ 
164+       it ( 'should return false when word is not found' ,  ( )  =>  { 
165+         expect ( trie . remove ( 'not there' ) ) . toBe ( false ) ; 
166+       } ) ; 
167+ 
168+       it ( 'should remove words in between and still match' ,  ( )  =>  { 
169+         expect ( trie . remove ( 'dog' ) ) . toBe ( true ) ; 
170+         expect ( trie . search ( 'dogs' ) ) . toBe ( true ) ; 
171+         expect ( trie . startsWith ( 'dog' ) ) . toBe ( true ) ; 
172+         expect ( trie . getAllWords ( ) ) . toEqual ( [ 
173+           'dogs' ,  'door' ,  'day' ,  'cat' , 
174+         ] ) ; 
175+       } ) ; 
176+ 
177+       it ( 'should remove word and no longer match partials' ,  ( )  =>  { 
178+         expect ( trie . remove ( 'dogs' ) ) . toBe ( true ) ; 
179+         expect ( trie . search ( 'dogs' ) ) . toBe ( false ) ; 
180+         expect ( trie . search ( 'dog' ) ) . toBe ( true ) ; 
181+         expect ( trie . startsWith ( 'dog' ) ) . toBe ( true ) ; 
182+         expect ( trie . getAllWords ( ) ) . toEqual ( [ 
183+           'dog' ,  'door' ,  'day' ,  'cat' , 
184+         ] ) ; 
185+       } ) ; 
186+     } ) ; 
132187  } ) ; 
133188} ) ; 
0 commit comments