Search in sources :

Example 1 with NumberLiteralAmplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier 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 2 with NumberLiteralAmplifier

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

the class NumberLiteralAmplifierTest method testIntMutation.

@Test
public void testIntMutation() {
    final String nameMethod = "methodInteger";
    final int originalValue = 23;
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    NumberLiteralAmplifier amplifier = getAmplifier(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<Integer> expectedValues = Arrays.asList(22, 24, 2147483647, -2147483648, 0, -1170105035);
    List<String> expectedFieldReads = Arrays.asList("java.lang.Integer.MAX_VALUE", "java.lang.Integer.MIN_VALUE");
    List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
    callAssertions(mutantMethods, nameMethod, expectedValues, expectedFieldReads, originalValue, 6);
}
Also used : NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 3 with NumberLiteralAmplifier

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

the class NumberLiteralAmplifierTest method testShortMutation.

@Test
public void testShortMutation() {
    final String nameMethod = "methodShort";
    final short originalValue = 23;
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    NumberLiteralAmplifier amplifier = getAmplifier(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<Short> expectedValues = Arrays.asList((short) 22, (short) 24, (short) 0, (short) -25291);
    List<String> expectedFieldReads = Arrays.asList("java.lang.Short.MAX_VALUE", "java.lang.Short.MIN_VALUE");
    List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
    callAssertions(mutantMethods, nameMethod, expectedValues, expectedFieldReads, originalValue, 6);
}
Also used : NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 4 with NumberLiteralAmplifier

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

the class NumberLiteralAmplifierTest method getAmplifier.

private NumberLiteralAmplifier getAmplifier(CtClass<?> testClassToBeAmplified) {
    final NumberLiteralAmplifier numberLiteralAmplifier = new NumberLiteralAmplifier();
    numberLiteralAmplifier.reset(testClassToBeAmplified);
    return numberLiteralAmplifier;
}
Also used : NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier)

Example 5 with NumberLiteralAmplifier

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

the class NumberLiteralAmplifierTest method testFloatMutation.

@Test
public void testFloatMutation() {
    final String nameMethod = "methodFloat";
    final double originalValue = 23.0F;
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    NumberLiteralAmplifier amplifier = getAmplifier(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<Float> expectedValues = Arrays.asList(22.0F, 24.0F, 0.0F, 0.7275637F);
    List<String> expectedFieldReads = Arrays.asList("java.lang.Float.MAX_VALUE", "java.lang.Float.MIN_VALUE", "java.lang.Float.MIN_NORMAL", "java.lang.Float.NaN", "java.lang.Float.POSITIVE_INFINITY", "java.lang.Float.NEGATIVE_INFINITY");
    List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
    callAssertions(mutantMethods, nameMethod, expectedValues, expectedFieldReads, originalValue, 10);
}
Also used : NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

NumberLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier)12 Test (org.junit.Test)10 CtMethod (spoon.reflect.declaration.CtMethod)10 Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)3 AbstractLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier)2 IterationDecoratorAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.IterationDecoratorAmplifier)2 StringLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier)2 ArrayList (java.util.ArrayList)2 AbstractTestOnSample (eu.stamp_project.dspot.AbstractTestOnSample)1 SimpleInputAmplDistributor (eu.stamp_project.dspot.amplifier.SimpleInputAmplDistributor)1 MethodAdderOnExistingObjectsAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier)1 ReturnValueAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier)1 RandomHelper (eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper)1 TestFramework (eu.stamp_project.dspot.common.test_framework.TestFramework)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1