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.AlgorythmNameBadSymbol, 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.FindSubstringBadSymbol(text, pattern, false); } statisticAccumulator.SaveRemain(); // assert }
public void SimpletStringCompareByPreprocessingCase2Text() { // arrange char[] alphabet = new char[] { 'a', 'c' }; string pattern = "accccc"; string text = "aaaaaaaaaaaccccc"; BoyerMooreComparer boyerMooreCompare = new BoyerMooreComparer() { StatisticAccumulator = new FakeStringCompareAccumulator() }; // act boyerMooreCompare.FindSubstringBadSymbol(text, pattern); // assert string expected = "10"; 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 text = new string(currentSequence.Take(_textLength).ToArray()); string pattern = new string(currentSequence.Skip(_textLength).Take(_patternLength).ToArray()); BoyerMooreComparer boyerMooreCompare = new BoyerMooreComparer() { StatisticAccumulator = _statisticAccumulator }; // act boyerMooreCompare.FindSubstringBadSymbol(text, pattern); // assert _stepCounter = _step; } return(false); }