use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class NumberLiteralAmplifierTest method testIntMutation.
@Test
public void testIntMutation() throws Exception {
final String nameMethod = "methodInteger";
final int originalValue = 23;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Integer> expectedValues = Arrays.asList(22, 24, 2147483647, -2147483648, 0);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(5, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values", expectedValues.contains(mutantLiteral.getValue()));
}
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class NumberLiteralAmplifierTest method testLongMutation.
@Test
public void testLongMutation() throws Exception {
final String nameMethod = "methodLong";
final long originalValue = 23L;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Long> expectedValues = Arrays.asList(22L, 24L, Long.MIN_VALUE, Long.MAX_VALUE, 0L);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(5, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values", expectedValues.contains(mutantLiteral.getValue()));
}
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class NumberLiteralAmplifierTest method testDoubleMutation.
@Test
public void testDoubleMutation() throws Exception {
final String nameMethod = "methodDouble";
final double originalValue = 23.0D;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Double> expectedValues = Arrays.asList(22.0D, 24.0D, Double.MAX_VALUE, Double.MIN_VALUE, Double.MIN_NORMAL, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0D);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(9, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values", expectedValues.contains(mutantLiteral.getValue()));
}
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class StatementAddTest method testOnClassWithJavaObjects.
@Test
public void testOnClassWithJavaObjects() throws Exception {
/*
Test that the StatementAdd amplifier is able to generate, and manage Collection and Map from java.util
*/
final String packageName = "fr.inria.statementadd";
InputProgram inputProgram = Utils.getInputProgram();
final Factory factory = inputProgram.getFactory();
inputProgram.setFactory(factory);
AmplificationHelper.setSeedRandom(32L);
StatementAdd amplifier = new StatementAdd(packageName);
amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));
CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTarget"), "test");
List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
assertEquals(7, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("getList", "getSizeOf", "getSizeOfTypedCollection", "getSizeOfTypedMap");
assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
}
}).first() != null));
}
use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.
the class StatementAddTest method testStatementAddOnArrayObjects.
@Test
public void testStatementAddOnArrayObjects() throws Exception {
final String packageName = "fr.inria.statementaddarray";
InputProgram inputProgram = Utils.getInputProgram();
final Factory factory = inputProgram.getFactory();
inputProgram.setFactory(factory);
AmplificationHelper.setSeedRandom(32L);
StatementAdd amplifier = new StatementAdd(packageName);
amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));
CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
System.out.println(amplifiedMethods);
assertEquals(5, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("methodWithArrayParatemeter", "methodWithArrayParatemeterFromDomain", "methodWithDomainParameter", "methodWithReturn", "method1");
assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
}
}).first() != null));
}
Aggregations