Commit 4589c6b3 authored by Chen Wenwen's avatar Chen Wenwen
Browse files

filter test cases

parent f990ab39
......@@ -30,7 +30,6 @@ import static org.fortiss.af3.testing.utils.TestingModelElementFactory.createTes
import static org.fortiss.af3.testing.utils.TestingModelElementFactory.setExpectedValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;
......@@ -65,7 +64,7 @@ import org.fortiss.af3.tools.base.UnknownLanguageFragmentException;
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 999ED06BF79C4B3E06E700993F95B574
* @ConQAT.Rating YELLOW Hash: 3A8B391AE4F56AB2FA4C9F3669471A3C
*/
public class ModelCheckingTestSuiteGenerator implements ITestSuiteGenerator {
......@@ -98,6 +97,7 @@ public class ModelCheckingTestSuiteGenerator implements ITestSuiteGenerator {
LinkedHashMap<State, ModelCheckingAnalysisResult> results;
try {
results = analyzer.performAnalysis(component).get(timeout);
} catch(TimeoutException e) {
throw new TestSuiteGenerationException("Time out!", e);
} catch(UnknownLanguageFragmentException e) {
......@@ -109,11 +109,10 @@ public class ModelCheckingTestSuiteGenerator implements ITestSuiteGenerator {
ArrayList<TestCase> testcasesVector = new ArrayList<TestCase>();
ArrayList<ArrayList<ExecutionStatistic>> statisticsVector =
new ArrayList<ArrayList<ExecutionStatistic>>();
int lastIdx = -1;
for(ModelCheckingAnalysisResult result : results.values()) {
ArrayList<ExecutionStatistic> statistics = new ArrayList<ExecutionStatistic>();
StatisticListenerManager statisticListenerManager = new StatisticListenerManager();
TestCase testcase = createTestCase(testsuite);
......@@ -141,33 +140,49 @@ public class ModelCheckingTestSuiteGenerator implements ITestSuiteGenerator {
} catch(TestCaseSimulatorException e) {
throw new TestSuiteGenerationException("Simulator error!", e);
}
int curIdx = 0;
for(StatisticListener statisticListener : statisticListenerManager
.getAllListeners()) {
statistics.add(statisticListener.getStatistic());
if(lastIdx < curIdx) {
statisticsVector.add(curIdx, new ArrayList<ExecutionStatistic>());
lastIdx++;
}
statisticsVector.get(curIdx++).add(statisticListener.getStatistic());
}
statisticsVector.add(statistics);
testcasesVector.add(testcase);
}
testsuite.getTestCasesList().clear();
int[] bestTestCasesIndex = findBestVectorList(toBooleanMatrix(statisticsVector));
Map<State, Integer> newStatesCounterMap = new HashMap<State, Integer>();
Map<TransitionSegment, Integer> newTransitionsCounterMap =
new HashMap<TransitionSegment, Integer>();
for(int index : bestTestCasesIndex) {
TestCase goodTestCase = testcasesVector.get(index);
testsuite.getTestCasesList().add(goodTestCase);
computingNewStateCount(statisticsVector.get(index), newStatesCounterMap);
computingNewTransitionCount(statisticsVector.get(index), newTransitionsCounterMap);
ArrayList<int[]> bestTestCasesIndexList =
findBestVectorList(toBooleanMatrix(statisticsVector, analyzer.toString()));
ArrayList<Map<State, Integer>> newStatesCounterMapList =
new ArrayList<Map<State, Integer>>();
ArrayList<Map<TransitionSegment, Integer>> newTransitionsCounterMapList =
new ArrayList<Map<TransitionSegment, Integer>>();
int listIndex = 0;
for(int[] bestTestCasesIndex : bestTestCasesIndexList) {
ArrayList<ExecutionStatistic> newStatisticsVector =
new ArrayList<ExecutionStatistic>();
for(int goodindex : bestTestCasesIndex) {
TestCase goodTestCase = testcasesVector.get(goodindex);
testsuite.getTestCasesList().add(goodTestCase);
newStatisticsVector.add(statisticsVector.get(listIndex).get(goodindex));
}
newStatesCounterMapList.add(computingNewStateCount(newStatisticsVector));
newTransitionsCounterMapList.add(computingNewTransitionCount(newStatisticsVector));
listIndex++;
}
testsuite.getSpecificationsList().add(
createNewStateAutomatonExecutionStatistic(component, newStatesCounterMap,
newTransitionsCounterMap));
for(int i = 0; i < newStatesCounterMapList.size(); i++)
testsuite
.getSpecificationsList()
.add(createNewStateAutomatonExecutionStatistic(component,
newStatesCounterMapList.get(i), newTransitionsCounterMapList.get(i)));
} finally {
monitor.done();
......@@ -175,5 +190,4 @@ public class ModelCheckingTestSuiteGenerator implements ITestSuiteGenerator {
return testsuite;
}
}
......@@ -19,6 +19,7 @@ package org.fortiss.af3.testing.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.fortiss.af3.state.model.State;
......@@ -33,7 +34,7 @@ import org.fortiss.af3.testing.model.statistic.TransitionIntTupel;
* @author wenwenchen
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
* @ConQAT.Rating YELLOW Hash: 95A3FCEA5452D71EB6CC054543B3FB9F
*/
public class StatisticUtils {
......@@ -42,21 +43,22 @@ public class StatisticUtils {
*
* @param statistics
* a List of ExecutionStatistic
* @param updateTransitionsCounterMap
* Map<TransitionSegment, Integer> to update
* @return a new TransitionsCounterMap
*/
public static void computingNewTransitionCount(ArrayList<ExecutionStatistic> statistics,
Map<TransitionSegment, Integer> updateTransitionsCounterMap) {
public static Map<TransitionSegment, Integer> computingNewTransitionCount(
ArrayList<ExecutionStatistic> statistics) {
Map<TransitionSegment, Integer> newTransitionsCounterMap =
new HashMap<TransitionSegment, Integer>();
for(ExecutionStatistic stat : statistics) {
if(stat instanceof StateAutomatonExecutionStatistic) {
TransitionIntTupel[] visitedTransitionIntTupel =
((StateAutomatonExecutionStatistic)stat).getTransitionVisitCount();
boolean isNew = updateTransitionsCounterMap.isEmpty();
boolean isNew = newTransitionsCounterMap.isEmpty();
for(TransitionIntTupel tupel : visitedTransitionIntTupel) {
if(isNew) {
updateTransitionsCounterMap.put(tupel.getTransition(), tupel.getCount());
newTransitionsCounterMap.put(tupel.getTransition(), tupel.getCount());
} else {
for(Map.Entry<TransitionSegment, Integer> entry : updateTransitionsCounterMap
for(Map.Entry<TransitionSegment, Integer> entry : newTransitionsCounterMap
.entrySet()) {
if(entry.getKey().equals(tupel.getTransition())) {
entry.setValue(entry.getValue().intValue() + tupel.getCount());
......@@ -66,7 +68,7 @@ public class StatisticUtils {
}
}
}
return newTransitionsCounterMap;
}
/**
......@@ -74,21 +76,21 @@ public class StatisticUtils {
*
* @param statistics
* a List of ExecutionStatistic
* @param updateStatesCounterMap
* Map<State, Integer> to update
* @return a new StatesCounterMap
*/
public static void computingNewStateCount(ArrayList<ExecutionStatistic> statistics,
Map<State, Integer> updateStatesCounterMap) {
public static Map<State, Integer> computingNewStateCount(
ArrayList<ExecutionStatistic> statistics) {
Map<State, Integer> newStatesCounterMap = new HashMap<State, Integer>();
for(ExecutionStatistic stat : statistics) {
if(stat instanceof StateAutomatonExecutionStatistic) {
StateIntTupel[] visitedStateIntTupel =
((StateAutomatonExecutionStatistic)stat).getStatesVisitCount();
boolean isNew = updateStatesCounterMap.isEmpty();
boolean isNew = newStatesCounterMap.isEmpty();
for(StateIntTupel tupel : visitedStateIntTupel) {
if(isNew) {
updateStatesCounterMap.put(tupel.getState(), tupel.getCount());
newStatesCounterMap.put(tupel.getState(), tupel.getCount());
} else {
for(Map.Entry<State, Integer> entry : updateStatesCounterMap.entrySet()) {
for(Map.Entry<State, Integer> entry : newStatesCounterMap.entrySet()) {
if(entry.getKey().equals(tupel.getState())) {
entry.setValue(entry.getValue().intValue() + tupel.getCount());
}
......@@ -97,7 +99,7 @@ public class StatisticUtils {
}
}
}
return newStatesCounterMap;
}
/**
......@@ -107,47 +109,95 @@ public class StatisticUtils {
* a ArrayList of ArrayList of T
* @return a two dimensional boolean array
*/
public static <T> boolean[][] toBooleanMatrix(ArrayList<ArrayList<T>> listList) {
boolean[][] booleanMatrix = new boolean[listList.size()][];
int matrixIndex = 0;
public static <T> ArrayList<boolean[][]> toBooleanMatrix(ArrayList<ArrayList<T>> listList,
String determine) {
ArrayList<boolean[][]> newList = new ArrayList<boolean[][]>();
boolean isTransition = determine.contains("Transition");
for(ArrayList<T> list : listList) {
booleanMatrix[matrixIndex++] = toBooleanVector(list);
boolean[][] booleanMatrix = new boolean[list.size()][];
int matrixIndex = 0;
for(T element : list) {
if(element instanceof StateAutomatonExecutionStatistic) {
booleanMatrix[matrixIndex++] =
(isTransition
? createTransitionStatisticBooleanVector((StateAutomatonExecutionStatistic)element)
: createStateStatisticBooleanVector((StateAutomatonExecutionStatistic)element));
}
}
newList.add(booleanMatrix);
}
return booleanMatrix;
return newList;
}
/**
* return a boolean vector from StateAutomatonExecutionStatistic, if there is only a
* StateAutomatonExecutionStatistic in the list
* return a Statistic Boolean Vector according to State and Transition information, which show
* the passed Model
*
* @param list
* a ArrayList of T
* @return a boolean array if T is instance of StateAutomatonExecutionStatistic
* @param statistic
* a StateAutomatonExecutionStatistic
* @return a boolean array according to the statistic
*/
public static <T> boolean[] toBooleanVector(ArrayList<T> list) {
if(list.size() == 1) {
T element = list.get(0);
if(element instanceof StateAutomatonExecutionStatistic) {
return createStatisticBooleanVector((StateAutomatonExecutionStatistic)element);
public static boolean[] createStateTransitionStatisticBooleanVector(
StateAutomatonExecutionStatistic statistic) {
StateIntTupel[] statesVector = statistic.getStatesVisitCount();
int statesVectorLength = statesVector.length;
TransitionIntTupel[] transitionsVector = statistic.getTransitionVisitCount();
boolean[] statisticBooleanVector =
new boolean[statesVectorLength + transitionsVector.length];
for(int i = 0; i < statesVectorLength; i++) {
if(statesVector[i].getCount() > 0) {
statisticBooleanVector[i] = true;
} else {
statisticBooleanVector[i] = false;
}
}
for(int i = 0; i < transitionsVector.length; i++) {
if(transitionsVector[i].getCount() > 0) {
statisticBooleanVector[i + statesVectorLength] = true;
} else {
statisticBooleanVector[i + statesVectorLength] = false;
}
}
return null;
return statisticBooleanVector;
}
/**
* return a Statistic Boolean Vector, which show the passed Model
* return a Statistic Boolean Vector according to State Information, which show the passed Model
*
* @param statistic
* a StateAutomatonExecutionStatistic
* @return a boolean array according to the statistic
*/
public static boolean[]
createStatisticBooleanVector(StateAutomatonExecutionStatistic statistic) {
TransitionIntTupel[] transitionVector = statistic.getTransitionVisitCount();
boolean[] statisticBooleanVector = new boolean[transitionVector.length];
for(int i = 0; i < transitionVector.length; i++) {
if(transitionVector[i].getCount() > 0) {
public static boolean[] createStateStatisticBooleanVector(
StateAutomatonExecutionStatistic statistic) {
StateIntTupel[] statesVector = statistic.getStatesVisitCount();
int statesVectorLength = statesVector.length;
boolean[] statisticBooleanVector = new boolean[statesVectorLength];
for(int i = 0; i < statesVectorLength; i++) {
if(statesVector[i].getCount() > 0) {
statisticBooleanVector[i] = true;
} else {
statisticBooleanVector[i] = false;
}
}
return statisticBooleanVector;
}
/**
* return a Statistic Boolean Vector according to Transition Information, which show the passed
* Model
*
* @param statistic
* a StateAutomatonExecutionStatistic
* @return a boolean array according to the statistic
*/
public static boolean[] createTransitionStatisticBooleanVector(
StateAutomatonExecutionStatistic statistic) {
TransitionIntTupel[] transitionsVector = statistic.getTransitionVisitCount();
boolean[] statisticBooleanVector = new boolean[transitionsVector.length];
for(int i = 0; i < transitionsVector.length; i++) {
if(transitionsVector[i].getCount() > 0) {
statisticBooleanVector[i] = true;
} else {
statisticBooleanVector[i] = false;
......@@ -159,21 +209,24 @@ public class StatisticUtils {
/**
* return a list of best vectors
*
* @param matrix
* @param matrixList
* a two dimensional boolean array
* @return a integer array of index of the best vectors
*/
public static int[] findBestVectorList(boolean[][] matrix) {
ArrayList<Integer> result = new ArrayList<Integer>();
public static ArrayList<int[]> findBestVectorList(ArrayList<boolean[][]> matrixList) {
ArrayList<int[]> resultList = new ArrayList<int[]>();
for(boolean[][] matrix : matrixList) {
ArrayList<Integer> result = new ArrayList<Integer>();
int maxIndex = -1;
while((maxIndex = findBestVector(matrix)) != -1) {
result.add(maxIndex);
int maxIndex = -1;
while((maxIndex = findBestVector(matrix)) != -1) {
result.add(maxIndex);
matrix = reduceMatrix(matrix, maxIndex);
matrix = reduceMatrix(matrix, maxIndex);
}
resultList.add(toArray(result));
}
return toArray(result);
return resultList;
}
/**
......
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