Commit 71c67b2e authored by Faezeh KHORRAM's avatar Faezeh KHORRAM 💬
Browse files

debug evaluator

parent 3f4220d8
...@@ -32,14 +32,10 @@ public class Evaluation4MODELSPaper { ...@@ -32,14 +32,10 @@ public class Evaluation4MODELSPaper {
Resource testSuiteRes; Resource testSuiteRes;
Package tdlTestSuite; Package tdlTestSuite;
List<TestDescription> testCases = new ArrayList<>();
MutationScoreCalculator scoreCalculator; MutationScoreCalculator scoreCalculator;
int initialNumOfKilledMutants; double mutationScore ;
double initialMutationScore;
int numOfIteration;
int numNewTests;
Map<Integer, List<TestDescription>> iteration_ampTests = new HashMap<>();
public void selectTestsForEvaluation(IFile testSuiteFile) throws MutationRuntimeException { public void selectTestsForEvaluation(IFile testSuiteFile) throws MutationRuntimeException {
PathHelper.getInstance().setTestSuiteFile(testSuiteFile); PathHelper.getInstance().setTestSuiteFile(testSuiteFile);
...@@ -60,22 +56,14 @@ public class Evaluation4MODELSPaper { ...@@ -60,22 +56,14 @@ public class Evaluation4MODELSPaper {
throw (new MutationRuntimeException(message)); throw (new MutationRuntimeException(message));
} }
List<TestDescription> testCases = new ArrayList<>(); System.out.println("\nCalculating the mutation score of the input test suite");
testCases = tdlTestSuite.getPackagedElement().stream().filter(p -> p instanceof TestDescription). testCases = tdlTestSuite.getPackagedElement().stream().filter(p -> p instanceof TestDescription).
map(p -> (TestDescription) p).collect(Collectors.toList()); map(p -> (TestDescription) p).collect(Collectors.toList());
int index = -1; //running all tests on all mutants
double mutationScore = 0; testCases.forEach(t -> scoreCalculator.runTestCaseOnAllMutants(t));
scoreCalculator.calculateOverallMutationScore();
for (int i=0; i<testCases.size(); i++) { mutationScore = scoreCalculator.getOverallMutationScore();
scoreCalculator.runTestCaseOnAliveMutants(testCases.get(i));
scoreCalculator.calculateOverallMutationScore();
mutationScore = scoreCalculator.getOverallMutationScore();
if (mutationScore > 0.8) {
index = i;
break;
}
}
IFile weakTestsFile = null; IFile weakTestsFile = null;
//if the mutation score is less than 40%, it is not a good input for the experiment //if the mutation score is less than 40%, it is not a good input for the experiment
if (mutationScore < 0.4) { if (mutationScore < 0.4) {
...@@ -88,18 +76,56 @@ public class Evaluation4MODELSPaper { ...@@ -88,18 +76,56 @@ public class Evaluation4MODELSPaper {
weakTestsFile = testSuiteFile; weakTestsFile = testSuiteFile;
} }
else if (mutationScore > 0.8) { else if (mutationScore > 0.8) {
//remove the test cases from the index to the end makeTestSuiteWeaker();
for (int i=index; i<testCases.size(); i++) {
tdlTestSuite.getPackagedElement().remove(testCases.get(index));
}
weakTestsFile = saveSelectedTestCases(); weakTestsFile = saveSelectedTestCases();
} }
//send it to the amplifier //send it to the amplifier
TDLTestAmplifier testAmplifier = new TDLTestAmplifier(); TDLTestAmplifier testAmplifier = new TDLTestAmplifier();
testAmplifier.amplifyTestSuite(weakTestsFile); testAmplifier.amplifyTestSuite(weakTestsFile);
} }
private void makeTestSuiteWeaker() throws MutationRuntimeException {
int index = 0;
while (index <testCases.size() && !(mutationScore >= 0.4 && mutationScore <= 0.8)) {
TestDescription testCase = testCases.get(index);
List<String> mutantsKilledByTestCase = scoreCalculator.testCase_killedMutant.get(testCase);
int numOfMutantsNotKilledByOtherTests = mutantsKilledByTestCase.stream().filter(m -> mutantNotKilledByOtherTests(testCase, m)).toList().size();
if (numOfMutantsNotKilledByOtherTests == 0) {
//no change in the mutation score
tdlTestSuite.getPackagedElement().remove(testCase);
}
else if (numOfMutantsNotKilledByOtherTests > 0) {
int numOfKilledMutants = scoreCalculator.getNumOfKilledMutants() - numOfMutantsNotKilledByOtherTests;
double newScore = (double) (numOfKilledMutants) / scoreCalculator.getNumOfMutants();
//remove the test case if the new score is not lower than 40%
if (newScore >= 0.4) {
tdlTestSuite.getPackagedElement().remove(testCase);
scoreCalculator.setNumOfKilledMutants(numOfKilledMutants);
scoreCalculator.calculateOverallMutationScore();
mutationScore = scoreCalculator.getOverallMutationScore();
}
}
index++;
}
if (mutationScore < 0.4 || mutationScore > 0.8) {
String message = "Amplification Stopped: It is not possible to make test suite weaker with the current threshold (between 40% and 80%)";
System.out.println(message);
throw (new MutationRuntimeException(message));
}
}
private boolean mutantNotKilledByOtherTests(TestDescription testCase, String mutant) {
List<TestDescription> otherTests = testCases.stream().
filter(t -> !EcoreUtil.equals(t, testCase)).toList();
for (TestDescription otherTest : otherTests) {
if (scoreCalculator.testCase_killedMutant.get(otherTest).contains(mutant)) {
return false;
}
}
return true;
}
private IFile saveSelectedTestCases() { private IFile saveSelectedTestCases() {
String sourcePath = testSuiteRes.getURI().toString(); String sourcePath = testSuiteRes.getURI().toString();
String extension = ".tdlan2"; String extension = ".tdlan2";
......
...@@ -44,7 +44,7 @@ public class CommandHandler implements IHandler { ...@@ -44,7 +44,7 @@ public class CommandHandler implements IHandler {
} }
}; };
Job job = Job.create("Test Amplifier", run); Job job = Job.create("Test Amplification Evaluator", run);
job.schedule(); job.schedule();
} }
} }
......
...@@ -104,8 +104,7 @@ public class MutationScoreCalculator { ...@@ -104,8 +104,7 @@ public class MutationScoreCalculator {
return mutationScore; return mutationScore;
} }
@SuppressWarnings("unused") public void runTestCaseOnAllMutants(TestDescription testCase) {
private void runTestCaseOnAllMutants(TestDescription testCase) {
//using default values for timeout from pitest tool //using default values for timeout from pitest tool
//for timeoutConstant, it is calculated based on the waiting times used in the event manager: //for timeoutConstant, it is calculated based on the waiting times used in the event manager:
//at the first of configuration and for each assertion 5000 waiting time //at the first of configuration and for each assertion 5000 waiting time
...@@ -324,6 +323,10 @@ public class MutationScoreCalculator { ...@@ -324,6 +323,10 @@ public class MutationScoreCalculator {
return numOfMutants; return numOfMutants;
} }
public void setNumOfKilledMutants(int numOfKilledMutants) {
this.numOfKilledMutants = numOfKilledMutants;
}
public int getNumOfKilledMutants() { public int getNumOfKilledMutants() {
return numOfKilledMutants; return numOfKilledMutants;
} }
......
Supports Markdown
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