コード例 #1
0
        public void PrefixTree_CountMatchesNumberOfWordsInTree()
        {
            PrefixTree tree = new PrefixTree();
            tree.Insert("CART");
            tree.Insert("DINO");
            tree.Insert("TAR");
            tree.Insert("PEN");

            Assert.AreEqual(4, tree.Count);
        }
コード例 #2
0
        public void GivenString_Put_ShoulGeneratePrefixTree()
        {
            var  tree   = new PrefixTree(new TrieTreeNode());
            bool result = tree.Insert("apple");

            Assert.IsTrue(result);
        }
コード例 #3
0
        public void PrefixTree_ExactMatchWorksWithWrongCase()
        {
            PrefixTree tree = new PrefixTree();
            tree.Insert("PATRIK");

            Assert.IsFalse(tree.IsExactMatch("pat"));
            Assert.IsTrue(tree.IsExactMatch("patrik"));
        }
コード例 #4
0
        public void PrefixTree_ExactMatch()
        {
            PrefixTree tree = new PrefixTree();
            tree.Insert("PATRIK");

            Assert.IsFalse(tree.IsExactMatch("PAT"));
            Assert.IsTrue(tree.IsExactMatch("PATRIK"));
        }
コード例 #5
0
        public void GivenValidInputString_StartWith_ShouldReturnTrue()
        {
            var tree = new PrefixTree(new TrieTreeNode());

            tree.Insert("apple");
            var result = tree.StartWith("app");

            Assert.IsTrue(result);
        }
コード例 #6
0
        public void GivenValidInputStringButInvalidSearch_Search_ShouldReturnFalse()
        {
            var tree = new PrefixTree(new TrieTreeNode());

            tree.Insert("apple");
            var result = tree.Search("app");

            Assert.IsFalse(result);
        }
コード例 #7
0
        public void GivenString_Get_ShouldReturnTrue()
        {
            var tree = new PrefixTree(new TrieTreeNode());

            tree.Insert("apple");
            var result = tree.Search("apple");

            Assert.IsTrue(result);
        }
コード例 #8
0
        public void PrefixTree_PartialMatch()
        {
            PrefixTree tree = new PrefixTree();
            tree.Insert("PATRIK");

            Assert.IsTrue(tree.IsPartialMatch("P"));
            Assert.IsTrue(tree.IsPartialMatch("PAT"));
            Assert.IsFalse(tree.IsPartialMatch("PAD"));
            Assert.IsFalse(tree.IsPartialMatch("T"));
            Assert.IsFalse(tree.IsPartialMatch(""));
        }
コード例 #9
0
 public PrefixTree Build()
 {
     PrefixTree tree = new PrefixTree();
     string[] lines = File.ReadAllLines(_file.FullName);
     foreach (string line in lines)
     {
         if (line.StartsWith("CUSTOM") || line.StartsWith("BASEWORDS") || line.StartsWith("DEFINITION"))
         {
             continue;
         }
         else if (line.StartsWith("COMPOUND"))
         {
             string[] parts = line.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
             if (parts.Length == 2)
             {
                 string[] words = parts[1].Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);
                 foreach (string word in words)
                 {
                     string temp = word.Trim();
                     tree.Insert(temp);
                 }
             }
         }
         else
         {
             string[] parts = line.Split(new char[] { '>' }, StringSplitOptions.RemoveEmptyEntries);
             if (parts.Length == 2)
             {
                 string[] words = parts[1].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                 foreach (string word in words)
                 {
                     tree.Insert(word);
                 }
             }
         }
     }
     return tree;
 }
コード例 #10
0
        public void PrefixTree_WordsAreInsertedAsLowercase()
        {
            PrefixTree tree = new PrefixTree();
            tree.Insert("CART");
            tree.Insert("DINO");
            tree.Insert("TAR");
            tree.Insert("PEN");

            Assert.IsNotNull(tree.Root.FindNode('c'));
        }
コード例 #11
0
        public void PrefixTree_PartialMatchWorksWithWrongCase()
        {
            PrefixTree tree = new PrefixTree();
            tree.Insert("PATRIK");

            Assert.IsTrue(tree.IsPartialMatch("p"));
            Assert.IsTrue(tree.IsPartialMatch("pat"));
            Assert.IsFalse(tree.IsPartialMatch("pad"));
            Assert.IsFalse(tree.IsPartialMatch("t"));
        }