コード例 #1
0
        public void MatchBitapTest()
        {
            diff_match_patchTest dmp = new diff_match_patchTest();

              // Bitap algorithm.
              dmp.Match_Distance = 100;
              dmp.Match_Threshold = 0.5f;
              Assert.AreEqual(5, dmp.MatchBitap("abcdefghijk", "fgh", 5), "MatchBitap: Exact match #1.");

              Assert.AreEqual(5, dmp.MatchBitap("abcdefghijk", "fgh", 0), "MatchBitap: Exact match #2.");

              Assert.AreEqual(4, dmp.MatchBitap("abcdefghijk", "efxhi", 0), "MatchBitap: Fuzzy match #1.");

              Assert.AreEqual(2, dmp.MatchBitap("abcdefghijk", "cdefxyhijk", 5), "MatchBitap: Fuzzy match #2.");

              Assert.AreEqual(-1, dmp.MatchBitap("abcdefghijk", "bxy", 1), "MatchBitap: Fuzzy match #3.");

              Assert.AreEqual(2, dmp.MatchBitap("123456789xx0", "3456789x0", 2), "MatchBitap: Overflow.");

              Assert.AreEqual(0, dmp.MatchBitap("abcdef", "xxabc", 4), "MatchBitap: Before start match.");

              Assert.AreEqual(3, dmp.MatchBitap("abcdef", "defyy", 4), "MatchBitap: Beyond end match.");

              Assert.AreEqual(0, dmp.MatchBitap("abcdef", "xabcdefy", 0), "MatchBitap: Oversized pattern.");

              dmp.Match_Threshold = 0.4f;
              Assert.AreEqual(4, dmp.MatchBitap("abcdefghijk", "efxyhi", 1), "MatchBitap: Threshold #1.");

              dmp.Match_Threshold = 0.3f;
              Assert.AreEqual(-1, dmp.MatchBitap("abcdefghijk", "efxyhi", 1), "MatchBitap: Threshold #2.");

              dmp.Match_Threshold = 0.0f;
              Assert.AreEqual(1, dmp.MatchBitap("abcdefghijk", "bcdef", 1), "MatchBitap: Threshold #3.");

              dmp.Match_Threshold = 0.5f;
              Assert.AreEqual(0, dmp.MatchBitap("abcdexyzabcde", "abccde", 3), "MatchBitap: Multiple select #1.");

              Assert.AreEqual(8, dmp.MatchBitap("abcdexyzabcde", "abccde", 5), "MatchBitap: Multiple select #2.");

              dmp.Match_Distance = 10;  // Strict location.
              Assert.AreEqual(-1, dmp.MatchBitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24), "MatchBitap: Distance test #1.");

              Assert.AreEqual(0, dmp.MatchBitap("abcdefghijklmnopqrstuvwxyz", "abcdxxefg", 1), "MatchBitap: Distance test #2.");

              dmp.Match_Distance = 1000;  // Loose location.
              Assert.AreEqual(0, dmp.MatchBitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24), "MatchBitap: Distance test #3.");
        }