use of spoon.reflect.code.CtLiteral in project dspot by STAMP-project.
the class AmplificationHelperTest method testReduction.
@Test
public void testReduction() throws Exception {
/*
test that the reduction, using hashcode is correct.
The method should return a list with different test
*/
AmplificationHelper.MAX_NUMBER_OF_TESTS = 2;
final CtMethod methodString = Utils.findMethod("fr.inria.amp.LiteralMutation", "methodString");
// very different
final CtMethod methodInteger = Utils.findMethod("fr.inria.amp.LiteralMutation", "methodInteger");
List<CtMethod<?>> methods = new ArrayList<>();
methods.add(methodString);
methods.add(methodString);
methods.add(methodString);
methods.add(methodString);
methods.add(methodString);
methods.add(methodString);
methods.add(methodString);
methods.add(methodString);
final CtMethod clone = methodString.clone();
final CtLiteral originalLiteral = clone.getElements(new TypeFilter<>(CtLiteral.class)).get(0);
originalLiteral.replace(Utils.getFactory().createLiteral(originalLiteral.getValue() + "a"));
methods.add(clone);
methods.add(clone);
methods.add(clone);
methods.add(methodInteger);
final List<CtMethod<?>> reduce = AmplificationHelper.reduce(methods);
assertEquals(2, reduce.size());
AmplificationHelper.MAX_NUMBER_OF_TESTS = 200;
}
use of spoon.reflect.code.CtLiteral in project dspot by STAMP-project.
the class NumberLiteralAmplifierTest method testFloatMutation.
@Test
public void testFloatMutation() throws Exception {
final String nameMethod = "methodFloat";
final double originalValue = 23.0F;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Float> expectedValues = Arrays.asList(22.0F, 24.0F, Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_NORMAL, Float.NaN, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F);
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.code.CtLiteral in project dspot by STAMP-project.
the class NumberLiteralAmplifierTest method testByteMutation.
@Test
public void testByteMutation() throws Exception {
final String nameMethod = "methodByte";
final byte 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<Byte> expectedValues = Arrays.asList((byte) 22, (byte) 24, Byte.MIN_VALUE, Byte.MAX_VALUE, (byte) 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()));
}
}
Aggregations