Search in sources :

Example 1 with Amplifier

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;
}
Also used : HashMap(java.util.HashMap) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) Map(java.util.Map) HashMap(java.util.HashMap) CtMethod(spoon.reflect.declaration.CtMethod)

Example 2 with Amplifier

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());
}
Also used : CharLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.CharLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) CharLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.CharLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 3 with Amplifier

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());
}
Also used : ArrayList(java.util.ArrayList) AbstractLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 4 with Amplifier

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);
}
Also used : AbstractLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier) CtExpression(spoon.reflect.code.CtExpression) AbstractLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 5 with Amplifier

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());
}
Also used : NullifierAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NullifierAmplifier) NullifierAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NullifierAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)18 CtMethod (spoon.reflect.declaration.CtMethod)17 Test (org.junit.Test)15 StringLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier)6 NullifierAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NullifierAmplifier)4 NumberLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier)4 AbstractLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier)3 ArrayList (java.util.ArrayList)3 AssertionGenerator (eu.stamp_project.dspot.assertiongenerator.AssertionGenerator)2 TestFinder (eu.stamp_project.dspot.common.configuration.test_finder.TestFinder)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Ignore (org.junit.Ignore)2 CtExpression (spoon.reflect.code.CtExpression)2 CtClass (spoon.reflect.declaration.CtClass)2 AbstractTestOnSample (eu.stamp_project.dspot.AbstractTestOnSample)1 TextualDistanceInputAmplDistributor (eu.stamp_project.dspot.amplifier.TextualDistanceInputAmplDistributor)1 AllLiteralAmplifiers (eu.stamp_project.dspot.amplifier.amplifiers.AllLiteralAmplifiers)1 BooleanLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.BooleanLiteralAmplifier)1 CharLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.CharLiteralAmplifier)1