Browse Source

Reuse DiffPerformanceTest support code to validate algorithms

Each algorithm should produce a particular number of results
given one of the standard inputs used during the performance
tests.  To help ensure those tests are accurate, assert that
the edit list length is correct.

Change-Id: I292f8fde0cec6a60a75ce09e70814a00ca47cb99
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.10
Shawn O. Pearce 14 years ago
parent
commit
e7a3e590ed
  1. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffPerformanceTest.java
  2. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/MyersDiffTest.java
  3. 28
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/PatienceDiffTest.java

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/MyersDiffPerformanceTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffPerformanceTest.java

@ -62,7 +62,7 @@ import org.eclipse.jgit.util.CPUTimeStopWatch;
* diffs between chunks of different length, measure the needed time and check * diffs between chunks of different length, measure the needed time and check
* that time/(N*D) does not differ more than a certain factor. * that time/(N*D) does not differ more than a certain factor.
*/ */
public class MyersDiffPerformanceTest extends TestCase { public class DiffPerformanceTest extends TestCase {
private static final long longTaskBoundary = 5000000000L; private static final long longTaskBoundary = 5000000000L;
private static final int minCPUTimerTicks = 10; private static final int minCPUTimerTicks = 10;
@ -186,7 +186,7 @@ public class MyersDiffPerformanceTest extends TestCase {
return ret; return ret;
} }
private static class CharArray extends Sequence { static class CharArray extends Sequence {
final char[] array; final char[] array;
public CharArray(String s) { public CharArray(String s) {
@ -199,7 +199,7 @@ public class MyersDiffPerformanceTest extends TestCase {
} }
} }
private static class CharCmp extends SequenceComparator<CharArray> { static class CharCmp extends SequenceComparator<CharArray> {
@Override @Override
public boolean equals(CharArray a, int ai, CharArray b, int bi) { public boolean equals(CharArray a, int ai, CharArray b, int bi) {
return a.array[ai] == b.array[bi]; return a.array[ai] == b.array[bi];

12
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/MyersDiffTest.java

@ -43,9 +43,21 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import org.eclipse.jgit.diff.DiffPerformanceTest.CharArray;
import org.eclipse.jgit.diff.DiffPerformanceTest.CharCmp;
public class MyersDiffTest extends AbstractDiffTestCase { public class MyersDiffTest extends AbstractDiffTestCase {
@Override @Override
protected DiffAlgorithm algorithm() { protected DiffAlgorithm algorithm() {
return MyersDiff.INSTANCE; return MyersDiff.INSTANCE;
} }
public void testPerformanceTestDeltaLength() {
String a = DiffTestDataGenerator.generateSequence(40000, 971, 3);
String b = DiffTestDataGenerator.generateSequence(40000, 1621, 5);
CharArray ac = new CharArray(a);
CharArray bc = new CharArray(b);
EditList r = algorithm().diff(new CharCmp(), ac, bc);
assertEquals(131, r.size());
}
} }

28
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/PatienceDiffTest.java

@ -43,6 +43,9 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import org.eclipse.jgit.diff.DiffPerformanceTest.CharArray;
import org.eclipse.jgit.diff.DiffPerformanceTest.CharCmp;
public class PatienceDiffTest extends AbstractDiffTestCase { public class PatienceDiffTest extends AbstractDiffTestCase {
@Override @Override
protected DiffAlgorithm algorithm() { protected DiffAlgorithm algorithm() {
@ -71,29 +74,4 @@ public class PatienceDiffTest extends AbstractDiffTestCase {
EditList r = algorithm().diff(new CharCmp(), ac, bc); EditList r = algorithm().diff(new CharCmp(), ac, bc);
assertEquals(25, r.size()); assertEquals(25, r.size());
} }
private static class CharArray extends Sequence {
final char[] array;
public CharArray(String s) {
array = s.toCharArray();
}
@Override
public int size() {
return array.length;
}
}
private static class CharCmp extends SequenceComparator<CharArray> {
@Override
public boolean equals(CharArray a, int ai, CharArray b, int bi) {
return a.array[ai] == b.array[bi];
}
@Override
public int hash(CharArray seq, int ptr) {
return seq.array[ptr];
}
}
} }

Loading…
Cancel
Save