Search in sources :

Example 6 with NumberLiteralAmplifier

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

the class NumberLiteralAmplifierTest method setup.

@Before
public void setup() throws Exception {
    super.setUp();
    literalMutationClass = findClass("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    amplifier = new NumberLiteralAmplifier();
}
Also used : NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) Before(org.junit.Before)

Example 7 with NumberLiteralAmplifier

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

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

the class SimpleInputAmplDistributorTest method test.

@Test
public void test() throws Exception {
    /*
            Test the simple input_ampl_distributor with different amplifier.
            The SimpleBudget should always provide a specific number of test Methods
         */
    final CtClass<?> testClass = findClass("fr.inria.statementadd.TestClassTargetAmplify");
    List<CtMethod<?>> ctMethods = TestFramework.getAllTest(testClass);
    final SimpleInputAmplDistributor simpleBudgetizer = new SimpleInputAmplDistributor(6, Arrays.asList(new IterationDecoratorAmplifier(new ReturnValueAmplifier(), 3), new IterationDecoratorAmplifier(new MethodAdderOnExistingObjectsAmplifier(), 2), new NumberLiteralAmplifier()));
    for (int i = 0; i < 3; i++) {
        // !
        ctMethods = simpleBudgetizer.inputAmplify(ctMethods, i);
    }
    assertEquals(6, ctMethods.size());
}
Also used : MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) SimpleInputAmplDistributor(eu.stamp_project.dspot.amplifier.SimpleInputAmplDistributor) CtMethod(spoon.reflect.declaration.CtMethod) IterationDecoratorAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.IterationDecoratorAmplifier) ReturnValueAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) Test(org.junit.Test)

Example 9 with NumberLiteralAmplifier

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

the class IterationDecoratorAmplifierTest method test.

@Test
public void test() throws Exception {
    /*
            Test the application of IterationDecoratorAmplifier.
            This amplifier decorate the given amplifier to apply it at a given frequency
         */
    final String nameMethod = "methodInteger";
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    // we apply the given amplifier each 2 iteration, i.e. iteration 0, iteration 2, iteration 4 etc....
    Amplifier amplifier = new IterationDecoratorAmplifier(new NumberLiteralAmplifier(), 2);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    // 1 / 2 iteration produces something (the list is not empty)
    for (int i = 0; i < 10; i = i + 2) {
        assertFalse(amplifier.amplify(method, i).collect(Collectors.toList()).isEmpty());
        assertTrue(amplifier.amplify(method, i + 1).collect(Collectors.toList()).isEmpty());
    }
    amplifier = new IterationDecoratorAmplifier(new NumberLiteralAmplifier(), 3);
    // 1 / 3 iteration produces something (the list is not empty)
    for (int i = 0; i < 12; i = i + 3) {
        assertFalse(amplifier.amplify(method, i).collect(Collectors.toList()).isEmpty());
        assertTrue(amplifier.amplify(method, i + 1).collect(Collectors.toList()).isEmpty());
        assertTrue(amplifier.amplify(method, i + 2).collect(Collectors.toList()).isEmpty());
    }
}
Also used : IterationDecoratorAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.IterationDecoratorAmplifier) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) IterationDecoratorAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.IterationDecoratorAmplifier) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 10 with NumberLiteralAmplifier

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

the class NumberLiteralAmplifierTest method testDoubleMutation.

@Test
public void testDoubleMutation() {
    final String nameMethod = "methodDouble";
    final double originalValue = 23.0D;
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    NumberLiteralAmplifier amplifier = getAmplifier(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<Double> expectedValues = Arrays.asList(22.0D, 24.0D, 0.0D, 0.7275636800328681);
    List<String> expectedFieldReads = Arrays.asList("java.lang.Double.MAX_VALUE", "java.lang.Double.MIN_VALUE", "java.lang.Double.MIN_NORMAL", "java.lang.Double.NaN", "java.lang.Double.POSITIVE_INFINITY", "java.lang.Double.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