public void TrieRemoveByWordBenchmark() { for (int i = 0; i < _words.Length; i++) { _trie.RemoveWord(_words[i]); } Assert.AreEqual(0, _trie.Count); }
public void RemoveWord01() { Assert.AreEqual(1, trie.RemoveWord("this")); Assert.AreEqual(9, trie.GetWords().Count); Assert.AreEqual(1, trie.RemoveWord("the")); Assert.AreEqual(8, trie.GetWords().Count); Assert.Throws <ArgumentOutOfRangeException>(() => trie.RemoveWord("te")); Assert.AreEqual(8, trie.GetWords().Count); Assert.AreEqual(1, trie.RemoveWord("test")); Assert.AreEqual(7, trie.GetWords().Count); Assert.Throws <ArgumentOutOfRangeException>(() => trie.RemoveWord("word not present")); Assert.AreEqual(7, trie.GetWords().Count); Assert.AreEqual(1, trie.RemoveWord("123")); Assert.AreEqual(2, trie.RemoveWord("1")); foreach (var word in trie.GetWords()) { trie.RemoveWord(word); } Assert.AreEqual(0, trie.GetWords().Count); }
private static void TestTrie() { ITrie trie = BuildTestTrie(); var words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); words = trie.GetWordsByPrefix(""); Console.WriteLine($"Total words with empty prefix: {words.Count}"); words = trie.GetWordsByPrefix("th"); Console.WriteLine($"Total words with th prefix: {words.Count}"); words = trie.GetWordsByPrefix("TH"); Console.WriteLine($"Total words with TH prefix: {words.Count}"); words = trie.GetWordsByPrefix("z"); Console.WriteLine($"Total words with z prefix: {words.Count}"); words = trie.GetWordsByPrefix("Z"); Console.WriteLine($"Total words with Z prefix: {words.Count}"); words = trie.GetWordsByPrefix("1"); Console.WriteLine($"Total words with 1 prefix: {words.Count}"); bool hasWord = trie.ContainsWord("test"); Console.WriteLine($"Word 'test' found: {hasWord}"); hasWord = trie.ContainsWord("TEST"); Console.WriteLine($"Word 'TEST' found: {hasWord}"); hasWord = trie.ContainsWord("zz"); Console.WriteLine($"Word 'zz' found: {hasWord}"); hasWord = trie.ContainsWord("ZZ"); Console.WriteLine($"Word 'ZZ' found: {hasWord}"); hasWord = trie.ContainsWord("Microsoft"); Console.WriteLine($"Word 'Microsoft' found: {hasWord}"); trie = BuildTestTrie(); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie.RemoveWord("this"); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie.RemoveWord("the"); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie.RemoveWord("te"); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie.RemoveWord("test"); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie.RemoveWord("word not present"); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie.RemoveWord("123"); foreach (var word in trie.GetAllWords()) { trie.RemoveWord(word); } words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie = BuildTestTrie(); trie.RemovePrefix("1"); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie.RemovePrefix("th"); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie.RemovePrefix("x"); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); trie.RemovePrefix(""); words = trie.GetAllWords(); Console.WriteLine($"Total word count in trie: {words.Count}"); }