本文整理汇总了Java中com.pholser.junit.quickcheck.random.SourceOfRandomness类的典型用法代码示例。如果您正苦于以下问题:Java SourceOfRandomness类的具体用法?Java SourceOfRandomness怎么用?Java SourceOfRandomness使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SourceOfRandomness类属于com.pholser.junit.quickcheck.random包,在下文中一共展示了SourceOfRandomness类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public Operation generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
switch (sourceOfRandomness.nextInt(18)) {
case 0: return new Put(randomKey(sourceOfRandomness), sourceOfRandomness.nextInt());
case 1: return new Get(randomKey(sourceOfRandomness));
case 2: return new LowerEntry(randomKey(sourceOfRandomness));
case 3: return new FloorEntry(randomKey(sourceOfRandomness));
case 4: return new HigherEntry(randomKey(sourceOfRandomness));
case 5: return new CeilingEntry(randomKey(sourceOfRandomness));
case 6: return new Size();
case 7: return new FirstEntry();
case 8: return new LastEntry();
case 9: return new Values();
case 10: return new DescendingValues();
case 11: return new TailMap(randomKey(sourceOfRandomness));
case 12: return new TailMapExclusive(randomKey(sourceOfRandomness));
case 13: return new HeadMap(randomKey(sourceOfRandomness));
case 14: return new HeadMapExclusive(randomKey(sourceOfRandomness));
case 15: return new DescendingTailMap(randomKey(sourceOfRandomness));
case 16: return new DescendingTailMapExclusive(randomKey(sourceOfRandomness));
case 17: return new Remove(randomKey(sourceOfRandomness));
default: throw new IllegalStateException();
}
}
示例2: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public Object generate(SourceOfRandomness random, GenerationStatus status) {
final Constructor<?> constructor = Stream.of(resolveConstructors(aClass, random))
.max((o1, o2) -> Integer.valueOf(o1.getParameterCount()).compareTo(o2.getParameterCount()))
.orElseThrow(() -> new IllegalAccessError("Cannot find constructor for type: " + aClass));
constructor.setAccessible(true);
final List<Object> generatedArgs = Stream.of(constructor.getGenericParameterTypes())
.map(generatorFunction)
.map(generator -> generator.generate(new SourceOfRandomness(new Random()), statusSupplier.get()))
.collect(Collectors.toList());
try {
if (generatedArgs.isEmpty()) {
final Object bean = constructor.newInstance();
Stream.of(bean.getClass().getDeclaredFields())
.filter(field -> !Modifier.isStatic(field.getModifiers()))
.filter(field -> !Modifier.isFinal(field.getModifiers()))
.peek(field -> field.setAccessible(true))
.forEach(field -> setRandomFieldValue(bean, field, random));
return bean;
}
return constructor.newInstance(generatedArgs.toArray());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
示例3: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public ConcatVector generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
ConcatVector v = new ConcatVector(CONCAT_VEC_COMPONENTS);
for (int x = 0; x < CONCAT_VEC_COMPONENTS; x++) {
if (sourceOfRandomness.nextBoolean()) {
v.setSparseComponent(x, sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH), sourceOfRandomness.nextDouble());
}
else {
double[] val = new double[sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH)];
for (int y = 0; y < val.length; y++) {
val[y] = sourceOfRandomness.nextDouble();
}
v.setDenseComponent(x, val);
}
}
return v;
}
示例4: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public GraphicalModel generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
GraphicalModel model = new GraphicalModel();
// Create the variables and factors. These are deliberately tiny so that the brute force approach is tractable
int[] variableSizes = new int[sourceOfRandomness.nextInt(10, 50)];
for (int i = 0; i < variableSizes.length; i++) {
variableSizes[i] = sourceOfRandomness.nextInt(1, 8);
}
model.getModelMetaDataByReference().put(MTurkHumanSource.QUERY_JSON, "{}");
for (int i = 0; i < variableSizes.length; i++) {
model.getVariableMetaDataByReference(i).put(MTurkHumanSource.QUERY_JSON, "{}");
}
return model;
}
示例5: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public ConcatVector generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
ConcatVector v = new ConcatVector(CONCAT_VEC_COMPONENTS);
for (int x = 0; x < CONCAT_VEC_COMPONENTS; x++) {
if (sourceOfRandomness.nextBoolean()) {
v.setSparseComponent(x, sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH), sourceOfRandomness.nextDouble());
} else {
double[] val = new double[sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH)];
for (int y = 0; y < val.length; y++) {
val[y] = 2.0 * (sourceOfRandomness.nextDouble() - 0.5);
}
v.setDenseComponent(x, val);
}
}
return v;
}
示例6: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public ConcatVector generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
ConcatVector v = new ConcatVector(CONCAT_VEC_COMPONENTS);
for (int x = 0; x < CONCAT_VEC_COMPONENTS; x++) {
if (sourceOfRandomness.nextBoolean()) {
v.setSparseComponent(x, sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH), sourceOfRandomness.nextDouble());
} else {
double[] val = new double[sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH)];
for (int y = 0; y < val.length; y++) {
val[y] = sourceOfRandomness.nextDouble();
}
v.setDenseComponent(x, val);
}
}
return v;
}
示例7: recursivelyFillArray
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
private static void recursivelyFillArray(List<Integer> assignmentSoFar, NDDoubleArrayWithGold testPair, SourceOfRandomness sourceOfRandomness) {
if (assignmentSoFar.size() == testPair.array.getDimensions().length) {
int[] arr = new int[assignmentSoFar.size()];
for (int i = 0; i < arr.length; i++) {
arr[i] = assignmentSoFar.get(i);
}
double value = sourceOfRandomness.nextDouble();
testPair.array.setAssignmentValue(arr, value);
testPair.gold.put(arr, value);
} else {
for (int i = 0; i < testPair.array.getDimensions()[assignmentSoFar.size()]; i++) {
List<Integer> newList = new ArrayList<>();
newList.addAll(assignmentSoFar);
newList.add(i);
recursivelyFillArray(newList, testPair, sourceOfRandomness);
}
}
}
示例8: recursivelyFillArray
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
private static void recursivelyFillArray(List<Integer> assignmentSoFar, NDArrayWithGold<Double> testPair, SourceOfRandomness sourceOfRandomness) {
if (assignmentSoFar.size() == testPair.array.getDimensions().length) {
int[] arr = new int[assignmentSoFar.size()];
for (int i = 0; i < arr.length; i++) {
arr[i] = assignmentSoFar.get(i);
}
double value = sourceOfRandomness.nextDouble();
testPair.array.setAssignmentValue(arr, value);
testPair.gold.put(arr, value);
}
else {
for (int i = 0; i < testPair.array.getDimensions()[assignmentSoFar.size()]; i++) {
List<Integer> newList = new ArrayList<>();
newList.addAll(assignmentSoFar);
newList.add(i);
recursivelyFillArray(newList, testPair, sourceOfRandomness);
}
}
}
示例9: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public T generate(SourceOfRandomness random, GenerationStatus status) {
int size = size(random, status);
T items = empty();
for (int i = 0; i < size; ++i) {
// Object item0 = componentGenerators().get(0).generate(random, status);
// Object item1 = componentGenerators().get(1).generate(random, status);
// Object item2 = componentGenerators().get(2).generate(random, status);
Object triple = componentGenerators().get(3).generate(random, status);
items = (T) items.__insert(triple);
}
return items;
}
示例10: doShrink
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public List<T> doShrink(SourceOfRandomness random, T larger) {
@SuppressWarnings("unchecked")
List<Object> asList = new ArrayList<>(larger);
List<T> shrinks = new ArrayList<>();
shrinks.addAll(removals(asList));
@SuppressWarnings("unchecked")
Shrink<Object> generator = (Shrink<Object>) componentGenerators().get(0);
List<List<Object>> oneItemShrinks = shrinksOfOneItem(random, asList, generator);
shrinks.addAll(oneItemShrinks.stream().map(this::convert).filter(this::inSizeRange)
.collect(Collectors.toList()));
return shrinks;
}
示例11: doShrink
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public List<T> doShrink(SourceOfRandomness random, T larger) {
List<Object> asList = new ArrayList<>(larger);
List<T> shrinks = new ArrayList<>();
shrinks.addAll(removals(asList));
Shrink<Object> generator = (Shrink<Object>) componentGenerators().get(0);
List<List<Object>> oneItemShrinks = shrinksOfOneItem(random, asList, generator);
shrinks.addAll(oneItemShrinks.stream()
.map(this::convert)
.filter(this::inSizeRange)
.collect(Collectors.toList()));
return shrinks;
}
示例12: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public SwitchAction generate(SourceOfRandomness random, GenerationStatus status) {
final boolean nextState = random.nextBoolean();
return new SwitchAction() {
@Override
public void apply(LightSwitch lightSwitch, LightSwitchModel model) {
lightSwitch.switchLight(nextState);
model.hasLight = nextState;
}
@Override
public String toString() {
return "-> " + nextState;
}
};
}
示例13: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public Person generate(final SourceOfRandomness random, final GenerationStatus status)
{
return new Person(
random.nextBoolean() ? Gender.Male : Gender.Female,
random.nextInt(1, 130));
}
示例14: createMaps
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
private static void createMaps(TreeMap<Integer, Integer> expected, NavigableMap<Integer, Integer> actual, int maxSize) {
final SourceOfRandomness sor = new SourceOfRandomness(new Random(1337));
for (int i = 0; i < maxSize; i++) {
final int key = randomKey(sor);
expected.put(key, i);
actual .put(key, i);
}
}
示例15: evaluate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入依赖的package包/类
@Override
public void evaluate() throws Throwable {
for (int i = 0; i < times; i++) {
final Object[] randomArgs = generators.stream()
.map(generator -> generator.generate(new SourceOfRandomness(new Random()), getStatus()))
.toArray();
method.invokeExplosively(target, randomArgs);
}
}