-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from VariantSync/next-release
VEVOS Simulation v.1.1.2
- Loading branch information
Showing
8 changed files
with
200 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...c/vevos/simulation/variability/sequenceextraction/LongestNonOverlappingSequencesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.variantsync.vevos.simulation.variability.sequenceextraction; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.variantsync.functjonal.list.NonEmptyList; | ||
import org.variantsync.vevos.simulation.variability.SPLCommit; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class LongestNonOverlappingSequencesTest { | ||
|
||
@Test | ||
public void exampleExtraction() { | ||
// For example, if the commits comprise three partially overlapping sequences ([A-B-C-D-E], [X-Y-Z], [A-B-F-G]), | ||
// the function will return the sequences ([A-B-C-D-E], [X-Y-Z], [F-G]). | ||
final SPLCommit a = new SPLCommit("A"); | ||
final SPLCommit b = new SPLCommit("B"); | ||
final SPLCommit c = new SPLCommit("C"); | ||
final SPLCommit d = new SPLCommit("D"); | ||
final SPLCommit e = new SPLCommit("E"); | ||
final SPLCommit f = new SPLCommit("F"); | ||
final SPLCommit g = new SPLCommit("G"); | ||
final SPLCommit x = new SPLCommit("X"); | ||
final SPLCommit y = new SPLCommit("Y"); | ||
final SPLCommit z = new SPLCommit("Z"); | ||
// A has no parent | ||
a.setParents(); | ||
// A-B | ||
b.setParents(a); | ||
// B-C | ||
c.setParents(b); | ||
// C-D | ||
d.setParents(c); | ||
// D-E | ||
e.setParents(d); | ||
// B-F | ||
f.setParents(b); | ||
// F-G | ||
g.setParents(f); | ||
// X has no parent | ||
x.setParents(); | ||
// X-Y | ||
y.setParents(x); | ||
// Y-Z | ||
z.setParents(y); | ||
|
||
List<SPLCommit> exampleCommits = Arrays.asList(a, b, c, d, e, f, g, x, y, z); | ||
NonEmptyList<SPLCommit> expectedOne = new NonEmptyList<>(Arrays.asList(a,b,c,d,e)); | ||
NonEmptyList<SPLCommit> expectedTwo = new NonEmptyList<>(Arrays.asList(x, y, z)); | ||
NonEmptyList<SPLCommit> expectedThree = new NonEmptyList<>(Arrays.asList(f, g)); | ||
|
||
LongestNonOverlappingSequences algorithm = new LongestNonOverlappingSequences(); | ||
List<NonEmptyList<SPLCommit>> result = algorithm.extract(exampleCommits); | ||
|
||
Assert.assertEquals(result.size(), 3); | ||
Assert.assertTrue(sequencesAreEqual(result.get(0), expectedOne)); | ||
Assert.assertTrue(sequencesAreEqual(result.get(1), expectedTwo)); | ||
Assert.assertTrue(sequencesAreEqual(result.get(2), expectedThree)); | ||
} | ||
|
||
@Test | ||
// This test caused a StackoverflowError for the previous implementation of LongestNonOverlappingSequences at | ||
// confirms that the Error is no longer thrown. | ||
public void stackOverflowPrevented() { | ||
int size = 10_000; | ||
Set<SPLCommit> commits = new HashSet<>(); | ||
SPLCommit previousCommit = new SPLCommit("0"); | ||
previousCommit.setParents(); | ||
commits.add(previousCommit); | ||
for (int i = 1; i < size; i++) { | ||
SPLCommit commit = new SPLCommit(String.valueOf(i)); | ||
commit.setParents(previousCommit); | ||
commits.add(commit); | ||
previousCommit = commit; | ||
} | ||
|
||
LongestNonOverlappingSequences algo = new LongestNonOverlappingSequences(); | ||
var result = algo.extract(commits); | ||
// Some sanity checks (i.e., is the sequence extracted correctly?) | ||
Assert.assertEquals(1, result.size()); | ||
Assert.assertEquals(result.get(0).size(), size); | ||
} | ||
|
||
private boolean sequencesAreEqual(final NonEmptyList<SPLCommit> a, final NonEmptyList<SPLCommit> b) { | ||
if (a.size() != b.size()) { | ||
return false; | ||
} | ||
for (int i = 0; i < a.size(); i++) { | ||
if (!a.get(i).id().equals(b.get(i).id())) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |