Exemple #1
0
        public void Match_EmptyTrie_DoesNothing()
        {
            WordTrie trie = new WordTrie();

            int count = 0;

            trie.Match(new Word("aaaa"), w => ++ count);

            Assert.Equal(0, count);
        }
Exemple #2
0
        public void Match_FirstLevelOneMatch_InvokesOnAllMatches()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("ab"));

            List <string> words = new List <string>();

            trie.Match(new Word("a"), w => words.Add(w.ToString()));

            Assert.Equal(new string[] { "AB" }, words.ToArray());
        }
Exemple #3
0
        public void Match_FirstCharMatchButNoOtherMatch_DoesNothing()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("abbb"));

            int count = 0;

            trie.Match(new Word("ac"), w => ++ count);

            Assert.Equal(0, count);
        }
Exemple #4
0
        public void Match_FirstCharNoMatch_DoesNothing()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("baaa"));

            int count = 0;

            trie.Match(new Word("aaaa"), w => ++ count);

            Assert.Equal(0, count);
        }
Exemple #5
0
        public void Match_FirstAndSecondLevelTwoMatches_InvokesOnAllMatches()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("abc"));
            trie.Add(new Word("abd"));

            List <string> words = new List <string>();

            trie.Match(new Word("ab"), w => words.Add(w.ToString()));

            words.Sort();
            Assert.Equal(new string[] { "ABC", "ABD" }, words.ToArray());
        }
Exemple #6
0
        public void Match_OneCharFirstLevelWild_InvokesOnAllMatches()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("abc"));
            trie.Add(new Word("xbc"));
            trie.Add(new Word("zbc"));

            List <string> words = new List <string>();

            trie.Match(new Word("?"), w => words.Add(w.ToString()));

            words.Sort();
            Assert.Equal(new string[] { "ABC", "XBC", "ZBC" }, words.ToArray());
        }
Exemple #7
0
        public void Match_FirstLevelThreeDeepMatches_InvokesOnAllMatches()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("adefghijkl"));
            trie.Add(new Word("acdefghi"));
            trie.Add(new Word("abcdefg"));

            List <string> words = new List <string>();

            trie.Match(new Word("a"), w => words.Add(w.ToString()));

            words.Sort();
            Assert.Equal(new string[] { "ABCDEFG", "ACDEFGHI", "ADEFGHIJKL" }, words.ToArray());
        }
Exemple #8
0
        public void Match_ThreeCharsSecondLevelWild_InvokesOnAllMatches()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("abc"));
            trie.Add(new Word("acc"));
            trie.Add(new Word("axa"));
            trie.Add(new Word("axc"));

            List <string> words = new List <string>();

            trie.Match(new Word("a?c"), w => words.Add(w.ToString()));

            words.Sort();
            Assert.Equal(new string[] { "ABC", "ACC", "AXC" }, words.ToArray());
        }
Exemple #9
0
        public void Match_TwoCharsFirstLevelWild_InvokesOnAllMatches()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("abc"));
            trie.Add(new Word("bbb"));
            trie.Add(new Word("bbxx"));
            trie.Add(new Word("ccccc"));

            List <string> words = new List <string>();

            trie.Match(new Word("?b"), w => words.Add(w.ToString()));

            words.Sort();
            Assert.Equal(new string[] { "ABC", "BBB", "BBXX" }, words.ToArray());
        }
Exemple #10
0
        public void MatchMaxLength_ThreeCharsAllWildMaxLength4_InvokesOnAllMatches()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("a"));
            trie.Add(new Word("bb"));
            trie.Add(new Word("ccc"));
            trie.Add(new Word("dddd"));
            trie.Add(new Word("eeeee"));

            List <string> words = new List <string>();

            trie.Match(new Word("???"), 4, w => words.Add(w.ToString()));

            words.Sort();
            Assert.Equal(new string[] { "CCC", "DDDD" }, words.ToArray());
        }
Exemple #11
0
        public void MatchMaxLength_TwoCharsMaxLength3_InvokesOnAllMatches()
        {
            WordTrie trie = new WordTrie();

            trie.Add(new Word("a"));
            trie.Add(new Word("bb"));
            trie.Add(new Word("cc"));
            trie.Add(new Word("ccc"));
            trie.Add(new Word("ccd"));
            trie.Add(new Word("cccc"));
            trie.Add(new Word("dddd"));
            trie.Add(new Word("eeeee"));

            List <string> words = new List <string>();

            trie.Match(new Word("cc"), 3, w => words.Add(w.ToString()));

            words.Sort();
            Assert.Equal(new string[] { "CC", "CCC", "CCD", }, words.ToArray());
        }