public void PatchApplyTest() { diff_match_patchTest dmp = new diff_match_patchTest(); dmp.Match_Distance = 1000; dmp.Match_Threshold = 0.5f; dmp.Patch_DeleteThreshold = 0.5f; List<Patch> patches; patches = dmp.PatchMake("", ""); Object[] results = dmp.PatchApply(patches, "Hello world."); bool[] boolArray = (bool[])results[1]; string resultStr = results[0] + "\t" + boolArray.Length; Assert.AreEqual("Hello world.\t0", resultStr, "PatchApply: Null case."); patches = dmp.PatchMake("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog."); results = dmp.PatchApply(patches, "The quick brown fox jumps over the lazy dog."); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; Assert.AreEqual("That quick brown fox jumped over a lazy dog.\tTrue\tTrue", resultStr, "PatchApply: Exact match."); results = dmp.PatchApply(patches, "The quick red rabbit jumps over the tired tiger."); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; Assert.AreEqual("That quick red rabbit jumped over a tired tiger.\tTrue\tTrue", resultStr, "PatchApply: Partial match."); results = dmp.PatchApply(patches, "I am the very model of a modern major general."); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; Assert.AreEqual("I am the very model of a modern major general.\tFalse\tFalse", resultStr, "PatchApply: Failed match."); patches = dmp.PatchMake("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy"); results = dmp.PatchApply(patches, "x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y"); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; Assert.AreEqual("xabcy\tTrue\tTrue", resultStr, "PatchApply: Big delete, small change."); patches = dmp.PatchMake("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy"); results = dmp.PatchApply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y"); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; Assert.AreEqual("xabc12345678901234567890---------------++++++++++---------------12345678901234567890y\tFalse\tTrue", resultStr, "PatchApply: Big delete, big change 1."); dmp.Patch_DeleteThreshold = 0.6f; patches = dmp.PatchMake("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy"); results = dmp.PatchApply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y"); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; Assert.AreEqual("xabcy\tTrue\tTrue", resultStr, "PatchApply: Big delete, big change 2."); dmp.Patch_DeleteThreshold = 0.5f; dmp.Match_Threshold = 0.0f; dmp.Match_Distance = 0; patches = dmp.PatchMake("abcdefghijklmnopqrstuvwxyz--------------------1234567890", "abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890"); results = dmp.PatchApply(patches, "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890"); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1]; Assert.AreEqual("ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890\tFalse\tTrue", resultStr, "PatchApply: Compensate for failed patch."); dmp.Match_Threshold = 0.5f; dmp.Match_Distance = 1000; patches = dmp.PatchMake("", "test"); string patchStr = dmp.PatchToText(patches); dmp.PatchApply(patches, ""); Assert.AreEqual(patchStr, dmp.PatchToText(patches), "PatchApply: No side effects."); patches = dmp.PatchMake("The quick brown fox jumps over the lazy dog.", "Woof"); patchStr = dmp.PatchToText(patches); dmp.PatchApply(patches, "The quick brown fox jumps over the lazy dog."); Assert.AreEqual(patchStr, dmp.PatchToText(patches), "PatchApply: No side effects with major delete."); patches = dmp.PatchMake("", "test"); results = dmp.PatchApply(patches, ""); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0]; Assert.AreEqual("test\tTrue", resultStr, "PatchApply: Edge exact match."); patches = dmp.PatchMake("XY", "XtestY"); results = dmp.PatchApply(patches, "XY"); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0]; Assert.AreEqual("XtestY\tTrue", resultStr, "PatchApply: Near edge exact match."); patches = dmp.PatchMake("y", "y123"); results = dmp.PatchApply(patches, "x"); boolArray = (bool[])results[1]; resultStr = results[0] + "\t" + boolArray[0]; Assert.AreEqual("x123\tTrue", resultStr, "PatchApply: Edge partial match."); }