@@ -167,7 +167,8 @@ class TrieTests: XCTestCase {
167167 let trieCopy = NSKeyedUnarchiver . unarchiveObject ( withFile: filePath) as? Trie
168168 XCTAssertEqual ( trieCopy? . count, trie. count)
169169 }
170-
170+
171+ /// Tests whether word prefixes are properly found and returned.
171172 func testFindWordsWithPrefix( ) {
172173 let trie = Trie ( )
173174 trie. insert ( word: " test " )
@@ -190,4 +191,28 @@ class TrieTests: XCTestCase {
190191 let wordsUpperCase = trie. findWordsWithPrefix ( prefix: " Te " )
191192 XCTAssertEqual ( wordsUpperCase. sorted ( ) , [ " team " , " test " ] )
192193 }
194+
195+ /// Tests whether word prefixes are properly detected on a boolean contains() check.
196+ func testContainsWordMatchPrefix( ) {
197+ let trie = Trie ( )
198+ trie. insert ( word: " test " )
199+ trie. insert ( word: " another " )
200+ trie. insert ( word: " exam " )
201+ let wordsAll = trie. contains ( word: " " , matchPrefix: true )
202+ XCTAssertEqual ( wordsAll, true )
203+ let words = trie. contains ( word: " ex " , matchPrefix: true )
204+ XCTAssertEqual ( words, true )
205+ trie. insert ( word: " examination " )
206+ let words2 = trie. contains ( word: " exam " , matchPrefix: true )
207+ XCTAssertEqual ( words2, true )
208+ let noWords = trie. contains ( word: " tee " , matchPrefix: true )
209+ XCTAssertEqual ( noWords, false )
210+ let unicodeWord = " 😬😎 "
211+ trie. insert ( word: unicodeWord)
212+ let wordsUnicode = trie. contains ( word: " 😬 " , matchPrefix: true )
213+ XCTAssertEqual ( wordsUnicode, true )
214+ trie. insert ( word: " Team " )
215+ let wordsUpperCase = trie. contains ( word: " Te " , matchPrefix: true )
216+ XCTAssertEqual ( wordsUpperCase, true )
217+ }
193218}
0 commit comments