Search in sources :

Example 36 with CtLiteral

use of spoon.reflect.code.CtLiteral in project dspot by STAMP-project.

the class AmplificationHelperTest method testReduction.

@Test
public void testReduction() throws Exception {
    /*
            test that the reduction, using hashcode is correct.
            The method should return a list with different test
         */
    AmplificationHelper.MAX_NUMBER_OF_TESTS = 2;
    final CtMethod methodString = Utils.findMethod("fr.inria.amp.LiteralMutation", "methodString");
    // very different
    final CtMethod methodInteger = Utils.findMethod("fr.inria.amp.LiteralMutation", "methodInteger");
    List<CtMethod<?>> methods = new ArrayList<>();
    methods.add(methodString);
    methods.add(methodString);
    methods.add(methodString);
    methods.add(methodString);
    methods.add(methodString);
    methods.add(methodString);
    methods.add(methodString);
    methods.add(methodString);
    final CtMethod clone = methodString.clone();
    final CtLiteral originalLiteral = clone.getElements(new TypeFilter<>(CtLiteral.class)).get(0);
    originalLiteral.replace(Utils.getFactory().createLiteral(originalLiteral.getValue() + "a"));
    methods.add(clone);
    methods.add(clone);
    methods.add(clone);
    methods.add(methodInteger);
    final List<CtMethod<?>> reduce = AmplificationHelper.reduce(methods);
    assertEquals(2, reduce.size());
    AmplificationHelper.MAX_NUMBER_OF_TESTS = 200;
}
Also used : CtLiteral(spoon.reflect.code.CtLiteral) ArrayList(java.util.ArrayList) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 37 with CtLiteral

use of spoon.reflect.code.CtLiteral in project dspot by STAMP-project.

the class NumberLiteralAmplifierTest method testFloatMutation.

@Test
public void testFloatMutation() throws Exception {
    final String nameMethod = "methodFloat";
    final double originalValue = 23.0F;
    CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    AmplificationHelper.setSeedRandom(42L);
    NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<Float> expectedValues = Arrays.asList(22.0F, 24.0F, Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_NORMAL, Float.NaN, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F);
    List<CtMethod> mutantMethods = amplificator.apply(method);
    assertEquals(9, mutantMethods.size());
    for (int i = 0; i < mutantMethods.size(); i++) {
        CtMethod mutantMethod = mutantMethods.get(i);
        assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
        CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
        assertNotEquals(originalValue, mutantLiteral.getValue());
        assertTrue(mutantLiteral.getValue() + " not in expected values", expectedValues.contains(mutantLiteral.getValue()));
    }
}
Also used : CtLiteral(spoon.reflect.code.CtLiteral) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 38 with CtLiteral

use of spoon.reflect.code.CtLiteral in project dspot by STAMP-project.

the class NumberLiteralAmplifierTest method testByteMutation.

@Test
public void testByteMutation() throws Exception {
    final String nameMethod = "methodByte";
    final byte originalValue = 23;
    CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    AmplificationHelper.setSeedRandom(42L);
    NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<Byte> expectedValues = Arrays.asList((byte) 22, (byte) 24, Byte.MIN_VALUE, Byte.MAX_VALUE, (byte) 0);
    List<CtMethod> mutantMethods = amplificator.apply(method);
    assertEquals(5, mutantMethods.size());
    for (int i = 0; i < mutantMethods.size(); i++) {
        CtMethod mutantMethod = mutantMethods.get(i);
        assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
        CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
        assertNotEquals(originalValue, mutantLiteral.getValue());
        assertTrue(mutantLiteral.getValue() + " not in expected values", expectedValues.contains(mutantLiteral.getValue()));
    }
}
Also used : CtLiteral(spoon.reflect.code.CtLiteral) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Aggregations

CtLiteral (spoon.reflect.code.CtLiteral)38 Test (org.junit.Test)28 CtMethod (spoon.reflect.declaration.CtMethod)19 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)19 AbstractTest (fr.inria.AbstractTest)13 Factory (spoon.reflect.factory.Factory)10 Launcher (spoon.Launcher)8 CtInvocation (spoon.reflect.code.CtInvocation)6 CtStatement (spoon.reflect.code.CtStatement)6 CtTypeReference (spoon.reflect.reference.CtTypeReference)6 CtExpression (spoon.reflect.code.CtExpression)5 List (java.util.List)4 CtLocalVariable (spoon.reflect.code.CtLocalVariable)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 CtIf (spoon.reflect.code.CtIf)3 CtClass (spoon.reflect.declaration.CtClass)3 CtElement (spoon.reflect.declaration.CtElement)3 NamedElementFilter (spoon.reflect.visitor.filter.NamedElementFilter)3 AssertionRemover (fr.inria.diversify.dspot.assertGenerator.AssertionRemover)2