Search in sources :

Example 1 with StringLiteralAmplifier

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

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

the class StringLiteralAmplifierTest method testAmplify.

@Test
public void testAmplify() throws Exception {
    /*
            test the StringLiteral
            The first iteration is complete, i.e. apply random operations plus the specific strings
         */
    final String nameMethod = "methodString";
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
    RandomHelper.setSeedRandom(42L);
    Amplifier amplifier = new StringLiteralAmplifier();
    amplifier.reset(literalMutationClass);
    CtMethod method = literalMutationClass.getMethod(nameMethod);
    List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
    assertEquals(28, mutantMethods.size());
}
Also used : StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 3 with StringLiteralAmplifier

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

the class AbstractSelectorRemoveOverlapTest method testRemoveOverlappingTests.

@Test
public void testRemoveOverlappingTests() {
    this.testSelectorUnderTest.init();
    DSpotState dspotState = new DSpotState();
    dspotState.setDelta(0.1f);
    dspotState.setTestFinder(new TestFinder(Collections.emptyList(), Collections.emptyList()));
    dspotState.setCompiler(compiler);
    dspotState.setTestSelector(this.testSelectorUnderTest);
    dspotState.setInputAmplDistributor(InputAmplDistributorEnum.RandomInputAmplDistributor.getInputAmplDistributor(200, Collections.singletonList(new StringLiteralAmplifier())));
    dspotState.setOutput(new Output(getPathToAbsoluteProjectRoot(), configuration.getOutputDirectory(), new NullCollector()));
    dspotState.setNbIteration(1);
    dspotState.setAutomaticBuilder(builder);
    dspotState.setTestCompiler(testCompiler);
    dspotState.setTestClassesToBeAmplified(Collections.singletonList(getTestClass()));
    dspotState.setAssertionGenerator(new AssertionGenerator(0.1f, compiler, testCompiler));
    DSpot dspot = new DSpot(dspotState);
    dspot.run();
    final File directory = new File(DSpotUtils.shouldAddSeparator.apply(this.configuration.getOutputDirectory()));
    if (!directory.exists()) {
        directory.mkdir();
    }
    assertEquals(getContentReportFile(), this.testSelectorUnderTest.report().output(this.getTestClass(), this.outputDirectory));
}
Also used : DSpot(eu.stamp_project.dspot.DSpot) InitializeDSpot(eu.stamp_project.dspot.common.configuration.InitializeDSpot) AssertionGenerator(eu.stamp_project.dspot.assertiongenerator.AssertionGenerator) Output(eu.stamp_project.dspot.common.report.output.Output) DSpotState(eu.stamp_project.dspot.common.configuration.DSpotState) TestFinder(eu.stamp_project.dspot.common.configuration.test_finder.TestFinder) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) File(java.io.File) NullCollector(eu.stamp_project.dspot.common.collector.NullCollector) Test(org.junit.Test)

Example 4 with StringLiteralAmplifier

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

the class StringLiteralAmplifierTest method testDoesNotAmplifyChar.

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

Example 5 with StringLiteralAmplifier

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

the class StringLiteralAmplifierTest method testOneLitExisting.

@Test
public void testOneLitExisting() throws Exception {
    CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.OneLiteralTest");
    Amplifier amplifier = new StringLiteralAmplifier();
    amplifier.reset(literalMutationClass);
    final Stream<CtMethod<?>> test = amplifier.amplify(findMethod(literalMutationClass, "test"), 0);
    System.out.println(test.collect(Collectors.toList()));
}
Also used : StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) Amplifier(eu.stamp_project.dspot.amplifier.amplifiers.Amplifier) StringLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Aggregations

StringLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.StringLiteralAmplifier)5 Test (org.junit.Test)5 Amplifier (eu.stamp_project.dspot.amplifier.amplifiers.Amplifier)4 CtMethod (spoon.reflect.declaration.CtMethod)4 DSpot (eu.stamp_project.dspot.DSpot)1 AbstractLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.AbstractLiteralAmplifier)1 NumberLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier)1 AssertionGenerator (eu.stamp_project.dspot.assertiongenerator.AssertionGenerator)1 NullCollector (eu.stamp_project.dspot.common.collector.NullCollector)1 DSpotState (eu.stamp_project.dspot.common.configuration.DSpotState)1 InitializeDSpot (eu.stamp_project.dspot.common.configuration.InitializeDSpot)1 TestFinder (eu.stamp_project.dspot.common.configuration.test_finder.TestFinder)1 Output (eu.stamp_project.dspot.common.report.output.Output)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1