use of spoon.reflect.code.CtLiteral 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.code.CtLiteral 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.code.CtLiteral 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.code.CtLiteral in project spoon by INRIA.
the class CommentTest method testWildComments.
@Test
public void testWildComments() {
// contract: tests that value of comment is correct even for wild combinations of characters. See WildComments class for details
Factory f = getSpoonFactory();
CtClass<?> type = (CtClass<?>) f.Type().get(WildComments.class);
List<CtLiteral<String>> literals = (List) ((CtNewArray<?>) type.getField("comments").getDefaultExpression()).getElements();
assertTrue(literals.size() > 10);
/*
* each string literal has a comment and string value, which defines expected value of it's comment
*/
for (CtLiteral<String> literal : literals) {
assertEquals(1, literal.getComments().size());
CtComment comment = literal.getComments().get(0);
String expected = literal.getValue();
assertEquals(literal.getPosition().toString(), expected, comment.getContent());
}
}
use of spoon.reflect.code.CtLiteral in project spoon by INRIA.
the class ReplaceTest method testReplaceExpression.
@Test
public void testReplaceExpression() {
CtMethod<?> sample = factory.Package().get("spoon.test.replace.testclasses").getType("Foo").getMethod("foo");
CtVariable<?> var = sample.getBody().getStatement(0);
Assert.assertTrue(var.getDefaultExpression() instanceof CtLiteral);
Assert.assertEquals(3, ((CtLiteral<?>) var.getDefaultExpression()).getValue());
CtLiteral replacement = factory.Core().createLiteral();
replacement.setValue(42);
var.getDefaultExpression().replace(replacement);
Assert.assertEquals(42, ((CtLiteral<?>) var.getDefaultExpression()).getValue());
}
Aggregations