Ejemplo n.º 1
0
        public void Remove_FirstTimeReturnsTrueNextTimeReturnsFalse()
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("zzz"));

            Assert.True(trie.Remove(new Word3("zzz")));
            Assert.False(trie.Remove(new Word3("zzz")));
            Assert.False(trie.Remove(new Word3("zzz")));

            trie.Add(new Word3("zzy"));

            Assert.True(trie.Remove(new Word3("zzy")));
            Assert.False(trie.Remove(new Word3("zzy")));
            Assert.False(trie.Remove(new Word3("zzy")));

            trie.Add(new Word3("zxy"));

            Assert.True(trie.Remove(new Word3("zxy")));
            Assert.False(trie.Remove(new Word3("zxy")));
            Assert.False(trie.Remove(new Word3("zxy")));

            trie.Add(new Word3("wxy"));

            Assert.True(trie.Remove(new Word3("wxy")));
            Assert.False(trie.Remove(new Word3("wxy")));
            Assert.False(trie.Remove(new Word3("wxy")));
        }
Ejemplo n.º 2
0
        public void Find_DisallowDuplicatesExactlyTwoMatches_ExecutesOnFoundTwice()
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("abc"));
            trie.Add(new Word3("abd"));
            trie.Add(new Word3("bcd"));
            trie.Add(new Word3("bce"));
            trie.Add(new Word3("cdf"));
            trie.Add(new Word3("def"));
            trie.Add(new Word3("cdg"));
            trie.Add(new Word3("deg"));
            Word3GridFinder finder = new Word3GridFinder(trie, false);

            List <Word3Grid> grids = new List <Word3Grid>();

            finder.Find(new Word3("abc"), g => grids.Add(g));

            Assert.Equal(2, grids.Count);
            Assert.Equal(new Word3("abc"), grids[0].Row1);
            Assert.Equal(new Word3("bcd"), grids[0].Row2);
            Assert.Equal(new Word3("def"), grids[0].Row3);
            Assert.Equal(new Word3("abc"), grids[1].Row1);
            Assert.Equal(new Word3("bcd"), grids[1].Row2);
            Assert.Equal(new Word3("deg"), grids[1].Row3);
        }
Ejemplo n.º 3
0
        public void Find_AllowDuplicatesMatchesFirstAndSecondRowButNoOtherWords_DoesNothing()
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("abc"));
            trie.Add(new Word3("bzz"));
            Word3GridFinder finder = new Word3GridFinder(trie, true);

            int count = 0;

            finder.Find(new Word3("abc"), g => ++ count);

            Assert.Equal(0, count);
        }
Ejemplo n.º 4
0
        public void Match1_WithMatches_ExecutesForEachPrefixMatch()
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("aab"));
            trie.Add(new Word3("aac"));
            trie.Add(new Word3("bac"));
            trie.Add(new Word3("baa"));
            List <string> wordsSeen = new List <string>();

            trie.Match1('a', w => wordsSeen.Add(w.ToString()));

            wordsSeen.Sort();
            Assert.Equal(2, wordsSeen.Count);
            Assert.Equal("aab", wordsSeen[0]);
            Assert.Equal("aac", wordsSeen[1]);
        }
Ejemplo n.º 5
0
        private static void MismatchOnLastColumnInnerTest(bool allowDuplicateWords)
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("art"));
            trie.Add(new Word3("loo"));
            trie.Add(new Word3("lek"));
            trie.Add(new Word3("all"));
            trie.Add(new Word3("roe"));
            Word3GridFinder finder = new Word3GridFinder(trie, allowDuplicateWords);

            int count = 0;

            finder.Find(new Word3("art"), g => ++ count);

            Assert.Equal(0, count);
        }
Ejemplo n.º 6
0
        public void Find_DisallowDuplicatesNoMatchesWithFiveWordsMatchingLastRowAndColumn_DoesNothing()
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("abc"));
            trie.Add(new Word3("aad"));
            trie.Add(new Word3("aac"));
            trie.Add(new Word3("bad"));
            trie.Add(new Word3("cde"));
            Word3GridFinder finder = new Word3GridFinder(trie, false);

            int count = 0;

            finder.Find(new Word3("abc"), g => ++ count);

            Assert.Equal(0, count);
        }
Ejemplo n.º 7
0
        public void Find_AllowDuplicatesExactlyOneMatchWithThreeWords_ExecutesOnFoundOnce()
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("abc"));
            trie.Add(new Word3("bcd"));
            trie.Add(new Word3("cde"));
            Word3GridFinder finder = new Word3GridFinder(trie, true);

            List <Word3Grid> grids = new List <Word3Grid>();

            finder.Find(new Word3("abc"), g => grids.Add(g));

            Assert.Equal(1, grids.Count);
            Assert.Equal(new Word3("abc"), grids[0].Row1);
            Assert.Equal(new Word3("bcd"), grids[0].Row2);
            Assert.Equal(new Word3("cde"), grids[0].Row3);
        }
Ejemplo n.º 8
0
        public void Contains_ReturnsTrueIfFoundFalseOtherwise()
        {
            Word3Trie trie = new Word3Trie();

            Assert.False(trie.Contains(new Word3("abc")));

            trie.Add(new Word3("abc"));

            Assert.True(trie.Contains(new Word3("abc")));
            Assert.False(trie.Contains(new Word3("abd")));

            trie.Add(new Word3("abd"));

            Assert.True(trie.Contains(new Word3("abd")));

            trie.Remove(new Word3("abc"));

            Assert.False(trie.Contains(new Word3("abc")));
        }
Ejemplo n.º 9
0
        public void Match2_NoMatch_DoesNothing()
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("bbb"));
            int count = 0;

            trie.Match2('b', 'a', w => ++ count);

            Assert.Equal(0, count);
        }
Ejemplo n.º 10
0
        private static void MatchInputWordButNoOtherWordsInnerTest(bool allowDuplicateWords)
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("abc"));
            Word3GridFinder finder = new Word3GridFinder(trie, allowDuplicateWords);

            int count = 0;

            finder.Find(new Word3("abc"), g => ++ count);

            Assert.Equal(0, count);
        }
Ejemplo n.º 11
0
        public void Enumerator_YieldsEveryValue()
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("aab"));
            trie.Add(new Word3("abc"));
            trie.Add(new Word3("aba"));
            trie.Add(new Word3("bbc"));
            trie.Add(new Word3("baa"));
            List <string> wordsSeen = new List <string>();

            foreach (Word3 word in trie)
            {
                wordsSeen.Add(word.ToString());
            }

            wordsSeen.Sort();
            Assert.Equal(5, wordsSeen.Count);
            Assert.Equal("aab", wordsSeen[0]);
            Assert.Equal("aba", wordsSeen[1]);
            Assert.Equal("abc", wordsSeen[2]);
            Assert.Equal("baa", wordsSeen[3]);
            Assert.Equal("bbc", wordsSeen[4]);
        }
Ejemplo n.º 12
0
        public void Find_DisallowDuplicatesNoMatchesWithSixWords_DoesNothing()
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("abc"));
            trie.Add(new Word3("abd"));
            trie.Add(new Word3("bcd"));
            trie.Add(new Word3("bce"));
            trie.Add(new Word3("def"));
            trie.Add(new Word3("cdg"));
            Word3GridFinder finder = new Word3GridFinder(trie, false);

            int count = 0;

            finder.Find(new Word3("abc"), g => ++ count);

            Assert.Equal(0, count);
        }
Ejemplo n.º 13
0
        private static void FindOneMatchSixWordsInnerTest(bool allowDuplicateWords)
        {
            Word3Trie trie = new Word3Trie();

            trie.Add(new Word3("pro"));
            trie.Add(new Word3("hop"));
            trie.Add(new Word3("ids"));
            trie.Add(new Word3("phi"));
            trie.Add(new Word3("rod"));
            trie.Add(new Word3("ops"));
            Word3GridFinder finder = new Word3GridFinder(trie, allowDuplicateWords);

            List <Word3Grid> grids = new List <Word3Grid>();

            finder.Find(new Word3("pro"), g => grids.Add(g));

            Assert.Equal(1, grids.Count);
            Assert.Equal(new Word3("pro"), grids[0].Row1);
            Assert.Equal(new Word3("hop"), grids[0].Row2);
            Assert.Equal(new Word3("ids"), grids[0].Row3);
        }