Example #1
0
        public void TestTrieInsert()
        {
            // create root node.
            TrieNode root = new TrieNode();

            // insert the strings as dictionary
            TrieOperation operation = new TrieOperation();

            operation.Insert(root, "abc");
            operation.Insert(root, "abcd");
            operation.Insert(root, "aa");
            operation.Insert(root, "abbbaba");

            // assert for search operation
            Assert.IsTrue(operation.Search(root, "abc"));
            Assert.IsTrue(operation.Search(root, "abcd"));
            Assert.IsTrue(operation.Search(root, "abbbaba"));
            Assert.IsFalse(operation.Search(root, "abb"));

            // delete abc from Trie node
            operation.Delete(root, "abcd");

            // assert for search operation.
            Assert.IsFalse(operation.Search(root, "abcd"));
            Assert.IsTrue(operation.Search(root, "abc"));
            Assert.IsTrue(operation.Search(root, "abbbaba"));
        }
Example #2
0
        public void TestAutoCompleteFeature()
        {
            TrieNode root = new TrieNode();

            trieOperation.Insert(root, "abc");
            trieOperation.Insert(root, "abcd");
            trieOperation.Insert(root, "abbbaba");

            List <string> listOfString = this.AutoCompleteUsingTries(root, "ab");

            Assert.IsTrue(listOfString.Contains("abbbaba"));
            // output coming as abbc, abbcd
            // Assert.IsTrue(listOfString.Contains("abc"));
            // Assert.IsTrue(listOfString.Contains("abcd"));
        }
Example #3
0
        public void TestPrintValidWords()
        {
            TrieNode root = new TrieNode();

            string[] array = { "e", "o", "b", "a", "m", "g", "l" };

            // populate dictionary
            trieOperation.Insert(root, "go");
            trieOperation.Insert(root, "goal");
            trieOperation.Insert(root, "me");
            trieOperation.Insert(root, "eat");
            trieOperation.Insert(root, "boy");
            trieOperation.Insert(root, "run");

            List <string> listStr = this.PrintValidWords(root, array);

            Assert.IsTrue(listStr.Contains("go"));
            Assert.IsTrue(listStr.Contains("goal"));
            Assert.IsTrue(listStr.Contains("me"));

            // can it be printed ???
            Assert.IsTrue(listStr.Contains("bo"));
            Assert.IsTrue(listStr.Contains("boal"));
        }