Skip to content

Commit 1f9a8c6

Browse files
committed
added 0-length tests for sequence distances
1 parent c4de167 commit 1f9a8c6

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

src/org/cicirello/sequences/distance/KendallTauDistance.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public final class KendallTauDistance extends AbstractSequenceDistanceMeasurer {
9595
@Override
9696
public <T> int distance(Sequence<T> s1, Sequence<T> s2) {
9797
if (s1.length() != s2.length()) throw new IllegalArgumentException("Sequences must be same length for Kendall Tau distance.");
98+
if (s1.length() == 0) return 0;
9899

99100
int[][] relabeling = new int[s1.length()][2];
100101
int numLabels = relabelElementsToInts(s1,s2,relabeling);

tests/org/cicirello/sequences/distance/SequenceDistanceTests.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,13 @@ public void testExactMatchDistance() {
4646
int[] a4 = {0, 3, 2, 1, 4, 5};
4747
// testing with sequences of any one type should be sufficient, since the various sequence types have been separately tested,
4848
// and all of the individual distance methods delegate computation to a common method.
49-
//PrimitiveSequence s1 = new PrimitiveSequence(a1);
50-
//PrimitiveSequence s2 = new PrimitiveSequence(a2);
51-
//PrimitiveSequence s3 = new PrimitiveSequence(a3);
52-
//PrimitiveSequence s4 = new PrimitiveSequence(a4);
5349
assertEquals("maximal distance", 6, d.distance(a1,a2));
5450
assertEquals("end points differ", 2, d.distance(a1,a3));
5551
assertEquals("differ in interior positions", 2, d.distance(a1,a4));
5652
int[] b1 = {0, 1, 2, 3, 4, 5, 6, 7, 8};
5753
int[] b2 = {5, 0, 1, 2, 3, 4, 6, 7, 8};
5854
int[] b3 = {5, 1, 2, 3, 4, 0, 6, 7, 8};
5955
int[] b4 = {0, 3, 2, 1, 4, 5, 6, 7, 8};
60-
//PrimitiveSequence t1 = new PrimitiveSequence(b1);
61-
//PrimitiveSequence t2 = new PrimitiveSequence(b2);
62-
//PrimitiveSequence t3 = new PrimitiveSequence(b3);
63-
//PrimitiveSequence t4 = new PrimitiveSequence(b4);
6456
// tests with different length sequences
6557
assertEquals("identical except for extras", 3, d.distance(a1,b1));
6658
assertEquals("maximal distance", 9, d.distance(a1,b2));
@@ -194,25 +186,21 @@ private int naiveKendalTau(int[] s1, int[] s2) {
194186

195187

196188
private void identicalSequences(SequenceDistanceMeasurer d) {
197-
for (int n = 1; n <= 10; n++) {
189+
for (int n = 0; n <= 10; n++) {
198190
int[] a = new int[n];
199191
for (int i = 0; i < n; i++) a[i] = ThreadLocalRandom.current().nextInt(100);
200192
// testing with sequences of any one type should be sufficient, since the various sequence types have been separately tested,
201193
// and all of the individual distance methods delegate computation to a common method.
202-
//PrimitiveSequence s = new PrimitiveSequence(a);
203-
//PrimitiveSequence copy = s.copy();
204194
assertEquals("distance of a sequence to itself should be 0", 0, d.distance(a, a.clone()));
205195
}
206196
}
207197

208198
private void identicalSequencesD(SequenceDistanceMeasurerDouble d) {
209-
for (int n = 1; n <= 10; n++) {
199+
for (int n = 0; n <= 10; n++) {
210200
int[] a = new int[n];
211201
for (int i = 0; i < n; i++) a[i] = ThreadLocalRandom.current().nextInt(100);
212202
// testing with sequences of any one type should be sufficient, since the various sequence types have been separately tested,
213203
// and all of the individual distance methods delegate computation to a common method.
214-
//PrimitiveSequence s = new PrimitiveSequence(a);
215-
//PrimitiveSequence copy = s.copy();
216204
assertEquals("distance of a sequence to itself should be 0", 0.0, d.distancef(a, a.clone()), EPSILON);
217205
}
218206
}

0 commit comments

Comments
 (0)