Example #1
0
        public void InsertAndFindCheck()
        {
            var trie = new Algorithms.Trie.Trie();

            trie.Insert("Hello");
            trie.Insert("Hey");
            Assert.Equal(2, trie.FindPrefix("H").Count);
            Assert.Equal(2, trie.FindPrefix("He").Count);
            Assert.Single(trie.FindPrefix("Hel"));
            Assert.Single(trie.FindPrefix("Hey"));
        }
Example #2
0
        public void ClearCheck()
        {
            var trie = new Algorithms.Trie.Trie();

            trie.Insert("Hello");
            trie.Insert("Hey");
            Assert.Equal(2, trie.FindPrefix("H").Count);
            Assert.Empty(trie.FindPrefix("h"));
            trie.Clear();
            Assert.Empty(trie.FindPrefix("h"));
            Assert.Empty(trie.FindPrefix("H"));
        }
Example #3
0
        public void DuplicateInsertAndFindCheck()
        {
            var trie = new Algorithms.Trie.Trie();

            trie.Insert("Hello");
            trie.Insert("Hey");
            Assert.Equal(2, trie.FindPrefix("H").Count);
            trie.Insert("Hello");
            trie.Insert("Hey");
            Assert.Equal(2, trie.FindPrefix("H").Count);
            trie.Insert("hello");
            trie.Insert("hey");
            Assert.Equal(2, trie.FindPrefix("h").Count);
            Assert.Equal(2, trie.FindPrefix("H").Count);
        }
Example #4
0
        public void CaseSensitiveFindCheck()
        {
            var trie = new Algorithms.Trie.Trie();

            trie.Insert("Hello");
            trie.Insert("Hey");
            Assert.Equal(2, trie.FindPrefix("H").Count);
            Assert.Empty(trie.FindPrefix("h"));
            trie.Insert("Hello");
            trie.Insert("Hey");
            Assert.Empty(trie.FindPrefix("h"));
            Assert.Equal(2, trie.FindPrefix("H").Count);
            trie.Insert("hello");
            trie.Insert("hey");
            Assert.Equal(2, trie.FindPrefix("h").Count);
            Assert.Equal(2, trie.FindPrefix("H").Count);
            Assert.Equal(2, trie.FindPrefix("He").Count);
            Assert.Single(trie.FindPrefix("Hel"));
            Assert.Single(trie.FindPrefix("Hey"));
        }
Example #5
0
        public void EmptyCheck()
        {
            var trie = new Algorithms.Trie.Trie();

            Assert.Empty(trie.FindPrefix("h"));
        }
Example #6
0
 private void InsertNode(char c, Trie node)
 {
     _children.Add(c, node);
 }