Search in sources :

Example 6 with FastLiteralAmplifier

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

the class TestDataMutatorTest method testCharacterMutation.

@Test
public void testCharacterMutation() throws Exception {
    /*
            Test the amplification on character literal
         */
    final String nameMethod = "methodCharacter";
    final char originalValue = 'z';
    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());
    List<Character> expectedValues = Arrays.asList('\0', ' ', 'h', '{', 'y', System.getProperty("line.separator").charAt(0));
    assertEquals(6, mutantMethods.size());
    for (int i = 0; i < mutantMethods.size(); i++) {
        CtMethod mutantMethod = mutantMethods.get(i);
        assertEquals(nameMethod + SUFFIX_MUTATION + "Char" + (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)

Example 7 with FastLiteralAmplifier

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

the class TestDataMutatorTest method testDoubleMutation.

@Test
public void testDoubleMutation() throws Exception {
    /*
            Test the amplification on numbers (double) literal
                4 operations: i+1, i−1, i×2, i÷2
                and 1 literals present that is different that the muted
         */
    final String nameMethod = "methodDouble";
    final double originalValue = 23.0D;
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    FastLiteralAmplifier amplifier = getTestDataMutator(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<Double> expectedValues = Arrays.asList(22.0D, 24.0D, 46.0D, (23.0D / 2.0D), 32.0D, 0.0D);
    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