Search in sources :

Example 11 with Amplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.

the class StringLiteralAmplifierTest method testDoesNotAmplifyChar.

@Test
public void testDoesNotAmplifyChar() throws Exception {
    final String nameMethod = "methodCharacter";
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    Amplifier mutator = new StringLiteralAmplifier();
    mutator.reset(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<CtMethod> mutantMethods = mutator.amplify(method, 0).collect(Collectors.toList());
    assertTrue(mutantMethods.isEmpty());
}
Also used : StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 12 with Amplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.

the class StringLiteralAmplifierTest method testOneLitExisting.

@Test
public void testOneLitExisting() throws Exception {
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.OneLiteralTest");
    Amplifier amplifier = new StringLiteralAmplifier();
    amplifier.reset(literalMutationClass);
    final Stream<CtMethod<?>> test = amplifier.amplify(findMethod(literalMutationClass, "test"), 0);
    System.out.println(test.collect(Collectors.toList()));
}
Also used : StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 13 with Amplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.

the class LiteralAmplifiersTest method testAllHasBeenAmplified.

@Ignore
@Test
public void testAllHasBeenAmplified() throws Exception {
    /*
            The amplifiers must keep doing the amplification in case of all the combination of amplification has been explored.
         */
    final CtClass testClass = launcher.getFactory().Class().get("fr.inria.workload.WorkloadTest");
    List<CtMethod<?>> allTest = TestFramework.getAllTest(testClass);
    Amplifier amplifier = new NumberLiteralAmplifier();
    allTest = allTest.stream().flatMap(// we apply twice the NumberLiteralAmplifier. In one iteration, it explores every amplification that can be done
    method -> amplifier.amplify(method, 0)).flatMap(// however, we can continue to amplify since there is some random
    method -> amplifier.amplify(method, 0)).collect(Collectors.toList());
    assertFalse(allTest.isEmpty());
}
Also used : AbstractLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier) RandomHelper(eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper) AbstractTestOnSample(eu.stamp_project.dspot.AbstractTestOnSample) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) TestFramework(eu.stamp_project.dspot.common.test_framework.TestFramework) Set(java.util.Set) Test(org.junit.Test) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Ignore(org.junit.Ignore) CtExpression(spoon.reflect.code.CtExpression) Assert.assertFalse(org.junit.Assert.assertFalse) CtClass(spoon.reflect.declaration.CtClass) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CtMethod(spoon.reflect.declaration.CtMethod) CtClass(spoon.reflect.declaration.CtClass) 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) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with Amplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.

the class NullifierAmplifierTest method testOnIntegerMethodCall.

@Test
public void testOnIntegerMethodCall() throws Exception {
    /*
            test the result of the NullifierAmplifier: it can nullify non primitive type but not primitive
         */
    final String nameMethod = "methodCall";
    CtClass<?> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.ClassWithMethodCall");
    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)

Example 15 with Amplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.Amplifier in project dspot by STAMP-project.

the class PerformanceTest method test.

@Ignore
@Test
public void test() throws Exception {
    /*
         * This test aims at measuring the time execution of multiple applications of Amplifiers.
         * This test is meant to be run manually
         */
    final int numberOfIteration = 3;
    final CtClass testClass = findClass("fr.inria.ampl.ToBeAmplifiedLiteralTest");
    final CtMethod originalTest = findMethod(testClass, "testInt");
    List<CtMethod> amplifiedTestMethod1 = Collections.singletonList(originalTest);
    List<CtMethod> amplifiedTestMethod2 = Collections.singletonList(originalTest);
    Amplifier testDataMutator = new FastLiteralAmplifier();
    testDataMutator.reset(testClass);
    Amplifier allLiteralAmplifiers = new AllLiteralAmplifiers();
    allLiteralAmplifiers.reset(testClass);
    long start = System.currentTimeMillis();
    for (int i = 0; i < numberOfIteration; i++) {
        amplifiedTestMethod1 = amplifiedTestMethod1.stream().flatMap(testMethod -> allLiteralAmplifiers.amplify(testMethod, 0)).collect(Collectors.toList());
        System.out.println("(" + i + ")Number of Amplification:" + amplifiedTestMethod1.size());
    }
    final long timeAllLiteral = System.currentTimeMillis() - start;
    System.out.println(timeAllLiteral + "ms");
    long start2 = System.currentTimeMillis();
    for (int i = 0; i < numberOfIteration; i++) {
        amplifiedTestMethod2 = amplifiedTestMethod2.stream().flatMap(testMethod -> testDataMutator.amplify(testMethod, 0)).collect(Collectors.toList());
        System.out.println("(" + i + ")Number of Amplification:" + amplifiedTestMethod2.size());
    }
    final long timeTestDataMutator = System.currentTimeMillis() - start2;
    System.out.println(timeTestDataMutator + "ms");
    assertTrue(timeTestDataMutator > timeAllLiteral);
    assertTrue(amplifiedTestMethod2.size() > amplifiedTestMethod1.size());
}
Also used : CtClass(spoon.reflect.declaration.CtClass) FastLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier) FastLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) CtMethod(spoon.reflect.declaration.CtMethod) AllLiteralAmplifiers(eu.stamp_project.dspot.amplifier.amplifiers.AllLiteralAmplifiers) Ignore(org.junit.Ignore) 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