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();
}
}
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));
}
}
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();
}
}
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);
}
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();
}
}
Aggregations