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>
This commit is contained in:
Shawn O. Pearce 2010-09-21 14:47:33 -07:00
parent 9bcf391355
commit e7a3e590ed
3 changed files with 18 additions and 28 deletions

View File

@ -62,7 +62,7 @@
* diffs between chunks of different length, measure the needed time and check
* 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 int minCPUTimerTicks = 10;
@ -186,7 +186,7 @@ private PerfData test(int characters) {
return ret;
}
private static class CharArray extends Sequence {
static class CharArray extends Sequence {
final char[] array;
public CharArray(String s) {
@ -199,7 +199,7 @@ public int size() {
}
}
private static class CharCmp extends SequenceComparator<CharArray> {
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];

View File

@ -43,9 +43,21 @@
package org.eclipse.jgit.diff;
import org.eclipse.jgit.diff.DiffPerformanceTest.CharArray;
import org.eclipse.jgit.diff.DiffPerformanceTest.CharCmp;
public class MyersDiffTest extends AbstractDiffTestCase {
@Override
protected DiffAlgorithm algorithm() {
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());
}
}

View File

@ -43,6 +43,9 @@
package org.eclipse.jgit.diff;
import org.eclipse.jgit.diff.DiffPerformanceTest.CharArray;
import org.eclipse.jgit.diff.DiffPerformanceTest.CharCmp;
public class PatienceDiffTest extends AbstractDiffTestCase {
@Override
protected DiffAlgorithm algorithm() {
@ -71,29 +74,4 @@ public void testPerformanceTestDeltaLength() {
EditList r = algorithm().diff(new CharCmp(), ac, bc);
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];
}
}
}