public void Suffix_Smoke_Test()
        {
            var tree = new SuffixTree <char>();

            tree.Insert("bananaa".ToCharArray());
            Assert.IsTrue(tree.Count == 1);

            //IEnumerable test
            Assert.AreEqual(tree.Count, tree.Count());

            Assert.IsTrue(tree.Contains("aa".ToCharArray()));
            Assert.IsFalse(tree.Contains("ab".ToCharArray()));

            var matches = tree.StartsWith("na".ToCharArray());

            Assert.IsTrue(matches.Count == 2);

            matches = tree.StartsWith("an".ToCharArray());
            Assert.IsTrue(matches.Count == 2);

            tree.Delete("bananaa".ToCharArray());
            Assert.IsTrue(tree.Count == 0);

            //IEnumerable test
            Assert.AreEqual(tree.Count, tree.Count());
        }
예제 #2
0
        public void AddingAfterClearingSuffixTree()
        {
            var suffixTree = new SuffixTree();

            var words = new string[]
            {
                "One", "one", "oNe", "two", "hello",
                "test", "here", "there", "?!??!?!?!?",
                "VeryVeryVeryLoooooooooooooooooong",
                ".k[2c3-9024g-u,9weg,ouimwt", "3q2tgwadh",
                "`+rv`+*1v+vt23*1`vt*1v", "!@#)(*^$!%@_",
                "  bum  ", "  bam  ", "  bum  bam  ",
                "1", "12", "123", "1234", "12345", "123456"
            };


            for (int i = 0; i < words.Length; i++)
            {
                if (suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }

                suffixTree.Add(words[i]);

                if (!suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }
            }

            if (suffixTree.Count != words.Length)
            {
                Assert.Fail();
            }

            suffixTree.Clear();

            if (suffixTree.Count != 0)
            {
                Assert.Fail();
            }

            for (int i = 0; i < words.Length; i++)
            {
                if (suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }

                suffixTree.Add(words[i]);

                if (!suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }
            }

            Assert.IsTrue(suffixTree.Count == words.Length);
        }
예제 #3
0
        public void ContainsTest1()
        {
            SuffixTree tree = new SuffixTree("");

            Assert.IsTrue(tree.Contains(""));
            Assert.IsFalse(tree.Contains("1"));
            Assert.IsFalse(tree.Contains("test"));
        }
예제 #4
0
        public void AddingAndRemovingSomeWordsAndCheckingIfContained()
        {
            var suffixTree = new SuffixTree();

            var words = new string[]
            {
                "One", "one", "oNe", "two", "hello",
                "test", "here", "there", "?!??!?!?!?",
                "VeryVeryVeryLoooooooooooooooooong",
                ".k[2c3-9024g-u,9weg,ouimwt", "3q2tgwadh",
                "`+rv`+*1v+vt23*1`vt*1v", "!@#)(*^$!%@_",
                "  bum  ", "  bam  ", "  bum  bam  ",
                "1", "12", "123", "1234", "12345", "123456"
            };


            for (int i = 0; i < words.Length; i++)
            {
                if (suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }

                suffixTree.Add(words[i]);

                if (!suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }
            }

            if (suffixTree.Count != words.Length)
            {
                Assert.Fail();
            }

            int removedWords = 0;

            for (int i = 0; i < words.Length; i += 2)
            {
                if (suffixTree.Remove(words[i]))
                {
                    removedWords++;
                }
                else
                {
                    Assert.Fail();
                }

                if (suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }
            }

            Assert.IsTrue(suffixTree.Count == words.Length - removedWords);
        }
예제 #5
0
        public void query_for_existence()
        {
            var subject = new SuffixTree();

            subject.Extend(SampleText);

            Assert.That(subject.Contains("much wood"), Is.True);
            Assert.That(subject.Contains("uck ch"), Is.True);
            Assert.That(subject.Contains("k if a"), Is.True);
            Assert.That(subject.Contains("wooden"), Is.False);
            Assert.That(subject.Contains("wwood"), Is.False);
        }
예제 #6
0
        public void GetWordsBySuffixAndCheckIfSorted()
        {
            var suffixTree = new SuffixTree();

            var words = new string[]
            {
                "afa suffix", "abaa suffix", "asd suffix",
                "ase suffix", "rfda suffix", "rtfs suffix",
                "efad suffix", "Abaa suffix", "fasrg suffix",
                "test suffix", "t3st suffix", "tEst suffix",
                "TEST suffix", "Test suffix", "T3st suffix",
                "Test123 suffix", "aheyj suffix", "gwecgs suffix",
                ".,gml;k suffix", "rbkp;r suffix", "wopger'lb suffix",
                "  zzz suffix", "^&*(& suffix", "кирилица suffix",
                "suffix not presented"
            };

            for (int i = 0; i < words.Length; i++)
            {
                if (suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }

                suffixTree.Add(words[i]);

                if (!suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }
            }

            var previousWord = string.Empty;
            int suffixWords  = 0;

            foreach (var word in suffixTree.GetWordsBySuffix("suffix"))
            {
                if (string.CompareOrdinal(previousWord, word) > 0)
                {
                    Assert.Fail();
                }

                System.Diagnostics.Trace.WriteLine(word);

                previousWord = word;
                suffixWords++;
            }

            Assert.IsTrue(suffixTree.Count == words.Length &&
                          suffixWords < words.Length);
        }
예제 #7
0
        public void CheckIfSuffixIsContained()
        {
            var suffixTree = new SuffixTree();

            var words = new string[]
            {
                "One", "one", "oNe", "two", "hello",
                "test", "here", "there", "?!??!?!?!?",
                "VeryVeryVeryLoooooooooooooooooong",
                ".k[2c3-9024g-u,9weg,ouimwt", "3q2tgwadh",
                "`+rv`+*1v+vt23*1`vt*1v", "!@#)(*^$!%@_",
                "  bum  ", "  bam  ", "  bum  bam  ",
                "1", "12", "123", "1234", "12345", "123456"
            };


            for (int i = 0; i < words.Length; i++)
            {
                suffixTree.Add(words[i]);

                for (int j = 0; j < words[i].Length; j++)
                {
                    if (!suffixTree.ContainsSuffix(words[i].Substring(j, words[i].Length - j)))
                    {
                        Assert.Fail();
                    }
                }
                if (!suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }
            }

            Assert.IsTrue(suffixTree.Count == words.Length);
        }
예제 #8
0
        public void CheckIfSortedAfterAdding()
        {
            var suffixTree = new SuffixTree();

            var words = new string[]
            {
                "One", "one", "oNe", "two", "hello",
                "test", "here", "there", "?!??!?!?!?",
                "VeryVeryVeryLoooooooooooooooooong",
                ".k[2c3-9024g-u,9weg,ouimwt", "3q2tgwadh",
                "`+rv`+*1v+vt23*1`vt*1v", "!@#)(*^$!%@_",
                "  bum  ", "  bam  ", "  bum  bam  ",
                "1", "12", "123", "1234", "12345", "123456"
            };


            for (int i = 0; i < words.Length; i++)
            {
                if (suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }

                suffixTree.Add(words[i]);

                if (!suffixTree.Contains(words[i]))
                {
                    Assert.Fail();
                }
            }

            var previousWord = string.Empty;

            foreach (var word in suffixTree)
            {
                if (string.CompareOrdinal(previousWord, word) > 0)
                {
                    Assert.Fail();
                }

                //System.Diagnostics.Trace.WriteLine(word);

                previousWord = word;
            }

            Assert.IsTrue(suffixTree.Count == words.Length);
        }
예제 #9
0
        public void ContainsTest3()
        {
            SuffixTree tree = new SuffixTree("SUF FIX");

            Assert.IsTrue(tree.Contains("F "));
            Assert.IsTrue(tree.Contains(" "));
            Assert.IsTrue(tree.Contains("SUF FIX"));
            Assert.IsTrue(tree.Contains("X"));

            Assert.IsFalse(tree.Contains("Y"));
            Assert.IsFalse(tree.Contains("IXX"));
            Assert.IsFalse(tree.Contains("  "));
            Assert.IsFalse(tree.Contains("T"));
        }
예제 #10
0
        static void Main(string[] args)
        {
            var s = "bananasbanananananananananassssss";
            var t = "ananasbanana";

            var tree = new SuffixTree();

            tree.AddString(s);

            Debug.WriteLine("");
            Debug.WriteLine(tree.Contains(t));
            Debug.WriteLine("");
            Debug.WriteLine(tree);
        }
예제 #11
0
        public void ContainsTest2()
        {
            SuffixTree tree = new SuffixTree("BANANA");

            Assert.IsTrue(tree.Contains(""));
            Assert.IsTrue(tree.Contains("A"));
            Assert.IsTrue(tree.Contains("NA"));
            Assert.IsTrue(tree.Contains("ANA"));
            Assert.IsTrue(tree.Contains("NANA"));
            Assert.IsTrue(tree.Contains("ANANA"));
            Assert.IsTrue(tree.Contains("BANANA"));
            Assert.IsTrue(tree.Contains("BAN"));
            Assert.IsTrue(tree.Contains("BANAN"));

            Assert.IsFalse(tree.Contains("BANANA1"));
            Assert.IsFalse(tree.Contains("NAB"));
            Assert.IsFalse(tree.Contains("x"));
            Assert.IsFalse(tree.Contains("Na"));
            Assert.IsFalse(tree.Contains("Tt"));
            Assert.IsFalse(tree.Contains("ANAu"));
        }