Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 4
0
 private void KmpMatcher(string text, string pattern)
 => KmpStringMatcher.GetMatchIndices(text, pattern).ToArray();
Ejemplo n.º 5
0
Archivo: NHAY.cs Proyecto: Dariasz/SPOJ
 public static IEnumerable <int> Solve(string text, string pattern)
 => KmpStringMatcher.GetMatchIndices(text, pattern);
Ejemplo n.º 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());