[jsword-svn] r1341 - in trunk/common/src: main/java/org/crosswire/common/diff test/java/org/crosswire/common/diff
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Wed May 23 04:47:26 MST 2007
Author: dmsmith
Date: 2007-05-23 04:47:26 -0700 (Wed, 23 May 2007)
New Revision: 1341
Added:
trunk/common/src/test/java/org/crosswire/common/diff/BitapTest.java
trunk/common/src/test/java/org/crosswire/common/diff/CommonalityTest.java
trunk/common/src/test/java/org/crosswire/common/diff/DiffCleanupTest.java
trunk/common/src/test/java/org/crosswire/common/diff/DifferenceTest.java
trunk/common/src/test/java/org/crosswire/common/diff/LineMapTest.java
Modified:
trunk/common/src/main/java/org/crosswire/common/diff/Bitap.java
trunk/common/src/main/java/org/crosswire/common/diff/CommonMiddle.java
trunk/common/src/main/java/org/crosswire/common/diff/Commonality.java
trunk/common/src/main/java/org/crosswire/common/diff/DiffCleanup.java
trunk/common/src/main/java/org/crosswire/common/diff/Difference.java
trunk/common/src/test/java/org/crosswire/common/diff/diff_match_patch_test.java
Log:
Test cases for diff.
Modified: trunk/common/src/main/java/org/crosswire/common/diff/Bitap.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Bitap.java 2007-05-23 01:48:45 UTC (rev 1340)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Bitap.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -36,7 +36,6 @@
*/
public class Bitap implements Locator
{
-
/**
* Locate the best instance of 'pattern' in 'text' near 'loc'.
* @param text The text to search
@@ -178,7 +177,7 @@
return bestLoc;
}
- public Map getAlphabet()
+ protected Map getAlphabet()
{
return alphabet;
}
@@ -197,7 +196,7 @@
}
// Initialize the alphabet for the Bitap algorithm.
- public void alphabet()
+ protected void alphabet()
{
int len = pattern.length();
Modified: trunk/common/src/main/java/org/crosswire/common/diff/CommonMiddle.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/CommonMiddle.java 2007-05-23 01:48:45 UTC (rev 1340)
+++ trunk/common/src/main/java/org/crosswire/common/diff/CommonMiddle.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -41,7 +41,12 @@
*/
public CommonMiddle(String sourceStart, String targetStart, String commonality, String sourceEnd, String targetEnd)
{
- super();
+ assert sourceStart != null;
+ assert targetStart != null;
+ assert commonality != null;
+ assert sourceEnd != null;
+ assert targetEnd != null;
+
this.sourceStart = sourceStart;
this.targetStart = targetStart;
this.commonality = commonality;
@@ -89,9 +94,68 @@
return targetEnd;
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append(sourceStart);
+ buf.append(',');
+ buf.append(targetStart);
+ buf.append(',');
+ buf.append(commonality);
+ buf.append(',');
+ buf.append(sourceEnd);
+ buf.append(',');
+ buf.append(targetEnd);
+ return buf.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((commonality == null) ? 0 : commonality.hashCode());
+ result = PRIME * result + ((sourceEnd == null) ? 0 : sourceEnd.hashCode());
+ result = PRIME * result + ((sourceStart == null) ? 0 : sourceStart.hashCode());
+ result = PRIME * result + ((targetEnd == null) ? 0 : targetEnd.hashCode());
+ result = PRIME * result + ((targetStart == null) ? 0 : targetStart.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (obj == null || getClass() != obj.getClass())
+ {
+ return false;
+ }
+
+ final CommonMiddle other = (CommonMiddle) obj;
+
+ return commonality.equals(other.commonality)
+ && sourceEnd.equals(other.sourceEnd)
+ && sourceStart.equals(other.sourceStart)
+ && targetEnd.equals(other.targetEnd)
+ && targetStart.equals(other.targetStart);
+ }
+
private String sourceStart;
private String targetStart;
private String commonality;
private String sourceEnd;
private String targetEnd;
+
}
\ No newline at end of file
Modified: trunk/common/src/main/java/org/crosswire/common/diff/Commonality.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Commonality.java 2007-05-23 01:48:45 UTC (rev 1340)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Commonality.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -21,7 +21,6 @@
*/
package org.crosswire.common.diff;
-
/**
* A Commonality is shared text at the beginning, middle or end of two strings.
*
@@ -54,7 +53,7 @@
int pointermid = pointermax;
while (pointermin < pointermid)
{
- if (source.substring(0, pointermid) == target.substring(0, pointermid))
+ if (source.regionMatches(0, target, 0, pointermid))
{
pointermin = pointermid;
}
@@ -81,7 +80,7 @@
int pointermid = pointermax;
while (pointermin < pointermid)
{
- if (source.substring(source.length() - pointermid) == target.substring(target.length() - pointermid))
+ if (source.regionMatches(source.length() - pointermid, target, target.length() - pointermid, pointermid))
{
pointermin = pointermid;
}
Modified: trunk/common/src/main/java/org/crosswire/common/diff/DiffCleanup.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/DiffCleanup.java 2007-05-23 01:48:45 UTC (rev 1340)
+++ trunk/common/src/main/java/org/crosswire/common/diff/DiffCleanup.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -147,7 +147,7 @@
EditType editType = curDiff.getEditType();
if (EditType.EQUAL.equals(editType)) // equality found
{
- if (curDiff.getText().length() < EDIT_COST && (postInsert + postDelete) > 0)
+ if (curDiff.getText().length() < editCost && (postInsert + postDelete) > 0)
{
// Candidate found.
equalities.push(curDiff);
@@ -184,8 +184,9 @@
// <ins>A</del>X<ins>C</ins><del>D</del>
// <ins>A</ins><del>B</del>X<del>C</del>
if (lastEquality != null
- && (((preInsert + preDelete + postInsert + postDelete) > 0) || ((lastEquality.length() < EDIT_COST / 2) && (preInsert + preDelete
- + postInsert + postDelete) == 3)))
+ && (((preInsert + preDelete + postInsert + postDelete) > 0)
+ || ((lastEquality.length() < editCost / 2)
+ && (preInsert + preDelete + postInsert + postDelete) == 3)))
{
// position pointer to the element after the one at the end of the stack
while (curDiff != equalities.lastElement())
@@ -374,8 +375,17 @@
}
/**
+ * Set the edit cost for efficiency
+ * @param newEditCost
+ */
+ public static void setEditCost(int newEditCost)
+ {
+ editCost = newEditCost;
+ }
+
+ /**
* Cost of an empty edit operation in terms of edit characters.
*/
private static final int EDIT_COST = 4;
-
+ private static int editCost = EDIT_COST;
}
Modified: trunk/common/src/main/java/org/crosswire/common/diff/Difference.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/diff/Difference.java 2007-05-23 01:48:45 UTC (rev 1340)
+++ trunk/common/src/main/java/org/crosswire/common/diff/Difference.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -33,6 +33,9 @@
{
public Difference(EditType edit, String text)
{
+ assert editType != null;
+ assert text != null;
+
this.editType = edit;
this.text = text;
}
@@ -117,10 +120,39 @@
text = addText + text;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return 31 * editType.hashCode() + text.hashCode();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (obj == null || getClass() != obj.getClass())
+ {
+ return false;
+ }
+
+ final Difference other = (Difference) obj;
+
+ return editType.equals(other.editType) && text.equals(other.text);
+ }
+
/**
* The edit to perform
*/
private EditType editType;
private String text;
private int index;
+
}
Added: trunk/common/src/test/java/org/crosswire/common/diff/BitapTest.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/diff/BitapTest.java (rev 0)
+++ trunk/common/src/test/java/org/crosswire/common/diff/BitapTest.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -0,0 +1,86 @@
+package org.crosswire.common.diff;
+
+/* Test harness for diff_match_patch.java
+ *
+ * Version 2.2, May 2007
+ * If debugging errors, start with the first reported error,
+ * subsequent tests often rely on earlier ones.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.crosswire.common.diff.Bitap;
+import org.crosswire.common.diff.CommonMiddle;
+import org.crosswire.common.diff.Commonality;
+import org.crosswire.common.diff.Diff;
+import org.crosswire.common.diff.Difference;
+import org.crosswire.common.diff.EditType;
+import org.crosswire.common.diff.LineMap;
+import org.crosswire.common.diff.Patch;
+
+
+public class BitapTest extends TestCase {
+
+
+ protected void setUp()
+ {
+ }
+
+
+ // MATCH TEST FUNCTIONS
+
+
+ public void testMatchAlphabet()
+ {
+ // Initialise the bitmasks for Bitap
+ Map bitmask;
+ bitmask = new HashMap();
+ bitmask.put(new Character('a'), new Integer(4)); bitmask.put(new Character('b'), new Integer(2)); bitmask.put(new Character('c'), new Integer(1));
+ Bitap bitap = new Bitap("","abc",0); //$NON-NLS-1$ //$NON-NLS-2$
+ bitap.alphabet();
+ assertEquals("match_alphabet: Unique.", bitmask, bitap.getAlphabet()); //$NON-NLS-1$
+ bitmask = new HashMap();
+ bitmask.put(new Character('a'), new Integer(37)); bitmask.put(new Character('b'), new Integer(18)); bitmask.put(new Character('c'), new Integer(8));
+ bitap = new Bitap("","abcaba",0); //$NON-NLS-1$ //$NON-NLS-2$
+ bitap.alphabet();
+ assertEquals("match_alphabet: Duplicates.", bitmask, bitap.getAlphabet()); //$NON-NLS-1$
+ }
+
+ public void testMatchBitap()
+ {
+// // Bitap algorithm
+// dmp.Match_Balance = 0.5f;
+// dmp.Match_Threshold = 0.5f;
+// dmp.Match_MinLength = 100;
+// dmp.Match_MaxLength = 1000;
+// assertEquals("match_bitap: Exact match #1.", 5, dmp.match_bitap("abcdefghijk", "fgh", 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// assertEquals("match_bitap: Exact match #2.", 5, dmp.match_bitap("abcdefghijk", "fgh", 0)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// assertEquals("match_bitap: Fuzzy match #1.", 4, dmp.match_bitap("abcdefghijk", "efxhi", 0)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// assertEquals("match_bitap: Fuzzy match #2.", 2, dmp.match_bitap("abcdefghijk", "cdefxyhijk", 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// assertEquals("match_bitap: Fuzzy match #3.", -1, dmp.match_bitap("abcdefghijk", "bxy", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// assertEquals("match_bitap: Overflow.", 2, dmp.match_bitap("123456789xx0", "3456789x0", 2)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// dmp.Match_Threshold = 0.75f;
+// assertEquals("match_bitap: Threshold #1.", 4, dmp.match_bitap("abcdefghijk", "efxyhi", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// dmp.Match_Threshold = 0.1f;
+// assertEquals("match_bitap: Threshold #2.", 1, dmp.match_bitap("abcdefghijk", "bcdef", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// dmp.Match_Threshold = 0.5f;
+// assertEquals("match_bitap: Multiple select #1.", 0, dmp.match_bitap("abcdexyzabcde", "abccde", 3)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// assertEquals("match_bitap: Multiple select #2.", 8, dmp.match_bitap("abcdexyzabcde", "abccde", 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// dmp.Match_Balance = 0.6f; // Strict location, loose accuracy.
+// assertEquals("match_bitap: Balance test #1.", -1, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// assertEquals("match_bitap: Balance test #2.", 0, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcxdxexfgh", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// dmp.Match_Balance = 0.4f; // Strict accuracy loose location.
+// assertEquals("match_bitap: Balance test #3.", 0, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// assertEquals("match_bitap: Balance test #4.", -1, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcxdxexfgh", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// dmp.Match_Balance = 0.5f;
+ }
+
+}
Added: trunk/common/src/test/java/org/crosswire/common/diff/CommonalityTest.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/diff/CommonalityTest.java (rev 0)
+++ trunk/common/src/test/java/org/crosswire/common/diff/CommonalityTest.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -0,0 +1,45 @@
+package org.crosswire.common.diff;
+
+/* Test harness for diff_match_patch.java
+ *
+ * Version 2.2, May 2007
+ * If debugging errors, start with the first reported error,
+ * subsequent tests often rely on earlier ones.
+ */
+
+import junit.framework.TestCase;
+
+
+public class CommonalityTest extends TestCase {
+
+
+ protected void setUp()
+ {
+ }
+
+ public void testPrefix()
+ {
+ // Detect and remove any common prefix.
+ assertEquals("Commonality.prefix: Null case.", 0, Commonality.prefix("abc", "xyz")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("Commonality.prefix: Non-null case.", 4, Commonality.prefix("1234abc", "1234xyz")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testSuffix()
+ {
+ // Detect and remove any common suffix.
+ assertEquals("Commonality.suffix: Null case.", 0, Commonality.suffix("abc", "xyz")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("Commonality.suffix: Non-null case.", 4, Commonality.suffix("abc1234", "xyz1234")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testHalfmatch()
+ {
+ // Detect a halfmatch.
+ assertNull("Commonality.halfMatch: No match.", Commonality.halfMatch("1234567890", "abcdef")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("Commonality.halfMatch: Single Match #1.", new CommonMiddle("12", "90", "345678", "a", "z"), Commonality.halfMatch("1234567890", "a345678z")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
+ assertEquals("Commonality.halfMatch: Single Match #2.", new CommonMiddle("a", "z", "345678", "12", "90"), Commonality.halfMatch("a345678z", "1234567890")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
+ assertEquals("Commonality.halfMatch: Multiple Matches #1.", new CommonMiddle("12123", "123121", "1234123451234", "a", "z"), Commonality.halfMatch("121231234123451234123121", "a1234123451234z")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
+ assertEquals("Commonality.halfMatch: Multiple Matches #2.", new CommonMiddle("", "-=-=-=-=-=", "x-=-=-=-=-=-=-=", "x", ""), Commonality.halfMatch("x-=-=-=-=-=-=-=-=-=-=-=-=", "xx-=-=-=-=-=-=-=")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
+ assertEquals("Commonality.halfMatch: Multiple Matches #3.", new CommonMiddle("-=-=-=-=-=", "", "-=-=-=-=-=-=-=y", "", "y"), Commonality.halfMatch("-=-=-=-=-=-=-=-=-=-=-=-=y", "-=-=-=-=-=-=-=yy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
+ }
+
+}
Added: trunk/common/src/test/java/org/crosswire/common/diff/DiffCleanupTest.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/diff/DiffCleanupTest.java (rev 0)
+++ trunk/common/src/test/java/org/crosswire/common/diff/DiffCleanupTest.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -0,0 +1,107 @@
+package org.crosswire.common.diff;
+
+/* Test harness for diff_match_patch.java
+ *
+ * Version 2.2, May 2007
+ * If debugging errors, start with the first reported error,
+ * subsequent tests often rely on earlier ones.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+
+public class DiffCleanupTest extends TestCase {
+
+
+ protected void setUp()
+ {
+ }
+
+
+ public void testDiffCleanupMerge()
+ {
+ // Cleanup a messy diff
+ List diffs = diffList();
+ DiffCleanup.cleanupMerge(diffs);
+ assertEquals("diff_cleanupMerge: Null case.", diffList(), diffs); //$NON-NLS-1$
+ diffs = diffList(new Object[] { new Difference(EditType.EQUAL, "a"), new Difference(EditType.DELETE, "b"), new Difference(EditType.INSERT, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ DiffCleanup.cleanupMerge(diffs);
+ assertEquals("diff_cleanupMerge: No change case.", diffList(new Object[] { new Difference(EditType.EQUAL, "a"), new Difference(EditType.DELETE, "b"), new Difference(EditType.INSERT, "c") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ diffs = diffList(new Object[] { new Difference(EditType.EQUAL, "a"), new Difference(EditType.EQUAL, "b"), new Difference(EditType.EQUAL, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ DiffCleanup.cleanupMerge(diffs);
+ assertEquals("diff_cleanupMerge: Merge equalities.", diffList(new Object[] { new Difference(EditType.EQUAL, "abc") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.DELETE, "b"), new Difference(EditType.DELETE, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ DiffCleanup.cleanupMerge(diffs);
+ assertEquals("diff_cleanupMerge: Merge deletions.", diffList(new Object[] { new Difference(EditType.DELETE, "abc") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$
+ diffs = diffList(new Object[] { new Difference(EditType.INSERT, "a"), new Difference(EditType.INSERT, "b"), new Difference(EditType.INSERT, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ DiffCleanup.cleanupMerge(diffs);
+ assertEquals("diff_cleanupMerge: Merge insertions.", diffList(new Object[] { new Difference(EditType.INSERT, "abc") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.INSERT, "b"), new Difference(EditType.DELETE, "c"), new Difference(EditType.INSERT, "d"), new Difference(EditType.EQUAL, "e"), new Difference(EditType.EQUAL, "f") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+ DiffCleanup.cleanupMerge(diffs);
+ assertEquals("diff_cleanupMerge: Merge interweave.", diffList(new Object[] { new Difference(EditType.DELETE, "ac"), new Difference(EditType.INSERT, "bd"), new Difference(EditType.EQUAL, "ef") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.INSERT, "abc"), new Difference(EditType.DELETE, "dc") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ DiffCleanup.cleanupMerge(diffs);
+ assertEquals("diff_cleanupMerge: Prefix and suffix detection.", diffList(new Object[] { new Difference(EditType.EQUAL, "a"), new Difference(EditType.DELETE, "d"), new Difference(EditType.INSERT, "b"), new Difference(EditType.EQUAL, "c") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ }
+
+ public void testDiffCleanupSemantic()
+ {
+ // Cleanup semantically trivial equalities
+ List diffs = diffList();
+ DiffCleanup.cleanupSemantic(diffs);
+ assertEquals("diff_cleanupSemantic: Null case.", diffList(), diffs); //$NON-NLS-1$
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.INSERT, "b"), new Difference(EditType.EQUAL, "cd"), new Difference(EditType.DELETE, "e") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ DiffCleanup.cleanupSemantic(diffs);
+ assertEquals("diff_cleanupSemantic: No elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.INSERT, "b"), new Difference(EditType.EQUAL, "cd"), new Difference(EditType.DELETE, "e") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.EQUAL, "b"), new Difference(EditType.DELETE, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ DiffCleanup.cleanupSemantic(diffs);
+ assertEquals("diff_cleanupSemantic: Simple elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abc"), new Difference(EditType.INSERT, "b") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.EQUAL, "cd"), new Difference(EditType.DELETE, "e"), new Difference(EditType.EQUAL, "f"), new Difference(EditType.INSERT, "g") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ DiffCleanup.cleanupSemantic(diffs);
+ assertEquals("diff_cleanupSemantic: Backpass elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abcdef"), new Difference(EditType.INSERT, "cdfg") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testDiffCleanupEfficiency()
+ {
+ // Cleanup operationally trivial equalities
+ DiffCleanup.setEditCost(4);
+ List diffs = diffList();
+ DiffCleanup.cleanupEfficiency(diffs);
+ assertEquals("diff_cleanupEfficiency: Null case.", diffList(), diffs); //$NON-NLS-1$
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "wxyz"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ DiffCleanup.cleanupEfficiency(diffs);
+ assertEquals("diff_cleanupEfficiency: No elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "wxyz"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "xyz"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ DiffCleanup.cleanupEfficiency(diffs);
+ assertEquals("diff_cleanupEfficiency: Four-edit elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abxyzcd"), new Difference(EditType.INSERT, "12xyz34") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ diffs = diffList(new Object[] { new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "x"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ DiffCleanup.cleanupEfficiency(diffs);
+ assertEquals("diff_cleanupEfficiency: Three-edit elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "xcd"), new Difference(EditType.INSERT, "12x34") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "xy"), new Difference(EditType.INSERT, "34"), new Difference(EditType.EQUAL, "z"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "56") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
+ DiffCleanup.cleanupEfficiency(diffs);
+ assertEquals("diff_cleanupEfficiency: Backpass elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abxyzcd"), new Difference(EditType.INSERT, "12xy34z56") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ DiffCleanup.setEditCost(5);
+ diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "wxyz"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ DiffCleanup.cleanupEfficiency(diffs);
+ assertEquals("diff_cleanupEfficiency: High cost elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abwxyzcd"), new Difference(EditType.INSERT, "12wxyz34") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ DiffCleanup.setEditCost(4);
+ }
+
+ // Private function for quickly building lists of diffs.
+ private static List diffList()
+ {
+ return new ArrayList();
+ }
+
+ // Private function for quickly building lists of diffs.
+ private static List diffList(Object[] diffs)
+ {
+ List myDiffList = new ArrayList();
+ myDiffList.addAll(Arrays.asList(diffs));
+ return myDiffList;
+ }
+}
Added: trunk/common/src/test/java/org/crosswire/common/diff/DifferenceTest.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/diff/DifferenceTest.java (rev 0)
+++ trunk/common/src/test/java/org/crosswire/common/diff/DifferenceTest.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -0,0 +1,33 @@
+package org.crosswire.common.diff;
+
+/* Test harness for diff_match_patch.java
+ *
+ * Version 2.2, May 2007
+ * If debugging errors, start with the first reported error,
+ * subsequent tests often rely on earlier ones.
+ */
+
+import junit.framework.TestCase;
+
+public class DifferenceTest extends TestCase
+{
+
+
+ protected void setUp()
+ {
+ }
+
+ public void testHashCode()
+ {
+ assertTrue("Difference.hashCode:", (new Difference(EditType.EQUAL, "a")).hashCode() == (new Difference(EditType.EQUAL, "a")).hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertFalse("Difference.hashCode:", (new Difference(EditType.EQUAL, "a")).hashCode() == (new Difference(EditType.EQUAL, "ab")).hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertFalse("Difference.hashCode:", (new Difference(EditType.EQUAL, "a")).hashCode() == (new Difference(EditType.INSERT, "a")).hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testEquals()
+ {
+ // First check that Diff equality works
+ assertTrue("Difference.equals:", new Difference(EditType.EQUAL, "a").equals(new Difference(EditType.EQUAL, "a"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("Difference.equals:", new Difference(EditType.EQUAL, "a"), new Difference(EditType.EQUAL, "a")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+}
Added: trunk/common/src/test/java/org/crosswire/common/diff/LineMapTest.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/diff/LineMapTest.java (rev 0)
+++ trunk/common/src/test/java/org/crosswire/common/diff/LineMapTest.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -0,0 +1,69 @@
+package org.crosswire.common.diff;
+
+/* Test harness for diff_match_patch.java
+ *
+ * Version 2.2, May 2007
+ * If debugging errors, start with the first reported error,
+ * subsequent tests often rely on earlier ones.
+ */
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class LineMapTest extends TestCase
+{
+
+
+ protected void setUp()
+ {
+ }
+
+ public void testCompile()
+ {
+ // Convert lines down to characters
+ ArrayList tmpVector = new ArrayList();
+ tmpVector.add(""); //$NON-NLS-1$
+ tmpVector.add("alpha\n"); //$NON-NLS-1$
+ tmpVector.add("beta\n"); //$NON-NLS-1$
+ LineMap map = new LineMap("alpha\nbeta\nalpha\n", "beta\nalpha\nbeta\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("new LineMap:", "\u0001\u0002\u0001", map.getSourceMap()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("new LineMap:", "\u0002\u0001\u0002", map.getTargetMap()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("new LineMap:", tmpVector, map.getLines()); //$NON-NLS-1$
+
+ tmpVector.clear();
+ tmpVector.add(""); //$NON-NLS-1$
+ tmpVector.add("alpha\r\n"); //$NON-NLS-1$
+ tmpVector.add("beta\r\n"); //$NON-NLS-1$
+ tmpVector.add("\r\n"); //$NON-NLS-1$
+ map = new LineMap("", "alpha\r\nbeta\r\n\r\n\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("new LineMap:", "", map.getSourceMap()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("new LineMap:", "\u0001\u0002\u0003\u0003", map.getTargetMap()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("new LineMap:", tmpVector, map.getLines()); //$NON-NLS-1$
+ }
+
+ public void testRestore()
+ {
+ // Convert chars up to lines
+ List diffs = diffList(new Object[] { new Difference(EditType.EQUAL, "\u0001\u0002\u0001"), new Difference(EditType.INSERT, "\u0002\u0001\u0002") }); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayList tmpVector = new ArrayList();
+ tmpVector.add(""); //$NON-NLS-1$
+ tmpVector.add("alpha\n"); //$NON-NLS-1$
+ tmpVector.add("beta\n"); //$NON-NLS-1$
+ LineMap map = new LineMap("alpha\nbeta\nalpha\n", "beta\nalpha\nbeta\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ map.restore(diffs);
+ assertEquals("LineMap.restore:", diffList(new Object[] {new Difference(EditType.EQUAL, "alpha\nbeta\nalpha\n"), new Difference(EditType.INSERT, "beta\nalpha\nbeta\n") }).get(0), diffs.get(0)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("LineMap.restore:", diffList(new Object[] {new Difference(EditType.EQUAL, "alpha\nbeta\nalpha\n"), new Difference(EditType.INSERT, "beta\nalpha\nbeta\n") }).get(diffs.size() - 1), diffs.get(diffs.size() - 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertEquals("LineMap.restore:", diffList(new Object[] {new Difference(EditType.EQUAL, "alpha\nbeta\nalpha\n"), new Difference(EditType.INSERT, "beta\nalpha\nbeta\n") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ // Private function for quickly building lists of diffs.
+ private static List diffList(Object[] diffs)
+ {
+ List myDiffList = new ArrayList();
+ myDiffList.addAll(Arrays.asList(diffs));
+ return myDiffList;
+ }
+}
Modified: trunk/common/src/test/java/org/crosswire/common/diff/diff_match_patch_test.java
===================================================================
--- trunk/common/src/test/java/org/crosswire/common/diff/diff_match_patch_test.java 2007-05-23 01:48:45 UTC (rev 1340)
+++ trunk/common/src/test/java/org/crosswire/common/diff/diff_match_patch_test.java 2007-05-23 11:47:26 UTC (rev 1341)
@@ -37,143 +37,6 @@
// DIFF TEST FUNCTIONS
-
- public void testDiffPrefix()
- {
- // Detect and remove any common prefix.
- assertEquals("diff_commonPrefix: Null case.", 0, Commonality.prefix("abc", "xyz")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertEquals("diff_commonPrefix: Non-null case.", 4, Commonality.prefix("1234abc", "1234xyz")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testDiffSuffix()
- {
- // Detect and remove any common suffix.
- assertEquals("diff_commonSuffix: Null case.", 0, Commonality.suffix("abc", "xyz")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertEquals("diff_commonSuffix: Non-null case.", 4, Commonality.suffix("abc1234", "xyz1234")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void testDiffHalfmatch()
- {
- // Detect a halfmatch.
- assertNull("diff_halfMatch: No match.", Commonality.halfMatch("1234567890", "abcdef")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertEquals("diff_halfMatch: Single Match #1.", new CommonMiddle("12", "90", "345678", "a", "z"), Commonality.halfMatch("1234567890", "a345678z")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- assertEquals("diff_halfMatch: Single Match #2.", new CommonMiddle("a", "z", "345678", "12", "90"), Commonality.halfMatch("a345678z", "1234567890")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- assertEquals("diff_halfMatch: Multiple Matches #1.", new CommonMiddle("12123", "123121", "1234123451234", "a", "z"), Commonality.halfMatch("121231234123451234123121", "a1234123451234z")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- assertEquals("diff_halfMatch: Multiple Matches #2.", new CommonMiddle("", "-=-=-=-=-=", "x-=-=-=-=-=-=-=", "x", ""), Commonality.halfMatch("x-=-=-=-=-=-=-=-=-=-=-=-=", "xx-=-=-=-=-=-=-=")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- assertEquals("diff_halfMatch: Multiple Matches #3.", new CommonMiddle("-=-=-=-=-=", "", "-=-=-=-=-=-=-=y", "", "y"), Commonality.halfMatch("-=-=-=-=-=-=-=-=-=-=-=-=y", "-=-=-=-=-=-=-=yy")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- }
-
- public void testDiffLinesToChars()
- {
- // Convert lines down to characters
- ArrayList tmpVector = new ArrayList();
- tmpVector.add(""); //$NON-NLS-1$
- tmpVector.add("alpha\n"); //$NON-NLS-1$
- tmpVector.add("beta\n"); //$NON-NLS-1$
- LineMap map = new LineMap("alpha\nbeta\nalpha\n", "beta\nalpha\nbeta\n"); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("diff_linesToChars:", "\u0001\u0002\u0001", map.getSourceMap()); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("diff_linesToChars:", "\u0002\u0001\u0002", map.getTargetMap()); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("diff_linesToChars:", tmpVector, map.getLines()); //$NON-NLS-1$
-
- tmpVector.clear();
- tmpVector.add(""); //$NON-NLS-1$
- tmpVector.add("alpha\r\n"); //$NON-NLS-1$
- tmpVector.add("beta\r\n"); //$NON-NLS-1$
- tmpVector.add("\r\n"); //$NON-NLS-1$
- map = new LineMap("", "alpha\r\nbeta\r\n\r\n\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("diff_linesToChars:", "", map.getSourceMap()); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("diff_linesToChars:", "\u0001\u0002\u0003\u0003", map.getTargetMap()); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("diff_linesToChars:", tmpVector, map.getLines()); //$NON-NLS-1$
- }
-
- public void testDiffCharsToLines()
- {
- // First check that Diff equality works
- assertTrue("diff_charsToLines:", new Difference(EditType.EQUAL, "a").equals(new Difference(EditType.EQUAL, "a"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertEquals("diff_charsToLines:", new Difference(EditType.EQUAL, "a"), new Difference(EditType.EQUAL, "a")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- // Second check that Diff hash codes work
- assertTrue("diff_charsToLines:", (new Difference(EditType.EQUAL, "a")).hashCode() == (new Difference(EditType.EQUAL, "a")).hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertFalse("diff_charsToLines:", (new Difference(EditType.EQUAL, "a")).hashCode() == (new Difference(EditType.EQUAL, "ab")).hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertFalse("diff_charsToLines:", (new Difference(EditType.EQUAL, "a")).hashCode() == (new Difference(EditType.INSERT, "a")).hashCode()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- // Convert chars up to lines
- List diffs = diffList(new Object[] { new Difference(EditType.EQUAL, "\u0001\u0002\u0001"), new Difference(EditType.INSERT, "\u0002\u0001\u0002") }); //$NON-NLS-1$ //$NON-NLS-2$
- ArrayList tmpVector = new ArrayList();
- tmpVector.add(""); //$NON-NLS-1$
- tmpVector.add("alpha\n"); //$NON-NLS-1$
- tmpVector.add("beta\n"); //$NON-NLS-1$
- LineMap map = new LineMap("alpha\nbeta\nalpha\n", "beta\nalpha\nbeta\n"); //$NON-NLS-1$ //$NON-NLS-2$
- map.restore(diffs);
- assertEquals("diff_charsToLines:", diffList(new Object[] {new Difference(EditType.EQUAL, "alpha\nbeta\nalpha\n"), new Difference(EditType.INSERT, "beta\nalpha\nbeta\n") }).get(0), diffs.get(0)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertEquals("diff_charsToLines:", diffList(new Object[] {new Difference(EditType.EQUAL, "alpha\nbeta\nalpha\n"), new Difference(EditType.INSERT, "beta\nalpha\nbeta\n") }).get(diffs.size() - 1), diffs.get(diffs.size() - 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertEquals("diff_charsToLines:", diffList(new Object[] {new Difference(EditType.EQUAL, "alpha\nbeta\nalpha\n"), new Difference(EditType.INSERT, "beta\nalpha\nbeta\n") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
-// public void testDiffCleanupMerge() {
-// // Cleanup a messy diff
-// List diffs = diffList();
-// dmp.diff_cleanupMerge(diffs);
-// assertEquals("diff_cleanupMerge: Null case.", diffList(), diffs); //$NON-NLS-1$
-// diffs = diffList(new Object[] { new Difference(EditType.EQUAL, "a"), new Difference(EditType.DELETE, "b"), new Difference(EditType.INSERT, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.diff_cleanupMerge(diffs);
-// assertEquals("diff_cleanupMerge: No change case.", diffList(new Object[] { new Difference(EditType.EQUAL, "a"), new Difference(EditType.DELETE, "b"), new Difference(EditType.INSERT, "c") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-// diffs = diffList(new Object[] { new Difference(EditType.EQUAL, "a"), new Difference(EditType.EQUAL, "b"), new Difference(EditType.EQUAL, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.diff_cleanupMerge(diffs);
-// assertEquals("diff_cleanupMerge: Merge equalities.", diffList(new Object[] { new Difference(EditType.EQUAL, "abc") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.DELETE, "b"), new Difference(EditType.DELETE, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.diff_cleanupMerge(diffs);
-// assertEquals("diff_cleanupMerge: Merge deletions.", diffList(new Object[] { new Difference(EditType.DELETE, "abc") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$
-// diffs = diffList(new Object[] { new Difference(EditType.INSERT, "a"), new Difference(EditType.INSERT, "b"), new Difference(EditType.INSERT, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.diff_cleanupMerge(diffs);
-// assertEquals("diff_cleanupMerge: Merge insertions.", diffList(new Object[] { new Difference(EditType.INSERT, "abc") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.INSERT, "b"), new Difference(EditType.DELETE, "c"), new Difference(EditType.INSERT, "d"), new Difference(EditType.EQUAL, "e"), new Difference(EditType.EQUAL, "f") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
-// dmp.diff_cleanupMerge(diffs);
-// assertEquals("diff_cleanupMerge: Merge interweave.", diffList(new Object[] { new Difference(EditType.DELETE, "ac"), new Difference(EditType.INSERT, "bd"), new Difference(EditType.EQUAL, "ef") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.INSERT, "abc"), new Difference(EditType.DELETE, "dc") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.diff_cleanupMerge(diffs);
-// assertEquals("diff_cleanupMerge: Prefix and suffix detection.", diffList(new Object[] { new Difference(EditType.EQUAL, "a"), new Difference(EditType.DELETE, "d"), new Difference(EditType.INSERT, "b"), new Difference(EditType.EQUAL, "c") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-// }
-
-// public void testDiffCleanupSemantic() {
-// // Cleanup semantically trivial equalities
-// List diffs = diffList();
-// dmp.diff_cleanupSemantic(diffs);
-// assertEquals("diff_cleanupSemantic: Null case.", diffList(), diffs); //$NON-NLS-1$
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.INSERT, "b"), new Difference(EditType.EQUAL, "cd"), new Difference(EditType.DELETE, "e") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-// dmp.diff_cleanupSemantic(diffs);
-// assertEquals("diff_cleanupSemantic: No elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.INSERT, "b"), new Difference(EditType.EQUAL, "cd"), new Difference(EditType.DELETE, "e") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.EQUAL, "b"), new Difference(EditType.DELETE, "c") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.diff_cleanupSemantic(diffs);
-// assertEquals("diff_cleanupSemantic: Simple elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abc"), new Difference(EditType.INSERT, "b") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.EQUAL, "cd"), new Difference(EditType.DELETE, "e"), new Difference(EditType.EQUAL, "f"), new Difference(EditType.INSERT, "g") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-// dmp.diff_cleanupSemantic(diffs);
-// assertEquals("diff_cleanupSemantic: Backpass elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abcdef"), new Difference(EditType.INSERT, "cdfg") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// }
-
-// public void testDiffCleanupEfficiency() {
-// // Cleanup operationally trivial equalities
-// dmp.Diff_EditCost = 4;
-// List diffs = diffList();
-// dmp.diff_cleanupEfficiency(diffs);
-// assertEquals("diff_cleanupEfficiency: Null case.", diffList(), diffs); //$NON-NLS-1$
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "wxyz"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-// dmp.diff_cleanupEfficiency(diffs);
-// assertEquals("diff_cleanupEfficiency: No elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "wxyz"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "xyz"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-// dmp.diff_cleanupEfficiency(diffs);
-// assertEquals("diff_cleanupEfficiency: Four-edit elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abxyzcd"), new Difference(EditType.INSERT, "12xyz34") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// diffs = diffList(new Object[] { new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "x"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-// dmp.diff_cleanupEfficiency(diffs);
-// assertEquals("diff_cleanupEfficiency: Three-edit elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "xcd"), new Difference(EditType.INSERT, "12x34") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "xy"), new Difference(EditType.INSERT, "34"), new Difference(EditType.EQUAL, "z"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "56") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
-// dmp.diff_cleanupEfficiency(diffs);
-// assertEquals("diff_cleanupEfficiency: Backpass elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abxyzcd"), new Difference(EditType.INSERT, "12xy34z56") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.Diff_EditCost = 5;
-// diffs = diffList(new Object[] { new Difference(EditType.DELETE, "ab"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "wxyz"), new Difference(EditType.DELETE, "cd"), new Difference(EditType.INSERT, "34") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
-// dmp.diff_cleanupEfficiency(diffs);
-// assertEquals("diff_cleanupEfficiency: High cost elimination.", diffList(new Object[] { new Difference(EditType.DELETE, "abwxyzcd"), new Difference(EditType.INSERT, "12wxyz34") }), diffs); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.Diff_EditCost = 4;
-// }
-
// public void testDiffAddIndex() {
// // Add an index to each diff tuple
// List diffs = diffList(new Object[] { new Difference(EditType.DELETE, "a"), new Difference(EditType.INSERT, "12"), new Difference(EditType.EQUAL, "wxy"), new Difference(EditType.INSERT, "34"), new Difference(EditType.EQUAL, "z"), new Difference(EditType.DELETE, "bcd"), new Difference(EditType.INSERT, "56") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
@@ -324,50 +187,6 @@
// MATCH TEST FUNCTIONS
-
- public void testMatchAlphabet() {
- // Initialise the bitmasks for Bitap
- Map bitmask;
- bitmask = new HashMap();
- bitmask.put(new Character('a'), new Integer(4)); bitmask.put(new Character('b'), new Integer(2)); bitmask.put(new Character('c'), new Integer(1));
- Bitap bitap = new Bitap("","abc",0); //$NON-NLS-1$ //$NON-NLS-2$
- bitap.alphabet();
- assertEquals("match_alphabet: Unique.", bitmask, bitap.getAlphabet()); //$NON-NLS-1$
- bitmask = new HashMap();
- bitmask.put(new Character('a'), new Integer(37)); bitmask.put(new Character('b'), new Integer(18)); bitmask.put(new Character('c'), new Integer(8));
- bitap = new Bitap("","abcaba",0); //$NON-NLS-1$ //$NON-NLS-2$
- bitap.alphabet();
- assertEquals("match_alphabet: Duplicates.", bitmask, bitap.getAlphabet()); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-// public void testMatchBitap() {
-// // Bitap algorithm
-// dmp.Match_Balance = 0.5f;
-// dmp.Match_Threshold = 0.5f;
-// dmp.Match_MinLength = 100;
-// dmp.Match_MaxLength = 1000;
-// assertEquals("match_bitap: Exact match #1.", 5, dmp.match_bitap("abcdefghijk", "fgh", 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// assertEquals("match_bitap: Exact match #2.", 5, dmp.match_bitap("abcdefghijk", "fgh", 0)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// assertEquals("match_bitap: Fuzzy match #1.", 4, dmp.match_bitap("abcdefghijk", "efxhi", 0)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// assertEquals("match_bitap: Fuzzy match #2.", 2, dmp.match_bitap("abcdefghijk", "cdefxyhijk", 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// assertEquals("match_bitap: Fuzzy match #3.", -1, dmp.match_bitap("abcdefghijk", "bxy", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// assertEquals("match_bitap: Overflow.", 2, dmp.match_bitap("123456789xx0", "3456789x0", 2)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.Match_Threshold = 0.75f;
-// assertEquals("match_bitap: Threshold #1.", 4, dmp.match_bitap("abcdefghijk", "efxyhi", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.Match_Threshold = 0.1f;
-// assertEquals("match_bitap: Threshold #2.", 1, dmp.match_bitap("abcdefghijk", "bcdef", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.Match_Threshold = 0.5f;
-// assertEquals("match_bitap: Multiple select #1.", 0, dmp.match_bitap("abcdexyzabcde", "abccde", 3)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// assertEquals("match_bitap: Multiple select #2.", 8, dmp.match_bitap("abcdexyzabcde", "abccde", 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.Match_Balance = 0.6f; // Strict location, loose accuracy.
-// assertEquals("match_bitap: Balance test #1.", -1, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// assertEquals("match_bitap: Balance test #2.", 0, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcxdxexfgh", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.Match_Balance = 0.4f; // Strict accuracy loose location.
-// assertEquals("match_bitap: Balance test #3.", 0, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcdefg", 24)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// assertEquals("match_bitap: Balance test #4.", -1, dmp.match_bitap("abcdefghijklmnopqrstuvwxyz", "abcxdxexfgh", 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-// dmp.Match_Balance = 0.5f;
-// }
-
// public void testMatchMain() {
// // Full match
// assertEquals("match_main: Equality.", 0, dmp.match_main("abcdef", "abcdef", 1000)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
More information about the jsword-svn
mailing list