Self-test implementations.
221 {
223
224
226obj.
insert(
"abscond");
232obj.
insert(
"approach");
237
238assert(!obj.
search(
"appy"));
239 std::cout << "appy is not a word in trie" << std::endl;
240
241assert(!obj.
search(
"car"));
242 std::cout << "car is not a word in trie" << std::endl;
243assert(obj.
search(
"app"));
244assert(obj.
search(
"apple"));
245assert(obj.
search(
"apples"));
246assert(obj.
search(
"apps"));
247assert(obj.
search(
"apen"));
248assert(obj.
search(
"approach"));
249assert(obj.
search(
"about"));
250assert(obj.
search(
"abscond"));
251assert(obj.
search(
"bus"));
252assert(obj.
search(
"buses"));
253assert(obj.
search(
"Bounce"));
254assert(obj.
search(
"Apple"));
255
256 std::cout << "All the Inserted words are present in the trie" << std::endl;
257
258
274
276
277 std::cout << "All the tests passed for startwith method" << std::endl;
278
279
280
281std::vector<std::string> pred_words = obj.
predict_words(
"a");
282
284 std::cout << str << std::endl;
285 }
286 assert(pred_words.size() == 8);
287 std::cout << "Returned all words that start with prefix a " << std::endl;
289
290 for (const std::string& str : pred_words) {
291 std::cout << str << std::endl;
292 }
293
294 assert(pred_words.size() == 5);
295 std::cout << "Returned all words that start with prefix app " << std::endl;
297
298 for (const std::string& str : pred_words) {
299 std::cout << str << std::endl;
300 }
301
302 assert(pred_words.size() == 1);
303 std::cout << "Returned all words that start with prefix A " << std::endl;
305
306 for (const std::string& str : pred_words) {
307 std::cout << str << std::endl;
308 }
309
310 assert(pred_words.size() == 2);
311 std::cout << "Returned all words that start with prefix bu " << std::endl;
312
313
314
316assert(!obj.
search(
"app"));
317 std::cout << "word app is deleted sucessful" << std::endl;
318
320 for (const std::string& str : pred_words) {
321 std::cout << str << std::endl;
322 }
323 assert(pred_words.size() == 4);
324 std::cout << "app is deleted sucessful" << std::endl;
325
326
327
331
332 assert(pred_words.size() == 0);
333 std::cout << "No word starts with prefix h in trie" << std::endl;
334
335 std::cout << "All tests passed" << std::endl;
336}
Trie class, implementation of trie using hashmap in each trie node for all the characters of char16_t...
void insert(const std::string &word)
insert the string into the trie
void delete_word(std::string word)
delete a word/string from a trie
bool search(const std::string &word)
search a word/string inside the trie
std::vector< std::string > predict_words(const std::string &prefix)
predict/recommend a word that starts with a given prefix
bool startwith(const std::string &prefix)
search a word/string that starts with a given prefix
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4