Search in sources :

Example 1 with ConstantPool

use of org.evosuite.seeding.ConstantPool in project evosuite by EvoSuite.

the class FloatPrimitiveStatement method randomize.

/* (non-Javadoc)
	 * @see org.evosuite.testcase.PrimitiveStatement#randomize()
	 */
/**
 * {@inheritDoc}
 */
@Override
public void randomize() {
    if (Randomness.nextDouble() >= Properties.PRIMITIVE_POOL) {
        value = (float) (Randomness.nextGaussian() * Properties.MAX_INT);
        int precision = Randomness.nextInt(7);
        chopPrecision(precision);
    } else {
        ConstantPool constantPool = ConstantPoolManager.getInstance().getConstantPool();
        value = constantPool.getRandomFloat();
    }
}
Also used : ConstantPool(org.evosuite.seeding.ConstantPool)

Example 2 with ConstantPool

use of org.evosuite.seeding.ConstantPool in project evosuite by EvoSuite.

the class StringPrimitiveStatement method randomize.

/* (non-Javadoc)
	 * @see org.evosuite.testcase.PrimitiveStatement#randomize()
	 */
/**
 * {@inheritDoc}
 */
@Override
public void randomize() {
    if (Randomness.nextDouble() >= Properties.PRIMITIVE_POOL)
        value = Randomness.nextString(Randomness.nextInt(Properties.STRING_LENGTH));
    else {
        ConstantPool constantPool = ConstantPoolManager.getInstance().getConstantPool();
        String candidateString = constantPool.getRandomString();
        if (Properties.MAX_STRING > 0 && candidateString.length() < Properties.MAX_STRING)
            value = candidateString;
        else
            value = Randomness.nextString(Randomness.nextInt(Properties.STRING_LENGTH));
    }
}
Also used : ConstantPool(org.evosuite.seeding.ConstantPool)

Example 3 with ConstantPool

use of org.evosuite.seeding.ConstantPool in project evosuite by EvoSuite.

the class ShortPrimitiveStatement method randomize.

/* (non-Javadoc)
	 * @see org.evosuite.testcase.PrimitiveStatement#randomize()
	 */
/**
 * {@inheritDoc}
 */
@Override
public void randomize() {
    short max = (short) Math.min(Properties.MAX_INT, 32767);
    if (Randomness.nextDouble() >= Properties.PRIMITIVE_POOL) {
        value = (short) ((Randomness.nextGaussian() * max));
    } else {
        ConstantPool constantPool = ConstantPoolManager.getInstance().getConstantPool();
        value = (short) constantPool.getRandomInt();
    }
}
Also used : ConstantPool(org.evosuite.seeding.ConstantPool)

Example 4 with ConstantPool

use of org.evosuite.seeding.ConstantPool in project evosuite by EvoSuite.

the class RemoteAddressPrimitiveStatement method randomize.

@Override
public void randomize() {
    EvoSuiteRemoteAddress addr;
    // TODO parameter
    double threshold = 0.8;
    boolean accessed = Randomness.nextDouble() <= threshold;
    if (accessed && !tc.getAccessedEnvironment().getViewOfRemoteContactedPorts().isEmpty()) {
        // use an address that the SUT tried to contact
        EndPointInfo info = Randomness.choice(tc.getAccessedEnvironment().getViewOfRemoteContactedPorts());
        String host = info.getHost();
        // TODO check why it can be a 0 here
        int port = info.getPort();
        port = getPort(port);
        addr = new EvoSuiteRemoteAddress(host, port);
    } else {
        /*
                make up an address based on string/int constants.
                this is needed to handle the cases when the SUT get
                an incoming message, and then check its remote address.

                TODO: here we could validate if host/port values are
                indeed valid. However, as this is kind of special case,
                and likely not so common, it doesn't have high priority.
             */
        ConstantPool constantPool = ConstantPoolManager.getInstance().getConstantPool();
        String host = constantPool.getRandomString();
        int port = constantPool.getRandomInt();
        port = getPort(port);
        addr = new EvoSuiteRemoteAddress(host, port);
    }
    setValue(addr);
}
Also used : EvoSuiteRemoteAddress(org.evosuite.runtime.testdata.EvoSuiteRemoteAddress) ConstantPool(org.evosuite.seeding.ConstantPool) EndPointInfo(org.evosuite.runtime.vnet.EndPointInfo)

Example 5 with ConstantPool

use of org.evosuite.seeding.ConstantPool in project evosuite by EvoSuite.

the class LongPrimitiveStatement method randomize.

/* (non-Javadoc)
	 * @see org.evosuite.testcase.PrimitiveStatement#randomize()
	 */
/**
 * {@inheritDoc}
 */
@Override
public void randomize() {
    if (Randomness.nextDouble() >= Properties.PRIMITIVE_POOL) {
        value = (long) (Randomness.nextGaussian() * Properties.MAX_INT);
    } else {
        ConstantPool constantPool = ConstantPoolManager.getInstance().getConstantPool();
        value = constantPool.getRandomLong();
    }
}
Also used : ConstantPool(org.evosuite.seeding.ConstantPool)

Aggregations

ConstantPool (org.evosuite.seeding.ConstantPool)8 EvoSuiteRemoteAddress (org.evosuite.runtime.testdata.EvoSuiteRemoteAddress)1 EndPointInfo (org.evosuite.runtime.vnet.EndPointInfo)1