Skip to content

Commit

Permalink
Added another test and 3 new samples
Browse files Browse the repository at this point in the history
  • Loading branch information
uuqjz committed Aug 14, 2023
1 parent 2672d27 commit 509bcc7
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 3 deletions.
52 changes: 49 additions & 3 deletions core/src/test/java/de/jplag/merging/MergingTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,18 +16,21 @@
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;
import de.jplag.strategy.ParallelComparisonStrategy;

/**
* 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;
Expand All @@ -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));
Expand Down Expand Up @@ -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<Token> tokenLeft = new ArrayList<>(comparison.firstSubmission().getTokenList());
List<Token> 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<Token> tokenLeft = new ArrayList<>(comparison.firstSubmission().getTokenList());
List<Token> 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() {
Expand Down
25 changes: 25 additions & 0 deletions core/src/test/resources/de/jplag/samples/merging/oneFile/a.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
15 changes: 15 additions & 0 deletions core/src/test/resources/de/jplag/samples/merging/twoFiles/b1.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
15 changes: 15 additions & 0 deletions core/src/test/resources/de/jplag/samples/merging/twoFiles/b2.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 509bcc7

Please sign in to comment.