コード例 #1
0
ファイル: SuffixTreeMapTests.cs プロジェクト: zack7891/DSA
        public void AddingAndRemovingSomeWordsAndCheckingIfContained()
        {
            var suffixTree = new SuffixTreeMap <string>();

            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.ContainsWord(words[i]))
                {
                    Assert.Fail();
                }

                suffixTree.Add(words[i], words[i]);

                if (!suffixTree.ContainsWord(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.ContainsWord(words[i]))
                {
                    Assert.Fail();
                }
            }

            Assert.IsTrue(suffixTree.Count == words.Length - removedWords);
        }
コード例 #2
0
ファイル: SuffixTreeMapTests.cs プロジェクト: zack7891/DSA
        public void CheckIfSortedAfterAddingAndRemovingSomeWords()
        {
            var suffixTree = new SuffixTreeMap <string>();

            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.ContainsWord(words[i]))
                {
                    Assert.Fail();
                }

                suffixTree.Add(words[i], words[i]);

                if (!suffixTree.ContainsWord(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.ContainsWord(words[i]))
                {
                    Assert.Fail();
                }
            }

            var previousWord = string.Empty;

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

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

                previousWord = word.Key;
            }

            Assert.IsTrue(suffixTree.Count == words.Length - removedWords);
        }