本文整理汇总了C#中nicTest.diff_match_patchTest.patch_apply方法的典型用法代码示例。如果您正苦于以下问题:C# diff_match_patchTest.patch_apply方法的具体用法?C# diff_match_patchTest.patch_apply怎么用?C# diff_match_patchTest.patch_apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nicTest.diff_match_patchTest
的用法示例。
在下文中一共展示了diff_match_patchTest.patch_apply方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: patch_applyTest
public void patch_applyTest()
{
var dmp = new diff_match_patchTest{Match_Distance = 1000, Match_Threshold = 0.5f, Patch_DeleteThreshold = 0.5f};
List<Patch> patches = dmp.patch_make("", "");
Object[] results = dmp.patch_apply(patches, "Hello world.");
var boolArray = (bool[])results[1];
string resultStr = results[0] + "\t" + boolArray.Length;
Assert.AreEqual("Hello world.\t0", resultStr, "patch_apply: Null case.");
patches = dmp.patch_make("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.");
results = dmp.patch_apply(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, "patch_apply: Exact match.");
results = dmp.patch_apply(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, "patch_apply: Partial match.");
results = dmp.patch_apply(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, "patch_apply: Failed match.");
patches = dmp.patch_make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
results = dmp.patch_apply(patches, "x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("xabcy\tTrue\tTrue", resultStr, "patch_apply: Big delete, small change.");
patches = dmp.patch_make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
results = dmp.patch_apply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("xabc12345678901234567890---------------++++++++++---------------12345678901234567890y\tFalse\tTrue", resultStr, "patch_apply: Big delete, big change 1.");
dmp.Patch_DeleteThreshold = 0.6f;
patches = dmp.patch_make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
results = dmp.patch_apply(patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("xabcy\tTrue\tTrue", resultStr, "patch_apply: Big delete, big change 2.");
dmp.Patch_DeleteThreshold = 0.5f;
dmp.Match_Threshold = 0.0f;
dmp.Match_Distance = 0;
patches = dmp.patch_make("abcdefghijklmnopqrstuvwxyz--------------------1234567890", "abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890");
results = dmp.patch_apply(patches, "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0] + "\t" + boolArray[1];
Assert.AreEqual("ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890\tFalse\tTrue", resultStr, "patch_apply: Compensate for failed patch.");
dmp.Match_Threshold = 0.5f;
dmp.Match_Distance = 1000;
patches = dmp.patch_make("", "test");
string patchStr = dmp.patch_toText(patches);
dmp.patch_apply(patches, "");
Assert.AreEqual(patchStr, dmp.patch_toText(patches), "patch_apply: No side effects.");
patches = dmp.patch_make("The quick brown fox jumps over the lazy dog.", "Woof");
patchStr = dmp.patch_toText(patches);
dmp.patch_apply(patches, "The quick brown fox jumps over the lazy dog.");
Assert.AreEqual(patchStr, dmp.patch_toText(patches), "patch_apply: No side effects with major delete.");
patches = dmp.patch_make("", "test");
results = dmp.patch_apply(patches, "");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0];
Assert.AreEqual("test\tTrue", resultStr, "patch_apply: Edge exact match.");
patches = dmp.patch_make("XY", "XtestY");
results = dmp.patch_apply(patches, "XY");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0];
Assert.AreEqual("XtestY\tTrue", resultStr, "patch_apply: Near edge exact match.");
patches = dmp.patch_make("y", "y123");
results = dmp.patch_apply(patches, "x");
boolArray = (bool[])results[1];
resultStr = results[0] + "\t" + boolArray[0];
Assert.AreEqual("x123\tTrue", resultStr, "patch_apply: Edge partial match.");
}