public void ProcessInputDataBuAdditionTestLength7Number3Pattern4Step987()
        {
            // arrange
            int step          = 9879;
            int bufferSize    = 1000;
            int patternLength = 7;
            int textLength    = 14;

            char[] alphabet = new char[] { 'a', 'c', 'g', 't' };
            StringCompareAccumulator statisticAccumulator = new StringCompareAccumulator(new StringCompareSaver(), BoyerMooreComparer.AlgorythmName,
                                                                                         patternLength, textLength, bufferSize, alphabet.Length);

            statisticAccumulator.Delete();
            int  size             = patternLength + textLength;
            long max              = 1L << (2 * size);
            long sequenceAsNumber = 0;

            int[]  sequence     = new int[size];
            char[] charSequence = new char[size];
            long[] masks        = new long[size];

            long mask = 3;

            for (int i = 0; i < size; i++)
            {
                masks[i] = mask;
                mask   <<= 2;
            }
            // act
            while (sequenceAsNumber < max)
            {
                int shift = 0;
                for (int i = 0; i < size; i++)
                {
                    sequence[i] = (int)((sequenceAsNumber & masks[i]) >> shift);
                    shift      += 2;
                }
                sequenceAsNumber += step;
                charSequence      = sequence.Select(j => alphabet[j]).ToArray();
                string             pattern           = new string(charSequence.Take(patternLength).ToArray());
                string             text              = new string(charSequence.Skip(patternLength).Take(textLength).ToArray());
                BoyerMooreComparer boyerMooreCompare = new BoyerMooreComparer()
                {
                    StatisticAccumulator = statisticAccumulator
                };
                // act
                boyerMooreCompare.FindSubstring(text, pattern, false);
            }
            statisticAccumulator.SaveRemain();

            // assert
        }
        public void SimpletStringCompareByPreprocessingCase3Text()
        {
            // arrange
            char[]             alphabet          = new char[] { 'a', 'c' };
            string             pattern           = "aacccc";
            string             text              = "aaaaaccccaaacacc";
            BoyerMooreComparer boyerMooreCompare = new BoyerMooreComparer()
            {
                StatisticAccumulator = new FakeStringCompareAccumulator()
            };

            // act
            boyerMooreCompare.FindSubstringGoodSuffix(text, pattern);
            // assert
            string expected = "3";

            Assert.AreEqual(boyerMooreCompare.OutputPresentation, expected, $"Wrong result:{boyerMooreCompare.OutputPresentation}, expected:{expected}");
        }
        //--------------------------------------------------------------------------------------
        protected override bool MakeAction()
        {
            if (_fCurrentPosition == _fSize - 1 && --_stepCounter == 0)
            {
                var                currentSequence   = _fCurrentSet.Select(i => _charSet[i]).ToList();
                string             pattern           = new string(currentSequence.Take(_patternLength).ToArray());
                string             text              = new string(currentSequence.Skip(_patternLength).Take(_textLength).ToArray());
                BoyerMooreComparer boyerMooreCompare = new BoyerMooreComparer()
                {
                    StatisticAccumulator = _statisticAccumulator
                };                    // act
                boyerMooreCompare.FindSubstring(text, pattern);
                // assert

                _stepCounter = _step;
            }

            return(false);
        }
Пример #4
0
 //--------------------------------------------------------------------------------------
 public EnumerateCharSetForBoyerMooreBadSymbolAdvCompare(
     char[] pCharSet,
     int pPatternLength,
     int pTextLength,
     int pStep      = 1,
     int bufferSize = 1000)
     : base(pCharSet, pTextLength + pPatternLength, 0)
 {
     _patternLength        = pPatternLength;
     _textLength           = pTextLength;
     _step                 = pStep;
     _stepCounter          = 1;
     _statisticAccumulator = new StringCompareAccumulator(new StringCompareSaver(), BoyerMooreComparer.AlgorythmNameBadSymbolAdv,
                                                          _patternLength, _textLength, bufferSize, pCharSet.Length);
     _statisticAccumulator.Delete();
     boyerMooreCompare = new BoyerMooreComparer()
     {
         StatisticAccumulator = _statisticAccumulator
     };
 }
Пример #5
0
        public void SimpletStringCompareByPreprocessingCaseWorstBestText()
        {
            // arrange
            char[]   alphabet      = new char[] { 'a', 'c' };
            string[] worstPatterns = { "aaaaac",
                                       "aaaaac",
                                       "aaaaac",
                                       "aaacac",
                                       "aaaaac",
                                       "aaacac",
                                       "aaacaa",
                                       "aaacac",
                                       "aaacac",
                                       "aaacaa" };

            string[] bestPatterns = { "aaaaaa",
                                      "aaaaaa",
                                      "aaaaaa",
                                      "aaaaaa",
                                      "aaaaaa",
                                      "aaaaaa",
                                      "aaaaaa",
                                      "aaaaaa",
                                      "aaaaaa",
                                      "aaaaaa" };

            string[] worstTexts = { "acacaaaaaccacacc", "acacaaaaaccaccca",

                                    "accccaaaacacacaa",
                                    "aaccacacaacaacac",
                                    "accccaaaacccacac",
                                    "aaccacacaacaacca",
                                    "cacccaacaaacacca",
                                    "aaccacacaacacaac",
                                    "aaccacacaacacaaa",
                                    "cacccaacaaacaccc" };

            string[] bestTexts = { "aaaacccacacaacca",
                                   "acaacacaacccacac",
                                   "acaaacccccaacaca",
                                   "acaacccccaaacaca",
                                   "acacacaaacaaccca",
                                   "acacaccacaaacccc",
                                   "acccaaaaccacccca",
                                   "aaaaccccacaaccca",
                                   "aaaccacaacaaacca",
                                   "aacacaacacaacaca" };

            List <BadSymbolStatistics> badSymbolStatistics = new List <BadSymbolStatistics>(50);
            BoyerMooreComparer         boyerMooreCompare   = new BoyerMooreComparer()
            {
                StatisticAccumulator = new FakeStringCompareAccumulator()
            };

            // act
            for (int i = 0; i < 10; i++)
            {
                boyerMooreCompare = new BoyerMooreComparer()
                {
                    StatisticAccumulator = new FakeStringCompareAccumulator()
                };
                boyerMooreCompare.FindSubstringBadSymbolAdv(worstTexts[i], worstPatterns[i]);
                badSymbolStatistics.Add(new BadSymbolStatistics()
                {
                    Pattern              = worstPatterns[i],
                    Text                 = worstTexts[i],
                    OutputPresentation   = boyerMooreCompare.OutputPresentation,
                    ElapsedTicks         = boyerMooreCompare.ElapsedTicks,
                    DurationMilliSeconds = boyerMooreCompare.DurationMilliSeconds,
#if (DEBUG)
                    ElapsedTicksList  = boyerMooreCompare.ElapsedTicksList.ToList(),
                    CoreProcess       = boyerMooreCompare.CoreProcess,
                    DictionaryProcess = boyerMooreCompare.DictionaryProcess,
                    OuterLoop         = boyerMooreCompare.OuterLoop
#endif
                });
                boyerMooreCompare = new BoyerMooreComparer()
                {
                    StatisticAccumulator = new FakeStringCompareAccumulator()
                };
                boyerMooreCompare.FindSubstringBadSymbolAdv(bestTexts[i], bestPatterns[i]);
                badSymbolStatistics.Add(new BadSymbolStatistics()
                {
                    Pattern              = worstPatterns[i],
                    Text                 = worstTexts[i],
                    OutputPresentation   = boyerMooreCompare.OutputPresentation,
                    ElapsedTicks         = boyerMooreCompare.ElapsedTicks,
                    DurationMilliSeconds = boyerMooreCompare.DurationMilliSeconds,
#if (DEBUG)
                    ElapsedTicksList  = boyerMooreCompare.ElapsedTicksList.ToList(),
                    CoreProcess       = boyerMooreCompare.CoreProcess,
                    DictionaryProcess = boyerMooreCompare.DictionaryProcess,
                    OuterLoop         = boyerMooreCompare.OuterLoop
#endif
                });
            }
            // assert
            //string expected = "8,9,10";
            //Assert.AreEqual(boyerMooreCompare.OutputPresentation, expected, $"Wrong result:{boyerMooreCompare.OutputPresentation}, expected:{expected}");
        }