use of eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier in project dspot by STAMP-project.
the class TestDataMutatorTest method getTestDataMutator.
private FastLiteralAmplifier getTestDataMutator(CtClass<Object> literalMutationClass) {
FastLiteralAmplifier amplifier = new FastLiteralAmplifier();
amplifier.reset(literalMutationClass);
return amplifier;
}
use of eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier in project dspot by STAMP-project.
the class TestDataMutatorTest method testBooleanMutation.
@Test
public void testBooleanMutation() throws Exception {
/*
Test the amplification on boolean literal
*/
final String nameMethod = "methodBoolean";
final boolean originalValue = true;
CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
RandomHelper.setSeedRandom(42L);
FastLiteralAmplifier mutator = getTestDataMutator(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<CtMethod> mutantMethods = mutator.amplify(method, 0).collect(Collectors.toList());
CtMethod mutantMethod = mutantMethods.get(0);
assertEquals(1, mutantMethods.size());
assertEquals(nameMethod + SUFFIX_MUTATION + "Boolean" + "1", mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertEquals(!(originalValue), mutantLiteral.getValue());
}
use of eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier in project dspot by STAMP-project.
the class TestDataMutatorTest method testStringMutation.
@Test
public void testStringMutation() throws Exception {
/*
Test the amplification on string literal
3 operations: remove 1 random char, replace 1 random char, add 1 random char
Additionally, it replace by totally random string with the same size than the original one,
and by 1 literals present that is different that the muted
*/
final String nameMethod = "methodString";
final String originalValue = "MyStringLiteral";
CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
RandomHelper.setSeedRandom(42L);
FastLiteralAmplifier amplifier = getTestDataMutator(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
assertEquals(12, mutantMethods.size());
for (int i = 0; i < 6; i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + SUFFIX_MUTATION + "String" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertDistanceBetweenOriginalAndMuted(originalValue, (String) mutantLiteral.getValue());
}
}
use of eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier in project dspot by STAMP-project.
the class PerformanceTest method test.
@Ignore
@Test
public void test() throws Exception {
/*
* This test aims at measuring the time execution of multiple applications of Amplifiers.
* This test is meant to be run manually
*/
final int numberOfIteration = 3;
final CtClass testClass = findClass("fr.inria.ampl.ToBeAmplifiedLiteralTest");
final CtMethod originalTest = findMethod(testClass, "testInt");
List<CtMethod> amplifiedTestMethod1 = Collections.singletonList(originalTest);
List<CtMethod> amplifiedTestMethod2 = Collections.singletonList(originalTest);
Amplifier testDataMutator = new FastLiteralAmplifier();
testDataMutator.reset(testClass);
Amplifier allLiteralAmplifiers = new AllLiteralAmplifiers();
allLiteralAmplifiers.reset(testClass);
long start = System.currentTimeMillis();
for (int i = 0; i < numberOfIteration; i++) {
amplifiedTestMethod1 = amplifiedTestMethod1.stream().flatMap(testMethod -> allLiteralAmplifiers.amplify(testMethod, 0)).collect(Collectors.toList());
System.out.println("(" + i + ")Number of Amplification:" + amplifiedTestMethod1.size());
}
final long timeAllLiteral = System.currentTimeMillis() - start;
System.out.println(timeAllLiteral + "ms");
long start2 = System.currentTimeMillis();
for (int i = 0; i < numberOfIteration; i++) {
amplifiedTestMethod2 = amplifiedTestMethod2.stream().flatMap(testMethod -> testDataMutator.amplify(testMethod, 0)).collect(Collectors.toList());
System.out.println("(" + i + ")Number of Amplification:" + amplifiedTestMethod2.size());
}
final long timeTestDataMutator = System.currentTimeMillis() - start2;
System.out.println(timeTestDataMutator + "ms");
assertTrue(timeTestDataMutator > timeAllLiteral);
assertTrue(amplifiedTestMethod2.size() > amplifiedTestMethod1.size());
}
use of eu.stamp_project.dspot.amplifier.amplifiers.FastLiteralAmplifier in project dspot by STAMP-project.
the class TestDataMutatorTest method testIntMutation.
@Test
public void testIntMutation() throws Exception {
/*
Test the amplification on numbers (integer) literal
4 operations: i+1, i−1, i×2, i÷2.
and 1 literals present that is different that the muted
and 0
*/
final String nameMethod = "methodInteger";
final int originalValue = 23;
CtClass<Object> literalMutationClass = launcher.getFactory().Class().get("fr.inria.amp.LiteralMutation");
RandomHelper.setSeedRandom(42L);
FastLiteralAmplifier amplifier = getTestDataMutator(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Integer> expectedValues = Arrays.asList(22, 24, 46, (23 / 2), 32, 0);
List<CtMethod> mutantMethods = amplifier.amplify(method, 0).collect(Collectors.toList());
assertEquals(6, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + SUFFIX_MUTATION + "Number" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(expectedValues.contains(mutantLiteral.getValue()));
}
}
Aggregations