public void FindAll_ReturnsExpected(string text, string pattern, int startIndex, IEnumerable <int> expected) { var kmp = new KmpStringMatcher(); var actual = kmp.FindAll(text, pattern, startIndex).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void FindFirst_ReturnsExpected(string text, string pattern, int startIndex, int expected) { var kmp = new KmpStringMatcher(); int actual = kmp.FindFirst(text, pattern, startIndex); Assert.AreEqual(expected, actual); }
public void StringMatchers_ForLargeStrings_AgreeWithEachOther() { string text = InputGenerator.GenerateRandomString(1000); string pattern = InputGenerator.GenerateRandomString(3); CollectionAssert.AreEqual( NaiveStringMatcher.GetMatchIndices(text, pattern).ToArray(), KmpStringMatcher.GetMatchIndices(text, pattern).ToArray()); text = InputGenerator.GenerateRandomString(1000, 'a', 'b'); pattern = InputGenerator.GenerateRandomString(3, 'a', 'b'); CollectionAssert.AreEqual( NaiveStringMatcher.GetMatchIndices(text, pattern).ToArray(), KmpStringMatcher.GetMatchIndices(text, pattern).ToArray()); }
private void KmpMatcher(string text, string pattern) => KmpStringMatcher.GetMatchIndices(text, pattern).ToArray();
public static IEnumerable <int> Solve(string text, string pattern) => KmpStringMatcher.GetMatchIndices(text, pattern);
public void ComputePrefixesLengthOfLongestProperSuffixThatIsItselfAPrefix() // This verifies the example shown in CLRS on page 1005. => CollectionAssert.AreEqual( new[] { 0, 0, 0, 1, 2, 3, 0, 1 }, KmpStringMatcher.ComputePrefixesLengthOfLongestProperSuffixThatIsItselfAPrefix("ababaca").ToArray());