示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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());
        }
示例#4
0
 private void KmpMatcher(string text, string pattern)
 => KmpStringMatcher.GetMatchIndices(text, pattern).ToArray();
示例#5
0
文件: NHAY.cs 项目: Dariasz/SPOJ
 public static IEnumerable <int> Solve(string text, string pattern)
 => KmpStringMatcher.GetMatchIndices(text, pattern);
示例#6
0
 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());