use of org.evosuite.testcase.statements.numeric.IntPrimitiveStatement in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testOverloadedMethodsNoArgs.
@Test
public void testOverloadedMethodsNoArgs() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// Method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "values()[B");
// Output goals for method values
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values()", Type.getType("[B"), ARRAY_NONEMPTY));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal4);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal3);
test2.addCoveredGoal(goal5);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
assertEquals("Generated test name differs from expected", "testValuesTakingByteArray", nameTest1);
assertEquals("Generated test name differs from expected", "testValuesTakingNoArguments", nameTest2);
}
use of org.evosuite.testcase.statements.numeric.IntPrimitiveStatement in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testIDNamingWithSameMethodGoals.
@Test
public void testIDNamingWithSameMethodGoals() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>()V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "getPublicID()Ljava/lang/String;");
TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "setPublicID(Ljava/lang/String;)LFooClass;");
// output goals
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "getPublicID()", Type.getType("Ljava.lang.String;"), REF_NONNULL));
TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "setPublicID(Ljava/lang/String;)", Type.getType("LFooClass;"), REF_NONNULL));
DefaultTestCase test1 = new DefaultTestCase();
// any statement to fool hashcode function
test1.addStatement(new IntPrimitiveStatement(test1, 1));
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal4);
DefaultTestCase test2 = new DefaultTestCase();
// any statement to fool hashcode function
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal3);
test2.addCoveredGoal(goal5);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
// TODO: testGetPublicID ?
assertEquals("Generated test name differs from expected", "testGetPublicIDTakingNoArguments", nameTest1);
// TODO: testSetPublicID ?
assertEquals("Generated test name differs from expected", "testSetPublicIDTakingString", nameTest2);
}
use of org.evosuite.testcase.statements.numeric.IntPrimitiveStatement in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testConstructors.
@Test
public void testConstructors() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// method goal
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
// exception goal
TestFitnessFunction goal2 = new ExceptionCoverageTestFitness("FooClass", "<init>(LFooClass;)V", ArrayIndexOutOfBoundsException.class, ExceptionCoverageTestFitness.ExceptionType.IMPLICIT);
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal2);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
assertEquals("Generated test name differs from expected", "testCreatesFooClass", nameTest1);
assertEquals("Generated test name differs from expected", "testFailsToCreateFooClassThrowsArrayIndexOutOfBoundsException", nameTest2);
}
use of org.evosuite.testcase.statements.numeric.IntPrimitiveStatement in project evosuite by EvoSuite.
the class TestMethodNamingComplexExamples method testOverloadedMethods.
@Test
public void testOverloadedMethods() throws NoSuchMethodException, ConstructionFailedException, ClassNotFoundException {
// Method goals
TestFitnessFunction goal1 = new MethodCoverageTestFitness("FooClass", "<init>(LFooClass;)V");
TestFitnessFunction goal2 = new MethodCoverageTestFitness("FooClass", "values([B)[B");
TestFitnessFunction goal3 = new MethodCoverageTestFitness("FooClass", "values([I)[B");
// Output goals for method values
TestFitnessFunction goal4 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([B)", Type.getType("[B"), ARRAY_EMPTY));
TestFitnessFunction goal5 = new OutputCoverageTestFitness(new OutputCoverageGoal("FooClass", "values([I)", Type.getType("[B"), ARRAY_NONEMPTY));
DefaultTestCase test1 = new DefaultTestCase();
test1.addCoveredGoal(goal1);
test1.addCoveredGoal(goal2);
test1.addCoveredGoal(goal4);
DefaultTestCase test2 = new DefaultTestCase();
// Need to add statements to change hashCode
test2.addStatement(new IntPrimitiveStatement(test2, 2));
test2.addCoveredGoal(goal1);
test2.addCoveredGoal(goal3);
test2.addCoveredGoal(goal5);
ArrayList<TestCase> testCases = new ArrayList<>();
testCases.add(test1);
testCases.add(test2);
CoverageGoalTestNameGenerationStrategy naming = new CoverageGoalTestNameGenerationStrategy(testCases);
String nameTest1 = naming.getName(test1);
String nameTest2 = naming.getName(test2);
assertEquals("Generated test name differs from expected", "testValuesTakingByteArray", nameTest1);
assertEquals("Generated test name differs from expected", "testValuesTakingIntArray", nameTest2);
}
use of org.evosuite.testcase.statements.numeric.IntPrimitiveStatement in project evosuite by EvoSuite.
the class TestSimilarity method testBasicSimilarityDifferentTypes.
@Test
public void testBasicSimilarityDifferentTypes() {
TestCase test1 = new DefaultTestCase();
TestCase test2 = new DefaultTestCase();
PrimitiveStatement<?> aInt = new IntPrimitiveStatement(test1, 42);
test1.addStatement(aInt);
PrimitiveStatement<?> aInt2 = new IntPrimitiveStatement(test1, 42);
test1.addStatement(aInt2);
PrimitiveStatement<?> bInt = new IntPrimitiveStatement(test2, 42);
test2.addStatement(bInt);
Constructor<?> c = Object.class.getConstructors()[0];
ConstructorStatement cs = new ConstructorStatement(test2, new GenericConstructor(c, Object.class), new ArrayList<VariableReference>());
test2.addStatement(cs);
double score = DiversityObserver.getNeedlemanWunschScore(test1, test2);
Assert.assertTrue(score <= 0);
}
Aggregations