use of spoon.reflect.code.CtLiteral in project dspot by STAMP-project.
the class TestDataMutatorTest method testDoubleMutation.
@Test
public void testDoubleMutation() throws Exception {
/*
Test the amplification on numbers (double) literal
4 operations: i+1, i−1, i×2, i÷2
and 1 literals present that is different that the muted
*/
final String nameMethod = "methodDouble";
final double originalValue = 23.0D;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
TestDataMutator amplificator = getTestDataMutator(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Double> expectedValues = Arrays.asList(22.0D, 24.0D, 46.0D, (23.0D / 2.0D), 32.0D, 0.0D);
List<CtMethod> mutantMethods = amplificator.apply(method);
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()));
}
}
use of spoon.reflect.code.CtLiteral 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 = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
TestDataMutator amplificator = getTestDataMutator(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Integer> expectedValues = Arrays.asList(22, 24, 46, (23 / 2), 32, 0);
List<CtMethod> mutantMethods = amplificator.apply(method);
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()));
}
}
use of spoon.reflect.code.CtLiteral in project dspot by STAMP-project.
the class TestDataMutatorTest method testCharacterMutation.
@Test
public void testCharacterMutation() throws Exception {
/*
Test the amplification on character literal
*/
final String nameMethod = "methodCharacter";
final char originalValue = 'z';
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
TestDataMutator mutator = getTestDataMutator(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<CtMethod> mutantMethods = mutator.apply(method);
List<Character> expectedValues = Arrays.asList('\0', ' ', 'h', '{', 'y', System.getProperty("line.separator").charAt(0));
assertEquals(6, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + SUFFIX_MUTATION + "Char" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(expectedValues.contains(mutantLiteral.getValue()));
}
}
use of spoon.reflect.code.CtLiteral 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 = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
TestDataMutator mutator = getTestDataMutator(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<CtMethod> mutantMethods = mutator.apply(method);
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 spoon.reflect.code.CtLiteral in project dspot by STAMP-project.
the class ChangeMinimizerTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() throws Exception {
/*
ChangeMinimizer keeps only the assertions that trigger the failure on the second version
*/
final CtClass testClass = Utils.findClass("example.TestSuiteExample");
final String configurationPath = Utils.getInputConfiguration().getProperty("configPath");
final String pathToFolder = Utils.getInputConfiguration().getProperty("folderPath");
InputConfiguration inputConfiguration = new InputConfiguration(configurationPath);
InputProgram inputProgram = InputConfiguration.initInputProgram(inputConfiguration);
inputConfiguration.setInputProgram(inputProgram);
String pathToChangedVersionOfProgram = pathToFolder + DSpotUtils.shouldAddSeparator.apply(pathToFolder) + (inputConfiguration.getProperty("targetModule") != null ? inputConfiguration.getProperty("targetModule") + DSpotUtils.shouldAddSeparator.apply(pathToFolder) : "");
inputProgram.setProgramDir(pathToChangedVersionOfProgram);
Initializer.initialize(Utils.getInputConfiguration(), inputProgram);
final HashMap<CtMethod<?>, Failure> failurePerAmplifiedTest = new HashMap<>();
final CtMethod<?> test2 = Utils.findMethod(testClass, "test2");
failurePerAmplifiedTest.put(test2, new Failure(Description.EMPTY, new StringIndexOutOfBoundsException(-1)));
final ChangeMinimizer changeMinimizer = new ChangeMinimizer(testClass, inputConfiguration, inputProgram, pathToChangedVersionOfProgram, failurePerAmplifiedTest);
final CtInvocation assertion = test2.getElements(new TypeFilter<CtInvocation>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation element) {
return AmplificationChecker.isAssert(element);
}
}).get(0);
final CtInvocation clone = assertion.clone();
clone.getElements(new TypeFilter<CtLiteral>(CtLiteral.class) {
@Override
public boolean matches(CtLiteral element) {
return element.getValue() instanceof Integer && super.matches(element);
}
}).get(0).setValue(-1);
test2.getBody().insertEnd(clone);
assertEquals(3, test2.getBody().getStatements().size());
final CtMethod<?> minimize = changeMinimizer.minimize(test2);
assertEquals(2, minimize.getBody().getStatements().size());
}
Aggregations