Search in sources :

Example 41 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestDefaultValue method testDouble.

@Test
public void testDouble() throws SecurityException, NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    ArrayReference doubleArray0 = builder.appendArrayStmt(Double[].class, 10);
    VariableReference double0 = builder.appendNull(Double.class);
    builder.appendAssignment(doubleArray0, 0, double0);
    builder.appendAssignment(double0, doubleArray0, 0);
    builder.appendMethod(double0, Double.class.getMethod("floatValue"));
    DefaultTestCase tc = builder.getDefaultTestCase();
    ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
    assertNotNull(ret_val);
    assertFalse(ret_val.explicitExceptions.isEmpty());
}
Also used : ArrayReference(org.evosuite.testcase.variable.ArrayReference) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Test(org.junit.Test)

Example 42 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestDoubleFloatComparison method testDelta.

@Test
public void testDelta() {
    TestCase test = new DefaultTestCase();
    DoublePrimitiveStatement statement1 = new DoublePrimitiveStatement(test);
    DoublePrimitiveStatement statement2 = new DoublePrimitiveStatement(test);
    double d1 = statement1.getValue();
    double d2 = statement2.getValue();
    int val = BooleanHelper.doubleSubG(d1, d2);
    assertEquals(val > 0, d1 > d2);
    assertEquals(val < 0, d1 < d2);
    assertEquals(val == 0, d1 == d2);
    for (int i = 0; i < 100; i++) {
        statement1.delta();
        statement2.delta();
        d1 = statement1.getValue();
        d2 = statement2.getValue();
        val = BooleanHelper.doubleSubG(d1, d2);
        assertEquals(val > 0, d1 > d2);
        assertEquals(val < 0, d1 < d2);
        assertEquals(val == 0, d1 == d2);
    }
    for (int i = 0; i < 100; i++) {
        statement1.randomize();
        statement2.randomize();
        d1 = statement1.getValue();
        d2 = statement2.getValue();
        val = BooleanHelper.doubleSubG(d1, d2);
        assertEquals(val > 0, d1 > d2);
        assertEquals(val < 0, d1 < d2);
        assertEquals(val == 0, d1 == d2);
    }
}
Also used : DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) DoublePrimitiveStatement(org.evosuite.testcase.statements.numeric.DoublePrimitiveStatement) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Test(org.junit.Test)

Example 43 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestOverloading method testOverloadedConstructor.

@Test
public void testOverloadedConstructor() {
    Class<?> clazz = ClassWithOverloadedMethods.class;
    Constructor<?> constructor1 = clazz.getConstructors()[0];
    Constructor<?> constructor2 = clazz.getConstructors()[1];
    GenericConstructor genericConstructor1 = new GenericConstructor(constructor1, clazz);
    GenericConstructor genericConstructor2 = new GenericConstructor(constructor2, clazz);
    TestCase test = new DefaultTestCase();
    ConstantValue intValue = new ConstantValue(test, int.class);
    VariableReference integerVar = new VariableReferenceImpl(test, Integer.class);
    List<VariableReference> parameters = Arrays.asList(intValue, integerVar);
    assertTrue(genericConstructor1.isOverloaded(parameters));
    assertTrue(genericConstructor2.isOverloaded(parameters));
}
Also used : ClassWithOverloadedMethods(com.examples.with.different.packagename.utils.generic.ClassWithOverloadedMethods) VariableReference(org.evosuite.testcase.variable.VariableReference) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) VariableReferenceImpl(org.evosuite.testcase.variable.VariableReferenceImpl) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) ConstantValue(org.evosuite.testcase.variable.ConstantValue) Test(org.junit.Test)

Example 44 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestOverloading method testOverloadedMethod.

@Test
public void testOverloadedMethod() {
    Class<?> clazz = ClassWithOverloadedMethods.class;
    Method method1 = clazz.getMethods()[0];
    Method method2 = clazz.getMethods()[1];
    GenericMethod genericMethod1 = new GenericMethod(method1, clazz);
    GenericMethod genericMethod2 = new GenericMethod(method2, clazz);
    TestCase test = new DefaultTestCase();
    ConstantValue intValue = new ConstantValue(test, int.class);
    VariableReference integerVar = new VariableReferenceImpl(test, Integer.class);
    List<VariableReference> parameters1 = Arrays.asList(intValue);
    List<VariableReference> parameters2 = Arrays.asList(integerVar);
    assertTrue(genericMethod1.isOverloaded());
    assertTrue(genericMethod2.isOverloaded());
    assertTrue(genericMethod1.isOverloaded(parameters1));
    assertTrue(genericMethod2.isOverloaded(parameters1));
    assertTrue(genericMethod1.isOverloaded(parameters2));
    assertTrue(genericMethod2.isOverloaded(parameters2));
}
Also used : ClassWithOverloadedMethods(com.examples.with.different.packagename.utils.generic.ClassWithOverloadedMethods) VariableReference(org.evosuite.testcase.variable.VariableReference) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) VariableReferenceImpl(org.evosuite.testcase.variable.VariableReferenceImpl) Method(java.lang.reflect.Method) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) ConstantValue(org.evosuite.testcase.variable.ConstantValue) Test(org.junit.Test)

Example 45 with DefaultTestCase

use of org.evosuite.testcase.DefaultTestCase in project evosuite by EvoSuite.

the class TestOverloading method testNotOverloadedConstructor.

@Test
public void testNotOverloadedConstructor() {
    Class<?> clazz = ClassWithoutOverloadedMethods.class;
    Constructor<?> constructor1 = clazz.getConstructors()[0];
    Constructor<?> constructor2 = clazz.getConstructors()[1];
    GenericConstructor genericConstructor1 = new GenericConstructor(constructor1, clazz);
    GenericConstructor genericConstructor2 = new GenericConstructor(constructor2, clazz);
    TestCase test = new DefaultTestCase();
    ConstantValue intValue = new ConstantValue(test, int.class);
    VariableReference stringVar = new VariableReferenceImpl(test, String.class);
    List<VariableReference> parameters1 = Arrays.asList(intValue);
    List<VariableReference> parameters2 = Arrays.asList(stringVar);
    assertFalse(genericConstructor1.isOverloaded(parameters1));
    assertFalse(genericConstructor2.isOverloaded(parameters2));
    assertFalse(genericConstructor1.isOverloaded(parameters2));
    assertFalse(genericConstructor2.isOverloaded(parameters1));
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) TestCase(org.evosuite.testcase.TestCase) VariableReferenceImpl(org.evosuite.testcase.variable.VariableReferenceImpl) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) ConstantValue(org.evosuite.testcase.variable.ConstantValue) ClassWithoutOverloadedMethods(com.examples.with.different.packagename.utils.generic.ClassWithoutOverloadedMethods) Test(org.junit.Test)

Aggregations

DefaultTestCase (org.evosuite.testcase.DefaultTestCase)347 Test (org.junit.Test)234 Constraint (org.evosuite.symbolic.expr.Constraint)101 TestCase (org.evosuite.testcase.TestCase)78 ArrayList (java.util.ArrayList)63 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)47 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)45 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)41 VariableReference (org.evosuite.testcase.variable.VariableReference)37 TestCaseStringAppendString (com.examples.with.different.packagename.solver.TestCaseStringAppendString)27 TestCaseStringIndexOfString (com.examples.with.different.packagename.solver.TestCaseStringIndexOfString)27 TestCaseStringLastIndexOfString (com.examples.with.different.packagename.solver.TestCaseStringLastIndexOfString)27 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)27 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)25 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)25 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)18 GenericMethod (org.evosuite.utils.generic.GenericMethod)17 TestChromosome (org.evosuite.testcase.TestChromosome)16 Method (java.lang.reflect.Method)14 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)14