Skip to content

Commit 145b5c3

Browse files
test(#8): added test that confirms that no StackOverflowError is caused by large histories
I also confirmed that the test fails when the recursive implementation is used
1 parent c329c19 commit 145b5c3

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/test/java/org/variantsync/vevos/simulation/variability/sequenceextraction/LongestNonOverlappingSequencesTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import org.variantsync.vevos.simulation.variability.SPLCommit;
66

77
import java.util.Arrays;
8+
import java.util.HashSet;
89
import java.util.List;
10+
import java.util.Set;
911

1012
public class LongestNonOverlappingSequencesTest {
1113

@@ -58,7 +60,27 @@ public void exampleExtraction() {
5860
assert sequencesAreEqual(result.get(2), expectedThree);
5961
}
6062

61-
public boolean sequencesAreEqual(final NonEmptyList<SPLCommit> a, final NonEmptyList<SPLCommit> b) {
63+
@Test
64+
public void stackOverflowPrevented() {
65+
int size = 10_000;
66+
Set<SPLCommit> commits = new HashSet<>();
67+
SPLCommit previousCommit = new SPLCommit("0");
68+
previousCommit.setParents();
69+
commits.add(previousCommit);
70+
for (int i = 1; i < size; i++) {
71+
SPLCommit commit = new SPLCommit(String.valueOf(i));
72+
commit.setParents(previousCommit);
73+
commits.add(commit);
74+
previousCommit = commit;
75+
}
76+
77+
LongestNonOverlappingSequences algo = new LongestNonOverlappingSequences();
78+
var result = algo.extract(commits);
79+
assert result.size() == 1;
80+
assert result.get(0).size() == size;
81+
}
82+
83+
private boolean sequencesAreEqual(final NonEmptyList<SPLCommit> a, final NonEmptyList<SPLCommit> b) {
6284
if (a.size() != b.size()) {
6385
return false;
6486
}

0 commit comments

Comments
 (0)