Example #1
0
        public void TestFind()
        {
            BoyerMoore finder = new BoyerMoore("bad");
            string     text   = "It’s too bad she won’t live. But then again, who does?";

            Assert.AreEqual(9, finder.Find(text));
        }
Example #2
0
        public void Find_DifferentCases_EmptyListReturned()
        {
            string text    = "abd Hello world adt";
            string pattern = "hello world";

            var expected = new List <int>();
            var actual   = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
Example #3
0
        public void Find_SearchNonexistentSubstring_EmptyListReturned()
        {
            string text    = "abcde";
            string pattern = "ghf";

            var expected = new List <int>();
            var actual   = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
Example #4
0
        public void Find_OrdinaryPatternAndText_1PositionsReturned()
        {
            string text    = "GCATCGCAGAGAGTATACAGTACG";
            string pattern = "GCAGAGAG";

            var expected = new List <int>()
            {
                5
            };
            var actual = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
Example #5
0
        public void Find_PatternWithWhiteSpaces_1PositionsReturned()
        {
            string text    = "sd bd de hello world 53 5 sdf";
            string pattern = "hello world";

            var expected = new List <int>()
            {
                9
            };
            var actual = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
Example #6
0
        public void Find_OnlyIdenticalCharactersInText_4PositionsReturned()
        {
            string text    = "aaaa";
            string pattern = "a";

            var expected = new List <int>()
            {
                0, 1, 2, 3
            };
            var actual = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
Example #7
0
        public void Find_MultiplePatternOccurrences_3PositionsReturned()
        {
            string text    = "hi adb hi 48 hiabc";
            string pattern = "hi";

            var expected = new List <int>()
            {
                0, 7, 13
            };
            var actual = BoyerMoore.Find(text, pattern);

            CollectionAssert.AreEqual(actual, expected);
        }
        private void FindSubstringsAndShow(bool ignoreCase = false)
        {
            SetDefaultBackgroundTextColor();

            string text    = TextFromRichTextBox();
            string pattern = PatternFromTextBox();

            if (text != "" && pattern != "")
            {
                var shifts = BoyerMoore.Find(text, pattern, ignoreCase);
                coincidenceLabel.Text = $"Совпадений: {shifts.Count}";
                ShowFound(pattern, shifts);
            }
            else
            {
                coincidenceLabel.Text = $"Совпадений: {0}";
            }
        }