Search in sources :

Example 16 with Amplifier

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

the class RecoveryDSpotTest method testThatDSpotCanRecoverFromError.

@Test
public void testThatDSpotCanRecoverFromError() throws Exception {
    /*
            We test here, with different mock, that DSpot can recover for errors, continue and terminate the amplification process.
         */
    final SelectorThatThrowsError selector = new SelectorThatThrowsError(builder, configuration);
    selector.setThrowsToAmplify(true);
    DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(configuration, "");
    final TestFinder testFinder = new TestFinder(Collections.emptyList(), Collections.emptyList());
    final CtClass<?> testClassToBeAmplified = findClass("fr.inria.amp.OneLiteralTest");
    final List<CtMethod<?>> testListToBeAmplified = testFinder.findTestMethods(testClassToBeAmplified, Collections.emptyList());
    DSpotState dspotState = new DSpotState();
    dspotState.setDelta(0.1f);
    dspotState.setCompiler(compiler);
    dspotState.setTestSelector(selector);
    dspotState.setInputAmplDistributor(new TextualDistanceInputAmplDistributor(200, Collections.emptyList()));
    dspotState.setNbIteration(1);
    dspotState.setTestCompiler(testCompiler);
    dspotState.setAssertionGenerator(new AssertionGenerator(0.1f, compiler, testCompiler));
    DSpot dspot = new DSpot(dspotState);
    dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
    assertEquals(2, DSpotState.GLOBAL_REPORT.getErrors().size());
    assertSame(ErrorEnum.ERROR_PRE_SELECTION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
    DSpotState.GLOBAL_REPORT.reset();
    selector.setThrowsToAmplify(false);
    selector.setThrowsToKeep(true);
    dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
    assertEquals(2, DSpotState.GLOBAL_REPORT.getErrors().size());
    assertSame(ErrorEnum.ERROR_SELECTION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
    DSpotState.GLOBAL_REPORT.reset();
    final List<Amplifier> amplifiers = Collections.singletonList(new AmplifierThatThrowsError());
    dspotState.setTestSelector(new TakeAllSelector(this.builder, this.configuration));
    dspotState.setInputAmplDistributor(new TextualDistanceInputAmplDistributor(200, amplifiers));
    dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
    assertEquals(1, DSpotState.GLOBAL_REPORT.getErrors().size());
    assertSame(ErrorEnum.ERROR_INPUT_AMPLIFICATION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
    DSpotState.GLOBAL_REPORT.reset();
    dspotState.setInputAmplDistributor(new TextualDistanceInputAmplDistributor(200, Collections.emptyList()));
    dspotState.setAssertionGenerator(new AssertionGeneratorThatThrowsError(compiler));
    dspot.fullAmplification(testClassToBeAmplified, testListToBeAmplified, Collections.emptyList(), 1);
    assertEquals(1, DSpotState.GLOBAL_REPORT.getErrors().size());
    assertSame(ErrorEnum.ERROR_ASSERT_AMPLIFICATION, DSpotState.GLOBAL_REPORT.getErrors().get(0).type);
    DSpotState.GLOBAL_REPORT.reset();
}
Also used : AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) DSpotCompiler(eu.stamp_project.dspot.common.compilation.DSpotCompiler) DSpotState(eu.stamp_project.dspot.common.configuration.DSpotState) TextualDistanceInputAmplDistributor(eu.stamp_project.dspot.amplifier.TextualDistanceInputAmplDistributor) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) TakeAllSelector(eu.stamp_project.dspot.selector.TakeAllSelector) TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 17 with Amplifier

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

the class BooleanLiteralAmplifierTest method testAmplify.

@Test
public void testAmplify() {
    final String nameMethod = "methodBoolean";
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    Amplifier mutator = new BooleanLiteralAmplifier();
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
    assertEquals(1, mutantMethods.size());
}
Also used : BooleanLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.BooleanLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) BooleanLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.BooleanLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 18 with Amplifier

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

Aggregations

Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)18 CtMethod (spoon.reflect.declaration.CtMethod)17 Test (org.junit.Test)15 StringLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier)6 NullifierAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NullifierAmplifier)4 NumberLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier)4 AbstractLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier)3 ArrayList (java.util.ArrayList)3 AssertionGenerator (eu.stamp_project.dspot.assertiongenerator.AssertionGenerator)2 TestFinder (eu.stamp_project.dspot.common.configuration.test_finder.TestFinder)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Ignore (org.junit.Ignore)2 CtExpression (spoon.reflect.code.CtExpression)2 CtClass (spoon.reflect.declaration.CtClass)2 AbstractTestOnSample (eu.stamp_project.dspot.AbstractTestOnSample)1 TextualDistanceInputAmplDistributor (eu.stamp_project.dspot.amplifier.TextualDistanceInputAmplDistributor)1 AllLiteralAmplifiers (eu.stamp_project.dspot.amplifier.amplifiers.AllLiteralAmplifiers)1 BooleanLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.BooleanLiteralAmplifier)1 CharLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.CharLiteralAmplifier)1