use of org.evosuite.coverage.ambiguity.AmbiguityCoverageSuiteFitness in project evosuite by EvoSuite.
the class CoverageCriteriaAnalyzer method analyzeCoverage.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void analyzeCoverage(TestSuiteChromosome testSuite, Properties.Criterion criterion, boolean recalculate) {
TestSuiteChromosome testSuiteCopy = testSuite.clone();
TestFitnessFactory factory = FitnessFunctions.getFitnessFactory(criterion);
if (recalculate) {
reinstrument(testSuiteCopy, criterion);
for (TestChromosome test : testSuiteCopy.getTestChromosomes()) {
test.getTestCase().clearCoveredGoals();
test.clearCachedResults();
// re-execute test cases and it will be able to find the covered goals
if (isMutationCriterion(criterion)) {
test.setChanged(true);
}
}
}
List<TestFitnessFunction> goals = factory.getCoverageGoals();
Collections.sort(goals);
StringBuffer buffer = new StringBuffer(goals.size());
int covered = 0;
for (TestFitnessFunction goal : goals) {
if (goal.isCoveredBy(testSuiteCopy)) {
logger.debug("Goal {} is covered", goal);
covered++;
buffer.append("1");
} else {
logger.debug("Goal {} is not covered", goal);
buffer.append("0");
if (Properties.PRINT_MISSED_GOALS)
LoggingUtils.getEvoLogger().info(" - Missed goal {}", goal.toString());
}
}
coverageBitString.put(criterion.name(), buffer);
ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.CoverageBitString, coverageBitString.size() == 0 ? "0" : coverageBitString.values().toString().replace("[", "").replace("]", "").replace(", ", ""));
RuntimeVariable bitStringVariable = getBitStringVariable(criterion);
if (bitStringVariable != null) {
String goalBitString = buffer.toString();
ClientServices.getInstance().getClientNode().trackOutputVariable(bitStringVariable, goalBitString);
}
if (goals.isEmpty()) {
if (criterion == Properties.Criterion.MUTATION || criterion == Properties.Criterion.STRONGMUTATION) {
ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.MutationScore, 1.0);
}
LoggingUtils.getEvoLogger().info("* Coverage of criterion " + criterion + ": 100% (no goals)");
ClientServices.getInstance().getClientNode().trackOutputVariable(getCoverageVariable(criterion), 1.0);
} else {
ClientServices.getInstance().getClientNode().trackOutputVariable(getCoverageVariable(criterion), (double) covered / (double) goals.size());
if (criterion == Properties.Criterion.MUTATION || criterion == Properties.Criterion.STRONGMUTATION) {
ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.MutationScore, (double) covered / (double) goals.size());
}
LoggingUtils.getEvoLogger().info("* Coverage of criterion " + criterion + ": " + NumberFormat.getPercentInstance().format((double) covered / (double) goals.size()));
LoggingUtils.getEvoLogger().info("* Total number of goals: " + goals.size());
LoggingUtils.getEvoLogger().info("* Number of covered goals: " + covered);
}
// FIXME it works, but needs a better way of handling this
if (criterion == Properties.Criterion.RHO) {
RhoCoverageSuiteFitness rho = new RhoCoverageSuiteFitness();
ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.RhoScore, Math.abs(0.5 - rho.getFitness(testSuite)));
} else if (criterion == Properties.Criterion.AMBIGUITY) {
AmbiguityCoverageSuiteFitness ag = new AmbiguityCoverageSuiteFitness();
ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.AmbiguityScore, ag.getFitness(testSuite));
}
}
Aggregations