use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class SimpleInputAmplDistributor method amplify.
private Map<Amplifier, Map<CtMethod<?>, List<CtMethod<?>>>> amplify(List<Amplifier> amplifiers, ArrayList<CtMethod<?>> testMethodsToBeAmplified, int iteration) {
Map<Amplifier, Map<CtMethod<?>, List<CtMethod<?>>>> amplifiedTestMethodPerAmplifierPerTestMethod = new HashMap<>();
for (Amplifier amplifier : amplifiers) {
amplifiedTestMethodPerAmplifierPerTestMethod.put(amplifier, new HashMap<>());
for (CtMethod<?> testMethod : testMethodsToBeAmplified) {
final List<CtMethod<?>> amplification = amplifier.amplify(testMethod, 0).collect(Collectors.toList());
Collections.shuffle(amplification, RandomHelper.getRandom());
amplifiedTestMethodPerAmplifierPerTestMethod.get(amplifier).put(testMethod, amplification);
}
}
return amplifiedTestMethodPerAmplifierPerTestMethod;
}
use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class CharacterLiteralAmplifierTest method testAmplify.
@Test
public void testAmplify() {
final String nameMethod = "methodCharacter";
amplifier.reset(literalMutationClass);
CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
RandomHelper.setSeedRandom(42L);
Amplifier mutator = new CharLiteralAmplifier();
mutator.reset(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
assertEquals(6, mutantMethods.size());
}
use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class LiteralAmplifiersTest method test.
@Test
public void test() throws Exception {
/*
This test the application of multiple amplifier, multiple time
The multiple applications of amplifiers should result with non-redundant amplified test
Here, we test that amplifiers marks amplified nodes and do not amplify them again
This avoid redundant transformation,
and thus improve the global performance in term of memory and execution time of DSpot
*/
final String nameMethod = "testInt";
CtClass<?> literalMutationClass = launcher.getFactory().Class().get("fr.inria.ampl.ToBeAmplifiedLiteralTest");
RandomHelper.setSeedRandom(42L);
Amplifier stringLiteralAmplifier = new StringLiteralAmplifier();
stringLiteralAmplifier.reset(literalMutationClass);
Amplifier numberLiteralAmplifier = new NumberLiteralAmplifier();
numberLiteralAmplifier.reset(literalMutationClass);
final CtMethod method = literalMutationClass.getMethodsByName(nameMethod).get(0);
// 1rst application of both amplifiers
List<CtMethod<?>> amplifiedStringMethods = stringLiteralAmplifier.amplify(method, 0).collect(Collectors.toList());
List<CtMethod<?>> amplifiedNumberMethods = numberLiteralAmplifier.amplify(method, 0).collect(Collectors.toList());
List<CtMethod<?>> amplifiedMethods = new ArrayList<>();
amplifiedMethods.addAll(amplifiedStringMethods);
amplifiedMethods.addAll(amplifiedNumberMethods);
assertEquals(47, amplifiedMethods.size());
// 2nd application of both amplifiers:
amplifiedStringMethods = amplifiedMethods.stream().flatMap(testMethod -> stringLiteralAmplifier.amplify(testMethod, 0)).collect(Collectors.toList());
amplifiedNumberMethods = amplifiedMethods.stream().flatMap(testMethod -> numberLiteralAmplifier.amplify(testMethod, 0)).collect(Collectors.toList());
amplifiedMethods.clear();
amplifiedMethods.addAll(amplifiedStringMethods);
amplifiedMethods.addAll(amplifiedNumberMethods);
// here, we have less amplified test method than before from more than 1630 to 1304
// TODO
assertEquals(1626, amplifiedMethods.size());
}
use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class LiteralAmplifiersTest method testAvoidRedundantAmplification.
@Test
public void testAvoidRedundantAmplification() throws Exception {
/*
This test implements the example cases showed in https://github.com/STAMP-project/dspot/issues/454
*/
CtClass<?> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
final String nameMethod = "methodString";
final CtMethod method = literalMutationClass.getMethodsByName(nameMethod).get(0);
final CtMethod clone = method.clone();
clone.setSimpleName("temporaryMethod");
clone.setBody(launcher.getFactory().createCodeSnippetStatement("int x = 1 + 1").compile());
Amplifier zeroAmplifier = new AbstractLiteralAmplifier<Integer>() {
@Override
protected Set<CtExpression<Integer>> amplify(CtExpression<Integer> original, CtMethod<?> testMethod) {
return Collections.singleton(testMethod.getFactory().createLiteral(0));
}
@Override
protected String getSuffix() {
return "zero-amplifier";
}
@Override
protected Class<?> getTargetedClass() {
return Integer.class;
}
};
literalMutationClass.addMethod(clone);
// used to verify that the application of Amplifiers does not modify the given test method
final String originalTestMethodString = clone.toString();
List<CtMethod<?>> zeroAmplifiedTests = zeroAmplifier.amplify(clone, 0).collect(Collectors.toList());
assertEquals(2, zeroAmplifiedTests.size());
// the original test method has not been modified
assertEquals(originalTestMethodString, clone.toString());
zeroAmplifiedTests = zeroAmplifiedTests.stream().flatMap(testMethod -> zeroAmplifier.amplify(testMethod, 0)).collect(Collectors.toList());
assertEquals(originalTestMethodString, clone.toString());
assertEquals(1, zeroAmplifiedTests.size());
literalMutationClass.removeMethod(clone);
}
use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.
the class NullifierAmplifierTest method test.
@Test
public void test() throws Exception {
// test the result of the NullifierAmplifier
final String nameMethod = "methodString";
CtClass<?> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
RandomHelper.setSeedRandom(42L);
Amplifier amplifier = new NullifierAmplifier();
final CtMethod method = findMethod(literalMutationClass, nameMethod);
List<CtMethod<?>> amplification = amplifier.amplify(method, 0).collect(Collectors.toList());
assertEquals(2, amplification.size());
amplification = amplification.stream().flatMap(testMethod -> amplifier.amplify(testMethod, 0)).collect(Collectors.toList());
assertEquals(2, amplification.size());
}
Aggregations