public void TestFindOccurences(string text, string pattern, int[] expectedOccurences) { var criticalPosition = pattern.GetFactorizations().PatternCriticalPosition; var period = PeriodCalculator.GetPeriod(pattern, pattern.Length); var sb = new StringBuilder(); var algorithm = new SuffixStringMatchingAlgorithm(sb, pattern, 0, pattern.Length, criticalPosition, period); var occurences = new List <int>(); for (var i = 0; i < text.Length; ++i) { sb.Append(text[i]); if (algorithm.CheckMatch(sb.Length)) { occurences.Add(i); } } Assert.That(occurences, Is.EquivalentTo(expectedOccurences)); }
public StringMatchingAlgorithm([NotNull] StringBuilder text, [NotNull] string pattern, int startPosition) { var factorizations = pattern.GetFactorizations(); if (factorizations.PatternFactorizationIsGood()) { shift = 0; incompleteAlgorithm = null; completeAlgorithm = new GoodFactorizationStringMatchingAlgorithm(text, startPosition, pattern, pattern.Length, factorizations.PatternCriticalPosition, PeriodCalculator.GetPeriod(pattern, pattern.Length)); } else { shift = pattern.Length - factorizations.PrefixLength; incompleteAlgorithm = new SuffixStringMatchingAlgorithm(text, pattern, startPosition, pattern.Length, factorizations.PatternCriticalPosition, PeriodCalculator.GetPeriod(pattern, pattern.Length)); completeAlgorithm = new GoodFactorizationStringMatchingAlgorithm(text, startPosition, pattern, factorizations.PrefixLength, factorizations.PrefixCriticalPosition, PeriodCalculator.GetPeriod(pattern, factorizations.PrefixLength)); } }
public void TestPatternPeriod(string template, int expectedPeriod) { Assert.That(PeriodCalculator.GetPeriod(template, template.Length), Is.EqualTo(expectedPeriod)); }