Sebastian Hahner 5 лет назад
Родитель
Сommit
0ff53e4d2d

+ 6 - 3
jplag/src/test/java/jplag/TestBase.java

@@ -9,8 +9,12 @@ public abstract class TestBase {
 
     private static final String BASE_PATH = "src/test/resources/samples";
 
+    protected String getBasePath() {
+        return BASE_PATH;
+    }
+
     protected JPlagResult runJPlagWithExclusionFile(String testSampleName, String exclusionFileName) throws ExitException {
-        String blackList = String.format(BASE_PATH + "/%s/%s", testSampleName, exclusionFileName);
+        String blackList = String.format(getBasePath() + "/%s/%s", testSampleName, exclusionFileName);
         return runJPlagWithOptions(testSampleName, options -> options.setExclusionFileName(blackList));
     }
 
@@ -19,11 +23,10 @@ public abstract class TestBase {
     }
 
     protected JPlagResult runJPlagWithOptions(String testSampleName, Consumer<JPlagOptions> customization) throws ExitException {
-        JPlagOptions options = new JPlagOptions(String.format(BASE_PATH + "/%s", testSampleName), LanguageOption.JAVA_1_9);
+        JPlagOptions options = new JPlagOptions(String.format(getBasePath() + "/%s", testSampleName), LanguageOption.JAVA_1_9);
         options.setDebugParser(true);
         customization.accept(options);
         JPlag jplag = new JPlag(options);
         return jplag.run();
     }
-
 }

+ 56 - 0
jplag/src/test/java/jplag/volume/Result.java

@@ -0,0 +1,56 @@
+package jplag.volume;
+
+/**
+ * This class mocks the internal JPlag data structure and only provides the fields saved in CSV results.
+ */
+public class Result {
+
+    // TODO SH: This shall be a record class in Java 16+
+
+    private int number;
+    private String nameA;
+    private String nameB;
+    private float percent;
+
+    public Result(int number, String nameA, String nameB, float percent) {
+        this.number = number;
+        this.nameA = nameA;
+        this.nameB = nameB;
+        this.percent = percent;
+    }
+
+    public Result() {
+    }
+
+    public String getNameA() {
+        return nameA;
+    }
+
+    public void setNameA(String nameA) {
+        this.nameA = nameA;
+    }
+
+    public String getNameB() {
+        return nameB;
+    }
+
+    public void setNameB(String nameB) {
+        this.nameB = nameB;
+    }
+
+    public float getPercent() {
+        return percent;
+    }
+
+    public void setPercent(float percent) {
+        this.percent = percent;
+    }
+
+    public int getNumber() {
+        return number;
+    }
+
+    public void setNumber(int number) {
+        this.number = number;
+    }
+}

+ 68 - 0
jplag/src/test/java/jplag/volume/VolumeTest.java

@@ -0,0 +1,68 @@
+package jplag.volume;
+
+import jplag.ExitException;
+import jplag.JPlagResult;
+import jplag.TestBase;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * These tests are not intended to be used automatically but rather manually prior to releases.
+ * These tests shall be used with large data sets (e.g., 100+ submissions) in order to validate the core functionality.
+ */
+public class VolumeTest extends TestBase {
+
+    /**
+     * This path ensures that volume testing data is not in the git repository (with default configuration)
+     */
+    private static final String VOLUME_BASE_PATH = "../../volume";
+
+    @Override
+    protected String getBasePath() {
+        return VOLUME_BASE_PATH;
+    }
+
+    /**
+     * This test requires a folder "data" with submissions and a file named "matches_avg.csv" inside the volume folder
+     */
+    @Test
+    public void volumeComparisonTest() throws ExitException, IOException {
+
+        // Always succeed if not executed in an appropriate environment
+        if(!new File(this.getBasePath()).exists()) {
+            return;
+        }
+
+        JPlagResult result = runJPlagWithOptions("data",
+                jPlagOptions -> jPlagOptions.setMaxNumberOfMatches(-1));
+
+        List<Result> csv = readCSVResults(String.format("%s/%s", this.getBasePath(), "matches_avg.csv"));
+
+        assertEquals(csv.size(), result.getAllComparisons().size());
+        System.out.println("Volume test size: " + csv.size());
+        // TODO SH: More individual tests
+    }
+
+    private List<Result> readCSVResults(String filePathAndName) throws IOException {
+        List<String> lines = Files.readAllLines(Path.of(filePathAndName));
+
+        return lines.stream().map(line -> {
+            var entries = line.split(";");
+
+            if(entries.length != 4) {
+                throw new IllegalArgumentException(String.format("Illegal line: '%s'", line));
+            }
+
+            return new Result(Integer.parseInt(entries[0]), entries[1], entries[2], Float.parseFloat((entries[3])));
+        }).collect(Collectors.toList());
+    }
+}