![JAR search and dependency download from the Maven repository](/logo.png)
org.evosuite.statistics.SequenceOutputVariableFactory Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2010-2018 Gordon Fraser, Andrea Arcuri and EvoSuite
* contributors
*
* This file is part of EvoSuite.
*
* EvoSuite is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* EvoSuite is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with EvoSuite. If not, see .
*/
package org.evosuite.statistics;
import org.evosuite.Properties;
import org.evosuite.TimeController;
import org.evosuite.testsuite.TestSuiteChromosome;
import java.util.ArrayList;
import java.util.List;
/**
* Creates an output variable that represents a sequence of values extracted from
* a test suite
*
* @author gordon
*
* @param
*/
public abstract class SequenceOutputVariableFactory {
protected RuntimeVariable variable;
protected List timeStamps = new ArrayList();
protected List values = new ArrayList();
private long startTime = 0L;
public SequenceOutputVariableFactory(RuntimeVariable variable) {
this.variable = variable;
}
public void setStartTime(long time) {
this.startTime = time;
}
protected abstract T getValue(TestSuiteChromosome individual);
public void update(TestSuiteChromosome individual) {
timeStamps.add(System.currentTimeMillis() - startTime);
values.add(getValue(individual));
}
public List getVariableNames() {
List variables = new ArrayList();
for(String suffix : getTimelineHeaderSuffixes()) {
variables.add(variable.name() + suffix);
}
return variables;
}
public List> getOutputVariables() {
List> variables = new ArrayList>();
for(String variableName : getVariableNames()) {
OutputVariable variable = new OutputVariable(variableName, getTimeLineValue(variableName));
variables.add(variable);
}
return variables;
}
@SuppressWarnings("unchecked")
private T getTimeLineValue(String name) {
long interval = Properties.TIMELINE_INTERVAL;
int index = Integer.parseInt( (name.split("_T"))[1] );
long preferredTime = interval * index;
/*
* No data. Is it even possible? Maybe if population is too large,
* and budget was not enough to get even first generation
*/
if(timeStamps.isEmpty()){
return (T) Integer.valueOf(0); // FIXXME - what else?
}
for(int i=0; i 0 ){
double covDelta = values.get(i).doubleValue() - values.get(i-1).doubleValue();
double ratio = covDelta / timeDelta;
long diff = preferredTime - timeStamps.get(i-1);
Double cov = values.get(i-1).doubleValue() + (diff * ratio);
return (T)cov; // TODO...type
}
}
/*
* No time stamp was higher. This might happen if coverage is 100% and we stop search.
* So just return last value seen
*/
return values.get(values.size()-1);
}
private String[] getTimelineHeaderSuffixes(){
int numberOfIntervals = calculateNumberOfIntervals();
String[] suffixes = new String[numberOfIntervals];
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy