Clean up tests: add seed AffinityPropagation tests, Ignore JsonCliTest(no assertions)

parent 6def08a0
Pipeline #111058 passed with stages
in 16 minutes and 33 seconds
......@@ -8,10 +8,7 @@ import de.monticore.lang.monticar.generator.middleware.clustering.ClusteringInpu
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.apache.commons.math3.linear.RealMatrix;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
public class AffinityPropagationAlgorithm implements ClusteringAlgorithm {
......@@ -31,7 +28,13 @@ public class AffinityPropagationAlgorithm implements ClusteringAlgorithm {
RealMatrix mat = new Array2DRowRealMatrix(clusteringInput.getAdjacencyMatrix());
AffinityPropagation clustering = new AffinityPropagationParameters().fitNewModel(mat);
AffinityPropagation clustering;
if(args.length == 2 && args[0] == AffinityPropagationBuilder.AffinityPropagationParameters.SEED){
clustering = new AffinityPropagationParameters().setSeed(new Random((Long) args[1])).fitNewModel(mat);
}else{
clustering = new AffinityPropagationParameters().fitNewModel(mat);
}
final int[] labels = clustering.getLabels();
......
package de.monticore.lang.monticar.generator.middleware.clustering.algorithms;
import smile.clustering.DBSCAN;
public class AffinityPropagationBuilder {
private Long seed;
// parameter list, true if mandatory
public enum AffinityPropagationParameters {
SEED(false);
private Boolean mandatory;
AffinityPropagationParameters(Boolean mandatory) {
this.mandatory = mandatory;
}
public Boolean isMandatory() {
return this.mandatory;
}
}
public AffinityPropagationBuilder() {
}
public AffinityPropagationBuilder(long seed) {
this.seed = seed;
}
public void setSeed(long seed) {
this.seed = seed;
}
public AffinityPropagationAlgorithm build() {
AffinityPropagationAlgorithm affinityPropagationAlgorithm = new AffinityPropagationAlgorithm();
if(seed == null){
return affinityPropagationAlgorithm;
}else{
affinityPropagationAlgorithm.setArgs(new Object[]{AffinityPropagationParameters.SEED, seed});
return affinityPropagationAlgorithm;
}
}
}
......@@ -556,6 +556,10 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
DBSCANClusteringBuilder.DBSCANParameters.DBSCAN_RADIUS, 10.0
};
break;
case AFFINITY_CLUSTERER:
params= new Object[]{
AffinityPropagationBuilder.AffinityPropagationParameters.SEED, 104L
};
}
testCreateClusters(ClusteringAlgorithmFactory.getFromKind(kind), params, componentInstanceSymbol, modelName);
}
......@@ -824,7 +828,7 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
RealMatrix mat = new Array2DRowRealMatrix(adjMatrix);
AffinityPropagation clustering = new AffinityPropagationParameters().fitNewModel(mat);
AffinityPropagation clustering = new AffinityPropagationParameters().setSeed(new Random(104)).fitNewModel(mat);
final int[] labels = clustering.getLabels();
for (int label : labels) {
......@@ -853,7 +857,7 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
RealMatrix mat = new Array2DRowRealMatrix(adjMatrix);
AffinityPropagation clustering = new AffinityPropagationParameters().fitNewModel(mat);
AffinityPropagation clustering = new AffinityPropagationParameters().setSeed(new Random(104)).fitNewModel(mat);
final int[] labels = clustering.getLabels();
for (int label : labels) {
......@@ -883,7 +887,7 @@ public class AutomaticClusteringTest extends AbstractSymtabTest{
RealMatrix mat = new Array2DRowRealMatrix(adjMatrix);
AffinityPropagation clustering = new AffinityPropagationParameters().fitNewModel(mat);
AffinityPropagation clustering = new AffinityPropagationParameters().setSeed(new Random(104)).fitNewModel(mat);
final int[] labels = clustering.getLabels();
for (int label : labels) {
......
......@@ -4,6 +4,7 @@ import de.monticore.lang.monticar.generator.middleware.cli.DistributedTargetGene
import org.junit.Ignore;
import org.junit.Test;
@Ignore("Not a test, does not assert anything")
public class JsonCliTest {
@Test
......
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