Search in sources :

Example 1 with DoublePrimitiveStatement

use of org.evosuite.testcase.statements.numeric.DoublePrimitiveStatement 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 2 with DoublePrimitiveStatement

use of org.evosuite.testcase.statements.numeric.DoublePrimitiveStatement in project evosuite by EvoSuite.

the class TestCaseBuilder method appendDoublePrimitive.

public VariableReference appendDoublePrimitive(double d) {
    DoublePrimitiveStatement primitiveStmt = new DoublePrimitiveStatement(tc, d);
    tc.addStatement(primitiveStmt);
    return primitiveStmt.getReturnValue();
}
Also used : DoublePrimitiveStatement(org.evosuite.testcase.statements.numeric.DoublePrimitiveStatement)

Example 3 with DoublePrimitiveStatement

use of org.evosuite.testcase.statements.numeric.DoublePrimitiveStatement in project evosuite by EvoSuite.

the class LocalSearchNumericSystemTest method getDoubleTest.

private TestCase getDoubleTest(double x, double y) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
    Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
    GenericClass clazz = new GenericClass(sut);
    DefaultTestCase test = new DefaultTestCase();
    GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
    TestFactory testFactory = TestFactory.getInstance();
    VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
    VariableReference intVar1 = test.addStatement(new DoublePrimitiveStatement(test, x));
    VariableReference intVar0 = test.addStatement(new DoublePrimitiveStatement(test, y));
    Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { double.class, double.class });
    GenericMethod method = new GenericMethod(m, sut);
    MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar0, intVar1 }));
    test.addStatement(ms);
    return test;
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) GenericClass(org.evosuite.utils.generic.GenericClass) TestFactory(org.evosuite.testcase.TestFactory) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) DoublePrimitiveStatement(org.evosuite.testcase.statements.numeric.DoublePrimitiveStatement) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod)

Aggregations

DoublePrimitiveStatement (org.evosuite.testcase.statements.numeric.DoublePrimitiveStatement)3 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)2 Method (java.lang.reflect.Method)1 TestCase (org.evosuite.testcase.TestCase)1 TestFactory (org.evosuite.testcase.TestFactory)1 MethodStatement (org.evosuite.testcase.statements.MethodStatement)1 VariableReference (org.evosuite.testcase.variable.VariableReference)1 GenericClass (org.evosuite.utils.generic.GenericClass)1 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)1 GenericMethod (org.evosuite.utils.generic.GenericMethod)1 Test (org.junit.Test)1