Commit af621db2 authored by Johannes Salentin's avatar Johannes Salentin
Browse files

Merge branch 'feature/DenseStructure' into develop

parents 187bbf92 6fbdbc7c
Pipeline #162999 passed with stages
in 1 minute and 21 seconds
package de.example.smells;
import de.example.model.ElementType;
import de.example.model.RelationshipType;
import java.util.List;
import java.util.Set;
import static de.example.smells.Constants.MAX_AVG_DEGREE;
......@@ -10,14 +14,32 @@ public class DenseStructure extends Detector {
super("Dense Structure");
}
// could use clustering coefficient
public List<EASmell> detect() {
overallDenseStructure();
for (ElementType element : model.getElements()) {
Set<ElementType> cluster = model.getCluster(element);
double e = 0;
for (RelationshipType relationship : model.getRelationships()) {
ElementType target = (ElementType) relationship.getTarget();
ElementType source = (ElementType) relationship.getSource();
if (cluster.contains(source) && cluster.contains(target)) {
e++;
}
}
double avgDegree = e / cluster.size();
if (avgDegree > MAX_AVG_DEGREE) {
addToSmells(new EASmell("Dense Structure", element, " with average degree of " + avgDegree));
}
}
return result;
}
private void overallDenseStructure() {
double v = model.getElements().size();
double e = model.getRelationships().size();
double avgDegree = e / (v/* * (v - 1)*/);
if (avgDegree > MAX_AVG_DEGREE) {
addToSmells(new EASmell("Dense Structure", null, " with average degree of " + avgDegree));
addToSmells(new EASmell("Overall Dense Structure", null, " with average degree of " + avgDegree));
}
return result;
}
}
......@@ -22,6 +22,6 @@ class TestDenseStructure {
ModelAdapter model = new ModelAdapter("SmellExample.xml", null);
Detector.setModel(model);
detector = new DenseStructure();
assertEquals(detector.detect().size(), 1);
assertEquals(detector.detect().size(), 3);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment