Ejemplo n.º 1
0
        private static void TestSearchMatches(ISearchAlgorithm<int[]> searcher, char[] s, char[] key, int expectedCount)
        {
            if (s.Length < 1)
            {
                throw new ArgumentException("s.Length < 1");
            }
            if (key.Length < 1)
            {
                throw new ArgumentException("key.Length < 1");
            }
            var keyLen = key.Length;
            var matchIndices = searcher.SearchAll(s, key);

            // Try to catch invalid indices early by
            // comparing result length with expected count
            Assert.AreEqual(expectedCount, matchIndices.Length);

            // For each match, compare every character to key
            foreach (var start in matchIndices)
            {
                var match = s.Skip(start).Take(keyLen).ToArray();

                // Try to catch invalid match without evaluating chars
                // by comparing match length against search key length
                Assert.AreEqual(keyLen, match.Length);
                for (int ci = 0; ci < keyLen; ci++)
                {
                    Assert.AreEqual(key[ci], match[ci]);
                }
            }
        }