Example #1
0
        public void TestLarger2()
        {
            var text = "xxxvaceorsuvaceo";
            var e    = new RationalNumber(3, 2);
            var sb   = new StringBuilder();

            sb.Append(text.Substring(0, 9));

            var catcher = new Catcher(sb, 5, 6, e, false, 200);

            catcher.WarmUp(8, 9);
            var repetitions = new List <Repetition>();

            for (var i = 9; i < text.Length; ++i)
            {
                sb.Append(text[i]);
                Repetition rep;
                if (catcher.TryCatch(out rep))
                {
                    repetitions.Add(rep);
                }
            }
            Assert.That(repetitions, Is.EquivalentTo(new[]
            {
                new Repetition(2, 8)
            }));
        }
Example #2
0
        public void TestEqualWithBackTrack()
        {
            var text = "xxxxaceorsuvaceo";
            var e    = new RationalNumber(3, 2);
            var sb   = new StringBuilder();

            sb.Append(text.Substring(0, 9));

            var catcher = new Catcher(sb, 5, 6, e, true, 200);

            catcher.WarmUp(8, 9);
            Repetition rep;

            for (var i = 9; i < text.Length; ++i)
            {
                sb.Append(text[i]);
                catcher.TryCatch(out rep);
            }
            catcher.Backtrack();
            sb.Remove(sb.Length - 1, 1);
            sb.Append('c');
            Assert.That(catcher.TryCatch(out rep), Is.False);
            sb.Remove(sb.Length - 1, 1);
            sb.Append('o');
            catcher.Backtrack();
            Assert.That(catcher.TryCatch(out rep), Is.True);
            Assert.That(rep, Is.EqualTo(new Repetition(3, 8)));
        }
        private void CreateCatcher(CatcherInterval interval)
        {
            if (interval.L < -1)
            {
                return;
            }
            var     n = interval.L + 1 + S * interval.Length;
            Catcher catcher;
            var     i = interval.R;
            var     j = Math.Max(i, n - 1 - (new RationalNumber(S) / E * interval.Length).Ceil());

            if (!catchers.TryGetValue(interval, out catcher))
            {
                catcher = new Catcher(Text, i, j, E, DetectEqual, interval.Length);
                catcher.WarmUp(j + 2, Text.Length);
                catchers[interval] = catcher;
            }
            catcher.RemoveTime = -1;
        }