diff --git a/core/src/test/java/de/jplag/merging/MergingTest.java b/core/src/test/java/de/jplag/merging/MergingTest.java index 8737beb80..609dd24f3 100644 --- a/core/src/test/java/de/jplag/merging/MergingTest.java +++ b/core/src/test/java/de/jplag/merging/MergingTest.java @@ -1,5 +1,6 @@ package de.jplag.merging; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; @@ -15,9 +16,11 @@ import de.jplag.JPlagComparison; import de.jplag.JPlagResult; import de.jplag.Match; +import de.jplag.SharedTokenType; import de.jplag.SubmissionSet; import de.jplag.SubmissionSetBuilder; import de.jplag.TestBase; +import de.jplag.Token; import de.jplag.exceptions.ExitException; import de.jplag.options.JPlagOptions; import de.jplag.strategy.ComparisonStrategy; @@ -25,8 +28,9 @@ /** * This class extends on {@link TestBase} and performs several test on Match Merging, in order to check its - * functionality. Therefore it uses two java programs and feds them into the JPlag pipeline. Results are stored before- - * and after Match Merging and used for all tests. The two samples are from PROGpedia and under the CC BY 4.0 license. + * functionality. Therefore it uses java programs and feds them into the JPlag pipeline. Results are stored before- and + * after Match Merging and used for all tests. The samples named "original" and "plag" are from PROGpedia and under the + * CC BY 4.0 license. */ class MergingTest extends TestBase { private JPlagOptions options; @@ -37,7 +41,7 @@ class MergingTest extends TestBase { private ComparisonStrategy comparisonStrategy; private SubmissionSet submissionSet; private final int MERGE_BUFFER = 8; - private final int SEPERATING_THRESHOLD = 2; + private final int SEPERATING_THRESHOLD = 10; MergingTest() throws ExitException { options = getDefaultOptions("merging").withMergingParameters(new MergingParameters(true, MERGE_BUFFER, SEPERATING_THRESHOLD)); @@ -116,6 +120,48 @@ void testFewerToken() { } } + @Test + @DisplayName("Test if amount of FILE_END token stayed the same") + void testFileEnd() { + int amountFileEndBefore = 0; + for (JPlagComparison comparison : comparisonsBefore) { + List tokenLeft = new ArrayList<>(comparison.firstSubmission().getTokenList()); + List tokenRight = new ArrayList<>(comparison.secondSubmission().getTokenList()); + + for (Token token : tokenLeft) { + if (token.getType().equals(SharedTokenType.FILE_END)) { + amountFileEndBefore++; + } + } + + for (Token token : tokenRight) { + if (token.getType().equals(SharedTokenType.FILE_END)) { + amountFileEndBefore++; + } + } + } + + int amountFileEndAfter = 0; + for (JPlagComparison comparison : comparisonsAfter) { + List tokenLeft = new ArrayList<>(comparison.firstSubmission().getTokenList()); + List tokenRight = new ArrayList<>(comparison.secondSubmission().getTokenList()); + + for (Token token : tokenLeft) { + if (token.getType().equals(SharedTokenType.FILE_END)) { + amountFileEndAfter++; + } + } + + for (Token token : tokenRight) { + if (token.getType().equals(SharedTokenType.FILE_END)) { + amountFileEndAfter++; + } + } + } + + assertEquals(amountFileEndBefore, amountFileEndAfter); + } + @Test @DisplayName("Test if merged matches have counterparts in the original matches") void testCorrectMerges() { diff --git a/core/src/test/resources/de/jplag/samples/merging/oneFile/a.java b/core/src/test/resources/de/jplag/samples/merging/oneFile/a.java new file mode 100644 index 000000000..8b2e43880 --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/merging/oneFile/a.java @@ -0,0 +1,25 @@ +public class Minimal { + public static void main (String [] Argv) { + int a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + a = 1; + } +} \ No newline at end of file diff --git a/core/src/test/resources/de/jplag/samples/merging/twoFiles/b1.java b/core/src/test/resources/de/jplag/samples/merging/twoFiles/b1.java new file mode 100644 index 000000000..4ff3e8b50 --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/merging/twoFiles/b1.java @@ -0,0 +1,15 @@ +public class Minimal { + public static void main (String [] Argv) { + int b1 = 1; + b1 = 1; + b1 = 1; + b1 = 1; + b1 = 1; + b1 = 1; + b1 = 1; + b1 = 1; + b1 = 1; + b1 = 1; + b1 = 1; + } +} \ No newline at end of file diff --git a/core/src/test/resources/de/jplag/samples/merging/twoFiles/b2.java b/core/src/test/resources/de/jplag/samples/merging/twoFiles/b2.java new file mode 100644 index 000000000..7fc5f14bf --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/merging/twoFiles/b2.java @@ -0,0 +1,15 @@ +public class Minimal { + public static void main (String [] Argv) { + int b2 = 1; + b2 = 1; + b2 = 1; + b2 = 1; + b2 = 1; + b2 = 1; + b2 = 1; + b2 = 1; + b2 = 1; + b2 = 1; + b2 = 1; + } +} \ No newline at end of file