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());
}
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());
}
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));
}
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());
}
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()));
}
Aggregations