Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Nov 29, 2024
1 parent c87dc3e commit 8ecc005
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 193 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static ImmutableList<ModelInstance> initCodeInstances(CodeModel codeMode
}

private static void fillPackages(Collection<? extends CodePackage> packages, List<ModelInstance> instances) {
for (var modelElement : packages) {
for (var modelElement : packages) {
String path = modelElement.getName();
CodeModule parent = modelElement.getParent();
while (parent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public static <A extends Entity, M extends Entity, B extends Entity> Optional<Tr
}

public static boolean isValidTransitiveTraceLink(TraceLink<?, ?> firstTraceLink, TraceLink<?, ?> secondTraceLink) {
var secondEndpointOfFirstTl = firstTraceLink.asPair().second().getId();
var firstEndpointOfSecondTl = secondTraceLink.asPair().first().getId();
var secondEndpointOfFirstTl = firstTraceLink.getSecondEndpoint().getId();
var firstEndpointOfSecondTl = secondTraceLink.getFirstEndpoint().getId();
return secondEndpointOfFirstTl.equals(firstEndpointOfSecondTl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@

import org.junit.jupiter.api.Test;

import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.ConfusablesHelper;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.UnicodeCharacter;

public class ConfusablesHelperTest {
public static final String example = """
public static final String EXAMPLE = """
# ! ǃ ⵑ !
""";
public static final List<UnicodeCharacter> homoglyphsExample = Stream.of("!", "ǃ", "ⵑ", "!").map(UnicodeCharacter::valueOf).toList();

@Test
void extractHomoglyphsFromLine() {
var homoglyphs = ConfusablesHelper.extractHomoglyphsFromLine(example);
var homoglyphs = ConfusablesHelper.extractHomoglyphsFromLine(EXAMPLE);
assertEquals(homoglyphsExample.size(), homoglyphs.size());
assertTrue(homoglyphs.containsAll(homoglyphsExample));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import org.junit.jupiter.api.Test;

import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.WordSimUtils;

class WordSimUtilsTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.ComparisonContext;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.UnicodeCharacterMatchFunctions;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.jarowinkler.JaroWinklerMeasure;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.jarowinkler.UnicodeJaroWinklerSimilarity;

class JaroWinklerMeasureTest {
private static final double delta = 0.01;
private static final double DELTA = 0.01;

/**
* These tests were extracted from the original {@link org.apache.commons.text.similarity.JaroWinklerSimilarity} implementation and should
Expand All @@ -24,30 +22,30 @@ void testSimilarityDirectly() {
assertThrows(IllegalArgumentException.class, () -> UnicodeJaroWinklerSimilarity.apply(s, s, UnicodeCharacterMatchFunctions.EQUAL));
assertThrows(IllegalArgumentException.class, () -> UnicodeJaroWinklerSimilarity.apply("foo", null, UnicodeCharacterMatchFunctions.EQUAL));
assertThrows(IllegalArgumentException.class, () -> UnicodeJaroWinklerSimilarity.apply(null, "foo", UnicodeCharacterMatchFunctions.EQUAL));
assertEquals(1.0, UnicodeJaroWinklerSimilarity.apply("", "", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(1.0, UnicodeJaroWinklerSimilarity.apply("foo", "foo", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.94, UnicodeJaroWinklerSimilarity.apply("foo", "foo ", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.91, UnicodeJaroWinklerSimilarity.apply("foo", "foo ", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.87, UnicodeJaroWinklerSimilarity.apply("foo", " foo ", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.51, UnicodeJaroWinklerSimilarity.apply("foo", " foo", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("", "a", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("aaapppp", "", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.93, UnicodeJaroWinklerSimilarity.apply("frog", "fog", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(1.0, UnicodeJaroWinklerSimilarity.apply("", "", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(1.0, UnicodeJaroWinklerSimilarity.apply("foo", "foo", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.94, UnicodeJaroWinklerSimilarity.apply("foo", "foo ", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.91, UnicodeJaroWinklerSimilarity.apply("foo", "foo ", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.87, UnicodeJaroWinklerSimilarity.apply("foo", " foo ", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.51, UnicodeJaroWinklerSimilarity.apply("foo", " foo", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("", "a", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("aaapppp", "", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.93, UnicodeJaroWinklerSimilarity.apply("frog", "fog", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("fly", "ant", UnicodeCharacterMatchFunctions.EQUAL));
assertEquals(0.44, UnicodeJaroWinklerSimilarity.apply("elephant", "hippo", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.44, UnicodeJaroWinklerSimilarity.apply("hippo", "elephant", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("hippo", "zzzzzzzz", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.88, UnicodeJaroWinklerSimilarity.apply("hello", "hallo", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.91, UnicodeJaroWinklerSimilarity.apply("ABC Corporation", "ABC Corp", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.95, UnicodeJaroWinklerSimilarity.apply("D N H Enterprises Inc", "D & H Enterprises, Inc.", UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.44, UnicodeJaroWinklerSimilarity.apply("elephant", "hippo", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.44, UnicodeJaroWinklerSimilarity.apply("hippo", "elephant", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.0, UnicodeJaroWinklerSimilarity.apply("hippo", "zzzzzzzz", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.88, UnicodeJaroWinklerSimilarity.apply("hello", "hallo", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.91, UnicodeJaroWinklerSimilarity.apply("ABC Corporation", "ABC Corp", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.95, UnicodeJaroWinklerSimilarity.apply("D N H Enterprises Inc", "D & H Enterprises, Inc.", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.94, UnicodeJaroWinklerSimilarity.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness",
UnicodeCharacterMatchFunctions.EQUAL), delta);
assertEquals(0.89, UnicodeJaroWinklerSimilarity.apply("PENNSYLVANIA", "PENNCISYLVNIA", UnicodeCharacterMatchFunctions.EQUAL), delta);
UnicodeCharacterMatchFunctions.EQUAL), DELTA);
assertEquals(0.89, UnicodeJaroWinklerSimilarity.apply("PENNSYLVANIA", "PENNCISYLVNIA", UnicodeCharacterMatchFunctions.EQUAL), DELTA);
}

@Test
void testHomoglyphSimilarity() {
var measure = new JaroWinklerMeasure();
assertEquals(1d, measure.getSimilarity(new ComparisonContext("ℜ𝘂ᖯʏ", "Ruby", UnicodeCharacterMatchFunctions.EQUAL_OR_HOMOGLYPH)), delta);
assertEquals(1d, measure.getSimilarity(new ComparisonContext("ℜ𝘂ᖯʏ", "Ruby", UnicodeCharacterMatchFunctions.EQUAL_OR_HOMOGLYPH)), DELTA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.ComparisonContext;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.UnicodeCharacterMatchFunctions;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.levenshtein.LevenshteinMeasure;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.levenshtein.UnicodeLevenshteinDistance;

class LevenshteinMeasureTest {
private static final double delta = 0.01;
private static final double DELTA = 0.01;

/**
* These tests were extracted from the original {@link org.apache.commons.text.similarity.LevenshteinDistance} implementation and should still hold true.
Expand All @@ -36,6 +34,6 @@ void testSimilarityDirectly() {
@Test
void testHomoglyphSimilarity() {
var measure = new LevenshteinMeasure();
assertEquals(1d, measure.getSimilarity(new ComparisonContext("ℜ𝘂ᖯʏ", "Ruby", UnicodeCharacterMatchFunctions.EQUAL_OR_HOMOGLYPH)), delta);
assertEquals(1d, measure.getSimilarity(new ComparisonContext("ℜ𝘂ᖯʏ", "Ruby", UnicodeCharacterMatchFunctions.EQUAL_OR_HOMOGLYPH)), DELTA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.junit.jupiter.api.Test;

import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.ComparisonContext;
import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.measures.ngram.NgramMeasure;

class NgramMeasureTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import org.junit.jupiter.api.Test;

import edu.kit.kastel.mcse.ardoco.core.common.similarity.wordsim.vector.VectorUtils;

class VectorUtilsTest {

record Example(float[] firstVec, float[] secondVec, double expectedCosineSimilarity) {
Expand Down Expand Up @@ -78,7 +76,7 @@ void testAdd() {
assertThrows(NullPointerException.class, () -> VectorUtils.add(new double[0], null));
assertThrows(IllegalArgumentException.class, () -> VectorUtils.add(new double[1], new double[2]));

double[] result = new double[] { 1.0, 2.0 };
double[] result = { 1.0, 2.0 };
VectorUtils.add(result, new double[] { 3.0, 4.0 });
assertArrayEquals(new double[] { 4.0, 6.0 }, result);
}
Expand All @@ -87,7 +85,7 @@ void testAdd() {
void testScale() {
assertThrows(NullPointerException.class, () -> VectorUtils.scale(null, 1.0));

double[] result = new double[] { 1.0, 2.0 };
double[] result = { 1.0, 2.0 };
VectorUtils.scale(result, 2.0);
assertArrayEquals(new double[] { 2.0, 4.0 }, result);
}
Expand Down

0 comments on commit 8ecc005

Please sign in to comment.