Dominik Fuchß 4 лет назад
Родитель
Сommit
86d5280a0c

+ 2 - 2
jplag.endtoend-testing/src/main/java/de/jplag/endtoend/model/ExpectedResult.java

@@ -7,6 +7,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
  * which can be found at https://github.com/jplag/JPlag/issues/548 Here this object is used for serialization and
  * which can be found at https://github.com/jplag/JPlag/issues/548 Here this object is used for serialization and
  * deserialization of the information from json to object or object to json.
  * deserialization of the information from json to object or object to json.
  */
  */
-public record ExpectedResult(@JsonProperty("minimal_similarity") float resultSimilarityMinimum,
-        @JsonProperty("maximum_similarity") float resultSimilarityMaximum, @JsonProperty("matched_token_number") int resultMatchedTokenNumber) {
+public record ExpectedResult(@JsonProperty("minimal_similarity") double resultSimilarityMinimum,
+        @JsonProperty("maximum_similarity") double resultSimilarityMaximum, @JsonProperty("matched_token_number") int resultMatchedTokenNumber) {
 }
 }

+ 12 - 7
jplag.endtoend-testing/src/test/java/de/jplag/endtoend/EndToEndSuiteTest.java

@@ -36,8 +36,9 @@ import de.jplag.options.JPlagOptions;
  * original class. The results are compared with the results from previous tests and changes are detected.
  * original class. The results are compared with the results from previous tests and changes are detected.
  */
  */
 public class EndToEndSuiteTest {
 public class EndToEndSuiteTest {
+    private static final double EPSILON = 1E-5;
     // Language -> directory names and Paths
     // Language -> directory names and Paths
-    private Map<String, Map<String, Path>> LanguageToTestCaseMapper;
+    private Map<String, Map<String, Path>> languageToTestCaseMapper;
 
 
     private List<Options> options;
     private List<Options> options;
 
 
@@ -47,7 +48,7 @@ public class EndToEndSuiteTest {
 
 
     public EndToEndSuiteTest() throws IOException {
     public EndToEndSuiteTest() throws IOException {
         // Loading the test resources
         // Loading the test resources
-        LanguageToTestCaseMapper = TestSuiteHelper.getAllLanguageResources();
+        languageToTestCaseMapper = TestSuiteHelper.getAllLanguageResources();
         // creating the temporary lists for the test run
         // creating the temporary lists for the test run
         validationErrors = new ArrayList<>();
         validationErrors = new ArrayList<>();
         temporaryResultList = new HashMap<>();
         temporaryResultList = new HashMap<>();
@@ -82,7 +83,7 @@ public class EndToEndSuiteTest {
      */
      */
     @TestFactory
     @TestFactory
     Collection<DynamicTest> dynamicOverAllTest() throws IOException {
     Collection<DynamicTest> dynamicOverAllTest() throws IOException {
-        for (Entry<String, Map<String, Path>> languageMap : LanguageToTestCaseMapper.entrySet()) {
+        for (Entry<String, Map<String, Path>> languageMap : languageToTestCaseMapper.entrySet()) {
             String currentLanguageIdentifier = languageMap.getKey();
             String currentLanguageIdentifier = languageMap.getKey();
             for (Entry<String, Path> languagePaths : languageMap.getValue().entrySet()) {
             for (Entry<String, Path> languagePaths : languageMap.getValue().entrySet()) {
                 String[] fileNames = FileHelper.loadAllTestFileNames(languagePaths.getValue());
                 String[] fileNames = FileHelper.loadAllTestFileNames(languagePaths.getValue());
@@ -154,20 +155,20 @@ public class EndToEndSuiteTest {
             String identifier = TestSuiteHelper.getTestIdentifier(jPlagComparison);
             String identifier = TestSuiteHelper.getTestIdentifier(jPlagComparison);
             addToTemporaryResultMap(directoryName, options, jPlagComparison, languageIdentifier);
             addToTemporaryResultMap(directoryName, options, jPlagComparison, languageIdentifier);
 
 
-            assertNotNull(currentResultDescription, "No stored result could be found for the current LanguageOption! " + options.toString());
+            assertNotNull(currentResultDescription, "No stored result could be found for the current LanguageOption! " + options);
 
 
             ExpectedResult result = currentResultDescription.getExpectedResultByIdentifier(TestSuiteHelper.getTestIdentifier(jPlagComparison));
             ExpectedResult result = currentResultDescription.getExpectedResultByIdentifier(TestSuiteHelper.getTestIdentifier(jPlagComparison));
             assertNotNull(result, "No stored result could be found for the identifier! " + identifier);
             assertNotNull(result, "No stored result could be found for the identifier! " + identifier);
 
 
-            if (Float.compare(result.resultSimilarityMinimum(), jPlagComparison.minimalSimilarity()) != 0) {
+            if (areDoublesDifferent(result.resultSimilarityMinimum(), jPlagComparison.minimalSimilarity())) {
                 addToValidationErrors("minimalSimilarity", String.valueOf(result.resultSimilarityMinimum()),
                 addToValidationErrors("minimalSimilarity", String.valueOf(result.resultSimilarityMinimum()),
                         String.valueOf(jPlagComparison.minimalSimilarity()));
                         String.valueOf(jPlagComparison.minimalSimilarity()));
             }
             }
-            if (Float.compare(result.resultSimilarityMaximum(), jPlagComparison.maximalSimilarity()) != 0) {
+            if (areDoublesDifferent(result.resultSimilarityMaximum(), jPlagComparison.maximalSimilarity())) {
                 addToValidationErrors("maximalSimilarity", String.valueOf(result.resultSimilarityMaximum()),
                 addToValidationErrors("maximalSimilarity", String.valueOf(result.resultSimilarityMaximum()),
                         String.valueOf(jPlagComparison.maximalSimilarity()));
                         String.valueOf(jPlagComparison.maximalSimilarity()));
             }
             }
-            if (Integer.compare(result.resultMatchedTokenNumber(), jPlagComparison.getNumberOfMatchedTokens()) != 0) {
+            if (result.resultMatchedTokenNumber() != jPlagComparison.getNumberOfMatchedTokens()) {
                 addToValidationErrors("numberOfMatchedTokens", String.valueOf(result.resultMatchedTokenNumber()),
                 addToValidationErrors("numberOfMatchedTokens", String.valueOf(result.resultMatchedTokenNumber()),
                         String.valueOf(jPlagComparison.getNumberOfMatchedTokens()));
                         String.valueOf(jPlagComparison.getNumberOfMatchedTokens()));
             }
             }
@@ -176,6 +177,10 @@ public class EndToEndSuiteTest {
         }
         }
     }
     }
 
 
+    private boolean areDoublesDifferent(double d1, double d2) {
+        return Math.abs(d1 - d2) >= EPSILON;
+    }
+
     /**
     /**
      * Creates the display message for failed tests
      * Creates the display message for failed tests
      * @param valueName Name of the failed test object
      * @param valueName Name of the failed test object