Exemplo n.º 1
0
        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(), KnuthCompare.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());
                KnuthCompare knuthCompare = new KnuthCompare()
                {
                    StatisticAccumulator = statisticAccumulator
                };
                // act
                knuthCompare.FindSubstring(text, pattern, false);
            }
            statisticAccumulator.SaveRemain();

            // assert
        }
Exemplo n.º 2
0
        public void KnuthCompareCase4Text()
        {
            // arrange
            char[]       alphabet     = new char[] { 'a', 'c' };
            string       pattern      = "aacaac";
            string       text         = "aaaaacaaacaacaac";
            KnuthCompare knuthCompare = new KnuthCompare()
            {
                StatisticAccumulator = new FakeStringCompareAccumulator()
            };

            // act
            knuthCompare.FindSubstring(text, pattern);
            // assert
            string expected = "7,10";

            Assert.AreEqual(knuthCompare.OutputPresentation, expected, $"Wrong result:{knuthCompare.OutputPresentation}, expected:{expected}");
        }
Exemplo n.º 3
0
            //--------------------------------------------------------------------------------------
            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());
                    KnuthCompare knuthCompare    = new KnuthCompare()
                    {
                        StatisticAccumulator = _statisticAccumulator
                    };                    // act
                    knuthCompare.FindSubstring(text, pattern);
                    // assert

                    _stepCounter = _step;
                }

                return(false);
            }