-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attributes & ignore Re-Organize Tests Fixed poms
- Loading branch information
Showing
152 changed files
with
334,466 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.ardoco.core</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>${revision}</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>tests-base</artifactId> | ||
<packaging>jar</packaging> | ||
<description>Base classes for tests. It also includes the benchmark data from https://github.com/ArDoCo/Benchmark</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.tngtech.archunit</groupId> | ||
<artifactId>archunit-junit5</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.ardoco</groupId> | ||
<artifactId>metrics</artifactId> | ||
<version>0.1.1</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.ardoco.core</groupId> | ||
<artifactId>common</artifactId> | ||
<version>${revision}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.ardoco.core</groupId> | ||
<artifactId>pipeline-core</artifactId> | ||
<version>${revision}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.reflections</groupId> | ||
<artifactId>reflections</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
129 changes: 129 additions & 0 deletions
129
tests-base/src/main/java/edu/kit/kastel/mcse/ardoco/core/tests/TestUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* Licensed under MIT 2021-2024. */ | ||
package edu.kit.kastel.mcse.ardoco.core.tests; | ||
|
||
import java.util.Locale; | ||
import java.util.Set; | ||
|
||
import org.eclipse.collections.api.collection.ImmutableCollection; | ||
import org.slf4j.Logger; | ||
|
||
import edu.kit.kastel.mcse.ardoco.core.api.output.ArDoCoResult; | ||
import edu.kit.kastel.mcse.ardoco.core.tests.eval.results.EvaluationResults; | ||
import edu.kit.kastel.mcse.ardoco.core.tests.eval.results.ExpectedResults; | ||
import edu.kit.kastel.mcse.ardoco.metrics.ClassificationMetricsCalculator; | ||
|
||
/** | ||
* This utility class provides methods for running the tests, especially regarding the evaluations. | ||
*/ | ||
public class TestUtil { | ||
|
||
private TestUtil() { | ||
throw new IllegalAccessError("This constructor should not be called!"); | ||
} | ||
|
||
/** | ||
* compares the tlr results with the expected results and creates a new {@link EvaluationResults}. | ||
* | ||
* @param arDoCoResult the ArDoCoResult | ||
* @param results Collection representing the results | ||
* @param goldStandard Collection representing the gold standard | ||
* @return the result of the comparison | ||
*/ | ||
public static <T> EvaluationResults<T> compareTLR(ArDoCoResult arDoCoResult, ImmutableCollection<T> results, ImmutableCollection<T> goldStandard) { | ||
|
||
Set<T> distinctTraceLinks = new java.util.LinkedHashSet<>(results.castToCollection()); | ||
Set<T> distinctGoldStandard = new java.util.LinkedHashSet<>(goldStandard.castToCollection()); | ||
|
||
int sentences = arDoCoResult.getText().getSentences().size(); | ||
int modelElements = 0; | ||
for (var model : arDoCoResult.getModelIds()) { | ||
modelElements += arDoCoResult.getModelState(model).getInstances().size(); | ||
} | ||
|
||
int confusionMatrixSum = sentences * modelElements; | ||
|
||
var calculator = ClassificationMetricsCalculator.getInstance(); | ||
|
||
var classification = calculator.calculateMetrics(distinctTraceLinks, distinctGoldStandard, confusionMatrixSum); | ||
return new EvaluationResults<>(classification); | ||
} | ||
|
||
/** | ||
* compares the inconsistencies results with the expected results and creates a new {@link EvaluationResults}. | ||
* | ||
* @param arDoCoResult the ArDoCoResult | ||
* @param results Collection representing the results | ||
* @param goldStandard Collection representing the gold standard | ||
* @return the result of the comparison | ||
*/ | ||
public static <T> EvaluationResults<T> compareInconsistencies(ArDoCoResult arDoCoResult, ImmutableCollection<T> results, | ||
ImmutableCollection<T> goldStandard) { | ||
|
||
Set<T> distinctTraceLinks = new java.util.LinkedHashSet<>(results.castToCollection()); | ||
Set<T> distinctGoldStandard = new java.util.LinkedHashSet<>(goldStandard.castToCollection()); | ||
|
||
int confusionMatrixSum = arDoCoResult.getText().getSentences().size(); | ||
|
||
var calculator = ClassificationMetricsCalculator.getInstance(); | ||
var classification = calculator.calculateMetrics(distinctTraceLinks, distinctGoldStandard, confusionMatrixSum); | ||
return new EvaluationResults<>(classification); | ||
} | ||
|
||
/** | ||
* Log the provided {@link EvaluationResults} using the provided logger and name. The log put out the result string provided by the | ||
* {@link EvaluationResults}. | ||
* | ||
* @param logger Logger to use | ||
* @param name Name to show in the output | ||
* @param results the results | ||
*/ | ||
public static void logResults(Logger logger, String name, EvaluationResults<?> results) { | ||
if (logger.isInfoEnabled()) | ||
logger.info(createResultLogString(name, results)); | ||
} | ||
|
||
/** | ||
* Creates a string from the given results that can be used, e.g., for logging. Extracts the name as well as precision, recall and F1-score and displays | ||
* them line by line. | ||
* | ||
* @param name the name that should be displayed | ||
* @param results the results | ||
* @return a String containing the name and the results (precision, recall, F1) line by line | ||
*/ | ||
public static String createResultLogString(String name, EvaluationResults<?> results) { | ||
return String.format(Locale.ENGLISH, "%n%s:%n%s", name, results); | ||
} | ||
|
||
public static void logExtendedResultsAsRow(Logger logger, String headerVal, String headerKey, EvaluationResults<?> results) { | ||
var txt = String.format("%n%s", results.toRow(headerVal, headerKey)); | ||
logger.info(txt); | ||
} | ||
|
||
/** | ||
* Log the provided {@link EvaluationResults} using the provided logger and name. Additionally, logs TP, FP, TN and FN used to calculate the metrics. | ||
* | ||
* @param logger Logger to use | ||
* @param name Name to show in the output | ||
* @param results the results | ||
*/ | ||
public static void logExplicitResults(Logger logger, String name, EvaluationResults<?> results) { | ||
var tp = results.truePositives().size(); | ||
var fp = results.falsePositives().size(); | ||
var fn = results.falseNegatives().size(); | ||
var precisionDenominator = tp + fp; | ||
var recallDenominator = tp + fn; | ||
var logString = String.format(Locale.ENGLISH, "%n%s:%n\tPrecision:%7d/%d = %.3f%n\tRecall:%10d/%d = %.3f", name, tp, precisionDenominator, results | ||
.precision(), tp, recallDenominator, results.recall()); | ||
logger.info(logString); | ||
} | ||
|
||
public static void logExtendedResultsWithExpected(Logger logger, Object testClass, String name, EvaluationResults<?> results, | ||
ExpectedResults expectedResults) { | ||
var infoString = String.format(Locale.ENGLISH, """ | ||
%s (%s): | ||
%s""", name, testClass.getClass().getSimpleName(), results.getExtendedResultStringWithExpected(expectedResults)); | ||
logger.info(infoString); | ||
} | ||
|
||
} |
Oops, something went wrong.