public List<String> getVariableNames() { List<String> variables = new ArrayList<String>(); for(String suffix : getTimelineHeaderSuffixes()) { variables.add(variable.name() + suffix); } return variables; }
/** * Retrieve list of possible variables * * @return */ private List<String> getAllOutputVariableNames() { List<String> variableNames = new ArrayList<String>(); String[] essentials = new String[] { //TODO maybe add some more "TARGET_CLASS" , "criterion", RuntimeVariable.Coverage.toString(), //TODO: why is this fixed? //RuntimeVariable.BranchCoverage.toString(), RuntimeVariable.Total_Goals.toString(), RuntimeVariable.Covered_Goals.toString() }; variableNames.addAll(Arrays.asList(essentials)); /* cannot use what we received, as due to possible bugs/errors those might not be constant variableNames.addAll(outputVariables.keySet()); variableNames.addAll(variableFactories.keySet()); variableNames.addAll(sequenceOutputVariableFactories.keySet()); */ return variableNames; }
Integer totalBranches = getIntegerValue(map,Total_Branches); Integer coveredBranches = getIntegerValue(map,Covered_Branches); Integer totalGoals = getIntegerValue(map,Total_Goals); Integer coveredGoals = getIntegerValue(map,Covered_Goals); Integer totalMethods = getIntegerValue(map,Total_Methods); Integer coveredMethods = getIntegerValue(map,Covered_Methods); Double coverage = getDoubleValue(map,Coverage); Double branchCoverage = getDoubleValue(map,BranchCoverage);
/** * Write result to disk using selected backend * * @return true if the writing was successful */ public boolean writeStatisticsForAnalysis() { logger.info("Writing statistics"); if(backend == null) { LoggingUtils.getEvoLogger().info("Backend is null"); return false; } outputVariables.put(RuntimeVariable.Total_Time.name(), new OutputVariable<Object>(RuntimeVariable.Total_Time.name(), System.currentTimeMillis() - startTime)); TestSuiteChromosome individual = new TestSuiteChromosome(); Map<String,OutputVariable<?>> map = getOutputVariables(individual); if(map==null){ logger.error("Not going to write down statistics data, as some are missing"); return false; } boolean valid = RuntimeVariable.validateRuntimeVariables(map); if(!valid){ logger.error("Not going to write down statistics data, as some data is invalid"); return false; } else { backend.writeData(individual, map); return true; } }
if (!columnName.equals(RuntimeVariable.Coverage.name()) && (columnName.endsWith("Coverage") || columnName.endsWith("Score")) ) { data.coverageValues.put(columnName, Double.parseDouble(getValue(rows, columnName))); if (!columnName.equals(RuntimeVariable.CoverageBitString.name()) && columnName.endsWith("CoverageBitString") ) { String coverageColumn = columnName.replace("BitString", ""); data.totalNumberOfStatements = Integer.parseInt(getValue(rows,RuntimeVariable.Length.toString())); data.durationInSeconds = Integer.parseInt(getValue(rows,RuntimeVariable.Total_Time.toString())) / 1000; data.numberOfTests = Integer.parseInt(getValue(rows,RuntimeVariable.Size.toString()));
return false; outputVariables.put(RuntimeVariable.Total_Time.name(), new OutputVariable<Object>(RuntimeVariable.Total_Time.name(), System.currentTimeMillis() - startTime)); boolean valid = RuntimeVariable.validateRuntimeVariables(map); if(!valid){ logger.error("Not going to write down statistics data, as some data is invalid");
private static Integer getIntegerValue(Map<String,OutputVariable<?>> map, RuntimeVariable variable){ OutputVariable<?> out = map.get(variable.toString()); if( out != null){ return (Integer) out.getValue(); } else { return null; } }
/** * Create default factories */ private void initFactories() { variableFactories.put(RuntimeVariable.Length.name(), new ChromosomeLengthOutputVariableFactory()); variableFactories.put(RuntimeVariable.Size.name(), new ChromosomeSizeOutputVariableFactory()); variableFactories.put(RuntimeVariable.Coverage.name(), new ChromosomeCoverageOutputVariableFactory()); variableFactories.put(RuntimeVariable.Fitness.name(), new ChromosomeFitnessOutputVariableFactory()); }
private static Double getDoubleValue(Map<String,OutputVariable<?>> map, RuntimeVariable variable){ OutputVariable<?> out = map.get(variable.toString()); if( out != null){ return (Double) out.getValue(); } else { return null; } } };
buffer.append("</td>"); buffer.append("<td>"); if (data.containsKey(RuntimeVariable.Total_Time.name())) { long duration = (Long)data.get(RuntimeVariable.Total_Time.name()).getValue() / 1000L; buffer.append(String.format("%d:%02d:%02d", duration / 3600, (duration % 3600) / 60, (duration % 60))); } else buffer.append("</td>"); buffer.append("<td>"); Double coverage = (Double)getOutputVariableValue(data, RuntimeVariable.Coverage.name()); buffer.append((coverage != null) ? NumberFormat.getPercentInstance().format(coverage) : "UNKNOWN"); buffer.append("</td>");
protected OutputVariable getOutputVariable(RuntimeVariable rv){ if(!Properties.OUTPUT_VARIABLES.contains(rv.toString())){ throw new IllegalStateException("Properties.OUTPUT_VARIABLES needs to contain "+rv.toString()); } Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten(); Assert.assertNotNull(map); OutputVariable out = map.get(rv.toString()); return out; }
public OutputVariable<T> getVariable(TestSuiteChromosome chromosome) { return new OutputVariable<T>(variable.name(), getData(chromosome)); }
public void setOutputVariable(OutputVariable<?> variable) { /** * if the output variable is contained in sequenceOutputVariableFactories, * then it must be a DirectSequenceOutputVariableFactory, hence we set its * value so that it can be used to produce the next timeline variable. */ if (sequenceOutputVariableFactories.containsKey(variable.getName())) { if(variable.getValue() instanceof Integer) { DirectSequenceOutputVariableFactory<Integer> v = (DirectSequenceOutputVariableFactory<Integer>) sequenceOutputVariableFactories.get(variable.getName()); v.setValue((Integer) variable.getValue()); } else if(variable.getValue() instanceof Double) { DirectSequenceOutputVariableFactory<Double> v = (DirectSequenceOutputVariableFactory<Double>) sequenceOutputVariableFactories.get(variable.getName()); v.setValue((Double) variable.getValue()); } // v.setValue((Integer)variable.getValue()); } else outputVariables.put(variable.getName(), variable); }
buffer.append(suite.getAge()); buffer.append(" generations, "); buffer.append(getOutputVariableValue(data, RuntimeVariable.Statements_Executed.name())); buffer.append(" statements, "); buffer.append(suite.size()); buffer.append("<li>Covered " + getOutputVariableValue(data, RuntimeVariable.Covered_Branches.name()) + "/" + getOutputVariableValue(data, RuntimeVariable.Total_Branches.name()) + " branches, "); buffer.append("<li>Covered "+ getOutputVariableValue(data, RuntimeVariable.Covered_Methods.name()) + "/" + getOutputVariableValue(data, RuntimeVariable.Total_Methods.name()) + " methods, "); buffer.append("<li>Covered "+ getOutputVariableValue(data, RuntimeVariable.Covered_Goals.name()) + "/" + getOutputVariableValue(data, RuntimeVariable.Total_Goals.name()) + " total goals\n"); if(data.containsKey(RuntimeVariable.MutationScore.name())) buffer.append("<li>Mutation score: " + NumberFormat.getPercentInstance().format((Double)data.get(RuntimeVariable.MutationScore.name()).getValue()) + "\n");
Assert.assertNotNull(map); OutputVariable<Double> coverage = (OutputVariable<Double>)map.get(RuntimeVariable.Coverage.toString()); OutputVariable<Double> branchCoverage = (OutputVariable<Double>)map.get(RuntimeVariable.BranchCoverage.toString()); OutputVariable<Integer> totalGoals = (OutputVariable<Integer>)map.get(RuntimeVariable.Total_Goals.toString()); OutputVariable<Integer> coveredGoals = (OutputVariable<Integer>)map.get(RuntimeVariable.Covered_Goals.toString()); OutputVariable<Integer> coveredBranches =(OutputVariable<Integer>)map.get(RuntimeVariable.Covered_Branches.toString()); OutputVariable<Integer> coveredBranchlessMethods = (OutputVariable<Integer>)map.get(RuntimeVariable.Covered_Branchless_Methods.toString()); OutputVariable<Integer> coveredBranchesReal = (OutputVariable<Integer>)map.get(RuntimeVariable.Covered_Branches_Real.toString()); OutputVariable<Integer> coveredBranchesInstrumented = (OutputVariable<Integer>)map.get(RuntimeVariable.Covered_Branches_Instrumented.toString());
sequenceOutputVariableFactories.put(RuntimeVariable.CoverageTimeline.name(), new CoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.FitnessTimeline.name(), new FitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.SizeTimeline.name(), new SizeSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.LengthTimeline.name(), new LengthSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.TotalExceptionsTimeline.name(), new TotalExceptionsSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.IBranchGoalsTimeline.name(), new IBranchGoalsSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.BranchCoverageTimeline.name(), new BranchCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.OnlyBranchFitnessTimeline.name(), new OnlyBranchFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.OnlyBranchCoverageTimeline.name(), new OnlyBranchCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.CBranchFitnessTimeline.name(), new CBranchFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.CBranchCoverageTimeline.name(), new CBranchCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.MethodTraceFitnessTimeline.name(), new MethodTraceFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.MethodTraceCoverageTimeline.name(), new MethodTraceCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.MethodFitnessTimeline.name(), new MethodFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.MethodCoverageTimeline.name(), new MethodCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.MethodNoExceptionFitnessTimeline.name(), new MethodNoExceptionFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.MethodNoExceptionCoverageTimeline.name(), new MethodNoExceptionCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.RhoScoreTimeline.name(), new RhoFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.AmbiguityScoreTimeline.name(), new AmbiguityFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.LineFitnessTimeline.name(), new LineFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.LineCoverageTimeline.name(), new LineCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.OutputFitnessTimeline.name(), new OutputFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.OutputCoverageTimeline.name(), new OutputCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.InputFitnessTimeline.name(), new InputFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.InputCoverageTimeline.name(), new InputCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.ExceptionFitnessTimeline.name(), new ExceptionFitnessSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.ExceptionCoverageTimeline.name(), new ExceptionCoverageSequenceOutputVariableFactory()); sequenceOutputVariableFactories.put(RuntimeVariable.WeakMutationCoverageTimeline.name(), new WeakMutationCoverageSequenceOutputVariableFactory());
private void testExceptionFitness() { EvoSuite evosuite = new EvoSuite(); String targetClass = ImplicitExplicitException.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.CRITERION = new Criterion[]{Properties.Criterion.EXCEPTION}; Properties.OUTPUT_VARIABLES = ""+ RuntimeVariable.Explicit_MethodExceptions + "," + RuntimeVariable.Explicit_TypeExceptions + "," + RuntimeVariable.Implicit_MethodExceptions +"," + RuntimeVariable.Implicit_TypeExceptions; String[] command = new String[] { "-generateSuite", "-class", targetClass }; Object result = evosuite.parseCommandLine(command); GeneticAlgorithm<?> ga = getGAFromResult(result); TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual(); System.out.println("EvolvedTestSuite:\n" + best); double fitness = best.getFitness(); /* * there are 2 undeclared exceptions (both implicit and explicit), * and 3 declared: so fit = 1 / (1+5) */ Assert.assertEquals("Wrong fitness: ", 1d / 6d, fitness, 0.0000001); Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten(); Assert.assertNotNull(map); Assert.assertEquals(1 , map.get(RuntimeVariable.Explicit_MethodExceptions.toString()).getValue()); Assert.assertEquals(1 , map.get(RuntimeVariable.Explicit_TypeExceptions.toString()).getValue()); Assert.assertEquals(1 , map.get(RuntimeVariable.Implicit_MethodExceptions.toString()).getValue()); Assert.assertEquals(1 , map.get(RuntimeVariable.Implicit_TypeExceptions.toString()).getValue()); }
sb.append("<div id=\"post\">\n"); OutputVariable<?> ov_covered_lines = data.get(RuntimeVariable.Covered_Lines.name()); @SuppressWarnings("unchecked") Set<Integer> coveredLines = (ov_covered_lines != null) ? (Set<Integer>) ov_covered_lines.getValue() : new HashSet<Integer>();
String strVar1 = RuntimeVariable.CoverageTimeline.toString(); OutputVariable cov = getLastTimelineVariable(map, strVar1); Assert.assertNotNull(cov); Assert.assertEquals("Incorrect last timeline value for " + strVar1, 1.0, cov.getValue()); String strVar2 = RuntimeVariable.OnlyBranchCoverageTimeline.toString(); OutputVariable method = getLastTimelineVariable(map, strVar2); Assert.assertNotNull(method); Assert.assertEquals("Incorrect last timeline value for " + strVar2, 1.0, method.getValue()); String strVar3 = RuntimeVariable.MethodNoExceptionCoverageTimeline.toString(); OutputVariable methodNE = getLastTimelineVariable(map, strVar3); Assert.assertNotNull(methodNE); Assert.assertEquals("Incorrect last timeline value for " + strVar3, 1.0, methodNE.getValue()); String strVar4 = RuntimeVariable.OutputCoverageTimeline.toString(); OutputVariable output = getLastTimelineVariable(map, strVar4); Assert.assertNotNull(output); Assert.assertEquals("Incorrect last timeline value for " + strVar4, 1.0, output.getValue()); String strVar5 = RuntimeVariable.CBranchFitnessTimeline.toString(); OutputVariable cbranchF = getLastTimelineVariable(map, strVar5); Assert.assertNotNull(cbranchF); Assert.assertEquals("Incorrect last timeline value for " + strVar5, 0.0, cbranchF.getValue()); String strVar6 = RuntimeVariable.CBranchCoverageTimeline.toString(); OutputVariable cbranchC = getLastTimelineVariable(map, strVar6); Assert.assertNotNull(cbranchC);
assertTrue("Expected 32-34lines, but found: "+CsvJUnitData.getValue(rows, RuntimeVariable.Total_Goals.name()), CsvJUnitData.getValue(rows, RuntimeVariable.Total_Goals.name()).equals("32") || CsvJUnitData.getValue(rows, RuntimeVariable.Total_Goals.name()).equals("33") || CsvJUnitData.getValue(rows, RuntimeVariable.Total_Goals.name()).equals("34"));