Skip to content

Commit 22481c9

Browse files
test: added test for the example specified in the docs of LongestNonOverlappingSequences
1 parent 9c7c3a5 commit 22481c9

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

src/main/java/org/variantsync/vevos/simulation/variability/SPLCommit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public Optional<SPLCommit[]> parents() {
138138
return Optional.ofNullable(parents);
139139
}
140140

141-
public void setParents(final SPLCommit[] parents) {
141+
public void setParents(final SPLCommit... parents) {
142142
this.parents = parents;
143143
}
144144

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.variantsync.vevos.simulation.variability.sequenceextraction;
2+
3+
import org.junit.Test;
4+
import org.variantsync.functjonal.list.NonEmptyList;
5+
import org.variantsync.vevos.simulation.variability.SPLCommit;
6+
7+
import java.util.Arrays;
8+
import java.util.List;
9+
10+
public class LongestNonOverlappingSequencesTest {
11+
12+
@Test
13+
public void exampleExtraction() {
14+
// For example, if the commits comprise three partially overlapping sequences ([A-B-C-D-E], [X-Y-Z], [A-B-F-G]),
15+
// the function will return the sequences ([A-B-C-D-E], [X-Y-Z], [F-G]).
16+
final SPLCommit a = new SPLCommit("A");
17+
final SPLCommit b = new SPLCommit("B");
18+
final SPLCommit c = new SPLCommit("C");
19+
final SPLCommit d = new SPLCommit("D");
20+
final SPLCommit e = new SPLCommit("E");
21+
final SPLCommit f = new SPLCommit("F");
22+
final SPLCommit g = new SPLCommit("G");
23+
final SPLCommit x = new SPLCommit("X");
24+
final SPLCommit y = new SPLCommit("Y");
25+
final SPLCommit z = new SPLCommit("Z");
26+
// A has no parent
27+
a.setParents();
28+
// A-B
29+
b.setParents(a);
30+
// B-C
31+
c.setParents(b);
32+
// C-D
33+
d.setParents(c);
34+
// D-E
35+
e.setParents(d);
36+
// B-F
37+
f.setParents(b);
38+
// F-G
39+
g.setParents(f);
40+
// X has no parent
41+
x.setParents();
42+
// X-Y
43+
y.setParents(x);
44+
// Y-Z
45+
z.setParents(y);
46+
47+
List<SPLCommit> exampleCommits = Arrays.asList(a, b, c, d, e, f, g, x, y, z);
48+
NonEmptyList<SPLCommit> expectedOne = new NonEmptyList<>(Arrays.asList(a,b,c,d,e));
49+
NonEmptyList<SPLCommit> expectedTwo = new NonEmptyList<>(Arrays.asList(x, y, z));
50+
NonEmptyList<SPLCommit> expectedThree = new NonEmptyList<>(Arrays.asList(f, g));
51+
52+
LongestNonOverlappingSequences algorithm = new LongestNonOverlappingSequences();
53+
List<NonEmptyList<SPLCommit>> result = algorithm.extract(exampleCommits);
54+
55+
assert result.size() == 3;
56+
assert sequencesAreEqual(result.get(0), expectedOne);
57+
assert sequencesAreEqual(result.get(1), expectedTwo);
58+
assert sequencesAreEqual(result.get(2), expectedThree);
59+
}
60+
61+
public boolean sequencesAreEqual(final NonEmptyList<SPLCommit> a, final NonEmptyList<SPLCommit> b) {
62+
if (a.size() != b.size()) {
63+
return false;
64+
}
65+
for (int i = 0; i < a.size(); i++) {
66+
if (!a.get(i).id().equals(b.get(i).id())) {
67+
return false;
68+
}
69+
}
70+
return true;
71+
}
72+
}

0 commit comments

Comments
 (0)