Пример #1
0
        public void PolyHashTest()
        {
            long result1 = HashingWithChain.PolyHash("world", 5);
            long result2 = HashingWithChain.PolyHash("HellO", 5);
            long result3 = HashingWithChain.PolyHash("GooD", 5);

            Assert.AreEqual(4, result1);
            Assert.AreEqual(4, result2);
            Assert.AreEqual(2, result3);
        }
Пример #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);

            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]);
            }
        }
Пример #4
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);
        }
Пример #5
0
        public void HashingWithChainTest()
        {
            HashingWithChain p = new HashingWithChain("TD2");

            TestTools.RunLocalTest("A10", p.Process, p.TestDataName);
        }