Просмотр исходного кода

Close #166. Adds efficient volume testing in O(n+m) that verifies matching results with a derivation of .1 percent

Sebastian Hahner 5 лет назад
Родитель
Сommit
dd32583c16
2 измененных файлов с 24 добавлено и 70 удалено
  1. 24 14
      jplag/src/test/java/jplag/VolumeTest.java
  2. 0 56
      jplag/src/test/java/jplag/volume/Result.java

+ 24 - 14
jplag/src/test/java/jplag/volume/VolumeTest.java → jplag/src/test/java/jplag/VolumeTest.java

@@ -1,19 +1,18 @@
-package jplag.volume;
+package jplag;
 
-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.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 /**
  * These tests are not intended to be used automatically but rather manually prior to releases.
@@ -32,7 +31,8 @@ public class VolumeTest extends TestBase {
     }
 
     /**
-     * This test requires a folder "data" with submissions and a file named "matches_avg.csv" inside the volume folder
+     * This test requires a folder "data" with submissions and a file named "matches_avg.csv" inside the volume folder.
+     * Accepts a derivation of 0.1% in the matching percentage
      */
     @Test
     public void volumeComparisonTest() throws ExitException, IOException {
@@ -42,27 +42,37 @@ public class VolumeTest extends TestBase {
             return;
         }
 
-        JPlagResult result = runJPlagWithOptions("data",
+        var results = runJPlagWithOptions("data",
                 jPlagOptions -> jPlagOptions.setMaxNumberOfMatches(-1));
 
-        List<Result> csv = readCSVResults(String.format("%s/%s", this.getBasePath(), "matches_avg.csv"));
+        var csv = readCSVResults(String.format("%s/%s", this.getBasePath(), "matches_avg.csv"));
 
-        assertEquals(csv.size(), result.getAllComparisons().size());
+        assertEquals(csv.size(), results.getAllComparisons().size());
         System.out.println("Volume test size: " + csv.size());
-        // TODO SH: More individual tests
+
+        results.getAllComparisons().forEach(result -> {
+            var key = result.firstSubmission.name + result.secondSubmission.name;
+
+            assertTrue(csv.containsKey(key));
+            assertEquals(csv.getOrDefault(key, -1f), result.percent(), 0.1f);
+        });
+
     }
 
-    private List<Result> readCSVResults(String filePathAndName) throws IOException {
+    private Map<String, Float> readCSVResults(String filePathAndName) throws IOException {
         List<String> lines = Files.readAllLines(Path.of(filePathAndName));
+        var results = new HashMap<String, Float>();
 
-        return lines.stream().map(line -> {
+        lines.forEach(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());
+            results.put(entries[1] + entries[2], Float.parseFloat((entries[3])));
+        });
+
+        return results;
     }
 }

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

@@ -1,56 +0,0 @@
-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;
-    }
-}