예제 #1
0
        public void PreComputeHashesTest()
        {
            string testStr    = "aaaa";
            int    patternLen = 2;

            long[] H = RabinKarp.PreComputeHashes(
                testStr, patternLen, 101, 3);

            for (int i = 0; i < testStr.Length - patternLen + 1; i++)
            {
                long expectedHash = RabinKarp.PolyHash(testStr, i, patternLen, 101, 3);
                Assert.AreEqual(expectedHash, H[i]);
            }
        }
예제 #2
0
        public void PreComputeHashesTest()
        {
            string testStr    = "nbvgcfdretfyghjugfdrtyghjuiytrdsfxcvbjhytrdfgcvbnhjkuiytgfhbvnm";
            int    patternLen = 4;

            long[] H = RabinKarp.PreComputeHashes(
                testStr, patternLen, 101, 3);

            for (int i = 0; i < testStr.Length - patternLen + 1; i++)
            {
                long expectedHash =
                    HashingWithChain.PolyHash(testStr, i, patternLen, 101, 101, 3);
                Assert.AreEqual(expectedHash, H[i]);
            }
        }
예제 #3
0
        public void PreComputeHashesTest()
        {
            string testStr    = "aaaa";
            int    patternLen = 2;

            long[] H = RabinKarp.PreComputeHashes(
                testStr, patternLen, 101, 3);

            long[] expectedHash = new long[testStr.Length - patternLen + 1];

            for (int i = testStr.Length - patternLen; i >= 0; i--)
            {
                expectedHash[i] =
                    HashingWithChain.PolyHash(testStr, i, patternLen, p: 101, x: 3);
            }


            CollectionAssert.AreEqual(expectedHash, H);
        }