Search in sources :

Example 1 with FastLiteralAmplifier

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

the class TestDataMutatorTest method getTestDataMutator.

private FastLiteralAmplifier getTestDataMutator(CtClass<Object> literalMutationClass) {
    FastLiteralAmplifier amplifier = new FastLiteralAmplifier();
    amplifier.reset(literalMutationClass);
    return amplifier;
}
Also used : FastLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier)

Example 2 with FastLiteralAmplifier

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

the class TestDataMutatorTest method testBooleanMutation.

@Test
public void testBooleanMutation() throws Exception {
    /*
            Test the amplification on boolean literal
         */
    final String nameMethod = "methodBoolean";
    final boolean originalValue = true;
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    FastLiteralAmplifier mutator = getTestDataMutator(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<CtMethod> mutantMethods = mutator.amplify(method, 0).collect(Collectors.toList());
    CtMethod mutantMethod = mutantMethods.get(0);
    assertEquals(1, mutantMethods.size());
    assertEquals(nameMethod + SUFFIX_MUTATION + "Boolean" + "1", mutantMethod.getSimpleName());
    CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
    assertEquals(!(originalValue), mutantLiteral.getValue());
}
Also used : FastLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier) CtLiteral(spoon.reflect.code.CtLiteral) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 3 with FastLiteralAmplifier

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

the class TestDataMutatorTest method testStringMutation.

@Test
public void testStringMutation() throws Exception {
    /*
          Test the amplification on string literal
                3 operations: remove 1 random char, replace 1 random char, add 1 random char
                Additionally, it replace by totally random string with the same size than the original one,
                and by 1 literals present that is different that the muted
        */
    final String nameMethod = "methodString";
    final String originalValue = "MyStringLiteral";
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    FastLiteralAmplifier amplifier = getTestDataMutator(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
    assertEquals(12, mutantMethods.size());
    for (int i = 0; i < 6; i++) {
        CtMethod mutantMethod = mutantMethods.get(i);
        assertEquals(nameMethod + SUFFIX_MUTATION + "String" + (i + 1), mutantMethod.getSimpleName());
        CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
        assertNotEquals(originalValue, mutantLiteral.getValue());
        assertDistanceBetweenOriginalAndMuted(originalValue, (String) mutantLiteral.getValue());
    }
}
Also used : FastLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier) CtLiteral(spoon.reflect.code.CtLiteral) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 4 with FastLiteralAmplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier 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)

Example 5 with FastLiteralAmplifier

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

the class TestDataMutatorTest method testIntMutation.

@Test
public void testIntMutation() throws Exception {
    /*
            Test the amplification on numbers (integer) literal
                4 operations: i+1, i−1, i×2, i÷2.
                and 1 literals present that is different that the muted
                and 0
         */
    final String nameMethod = "methodInteger";
    final int originalValue = 23;
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    FastLiteralAmplifier amplifier = getTestDataMutator(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<Integer> expectedValues = Arrays.asList(22, 24, 46, (23 / 2), 32, 0);
    List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
    assertEquals(6, mutantMethods.size());
    for (int i = 0; i < mutantMethods.size(); i++) {
        CtMethod mutantMethod = mutantMethods.get(i);
        assertEquals(nameMethod + SUFFIX_MUTATION + "Number" + (i + 1), mutantMethod.getSimpleName());
        CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
        assertNotEquals(originalValue, mutantLiteral.getValue());
        assertTrue(expectedValues.contains(mutantLiteral.getValue()));
    }
}
Also used : FastLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier) CtLiteral(spoon.reflect.code.CtLiteral) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

FastLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier)7 Test (org.junit.Test)6 CtMethod (spoon.reflect.declaration.CtMethod)6 CtLiteral (spoon.reflect.code.CtLiteral)5 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)5 AllLiteralAmplifiers (eu.stamp_project.dspot.amplifier.amplifiers.AllLiteralAmplifiers)1 Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)1 Ignore (org.junit.Ignore)1 CtClass (spoon.reflect.declaration.CtClass)1