本文整理了Java中com.pholser.junit.quickcheck.generator.Generator.shrink()
方法的一些代码示例,展示了Generator.shrink()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Generator.shrink()
方法的具体详情如下:
包路径:com.pholser.junit.quickcheck.generator.Generator
类名称:Generator
方法名:shrink
[英]Generators first ensure that they #canShrink(Object) in shrinking the given value, and if so, they #doShrink(SourceOfRandomness,Object).
[中]生成器首先确保在收缩给定值时可以收缩(对象),如果可以,则可以收缩(随机性源,对象)。
代码示例来源:origin: pholser/junit-quickcheck
@Override public List<Optional> doShrink(
SourceOfRandomness random,
Optional larger) {
if (!larger.isPresent())
return new ArrayList<>();
List<Optional> shrinks = new ArrayList<>();
shrinks.add(Optional.absent());
shrinks.addAll(
componentGenerators().get(0)
.shrink(random, larger.get())
.stream()
.map(Optional::fromNullable)
.collect(toList()));
return shrinks;
}
代码示例来源:origin: pholser/junit-quickcheck
@Override public List<Optional> doShrink(
SourceOfRandomness random,
Optional larger) {
if (!larger.isPresent())
return new ArrayList<>();
List<Optional> shrinks = new ArrayList<>();
shrinks.add(Optional.empty());
shrinks.addAll(
componentGenerators().get(0)
.shrink(random, larger.get())
.stream()
.map(Optional::of)
.collect(toList()));
return shrinks;
}
代码示例来源:origin: pholser/junit-quickcheck
@Override public List<Object> doShrink(SourceOfRandomness random, Object larger) {
List<Weighted<Generator<?>>> shrinkers =
composed.stream()
.filter(w -> w.item.canShrink(larger))
.collect(toList());
Generator<?> choice = Items.chooseWeighted(shrinkers, random);
return new ArrayList<>(choice.shrink(random, larger));
}
代码示例来源:origin: pholser/junit-quickcheck
public List<Object> shrink(Object larger) {
return generator.canShrink(larger)
? new ArrayList<>(generator.shrink(random(), larger))
: emptyList();
}
代码示例来源:origin: pholser/junit-quickcheck
@Override public List<Segment> doShrink(
SourceOfRandomness r,
Segment larger) {
Generator<Point> pointGen = gen().type(Point.class);
return zip(
pointGen.shrink(r, larger.a).stream(),
pointGen.shrink(r, larger.b).stream(),
Segment::new
).collect(toList());
}
}
代码示例来源:origin: pholser/junit-quickcheck
@Override public List<Either> doShrink(
SourceOfRandomness random,
Either larger) {
@SuppressWarnings("unchecked")
Either<Object, Object> either = (Either<Object, Object>) larger;
return either.map(
left -> componentGenerators().get(0).shrink(random, left)
.stream()
.map(Either::makeLeft)
.collect(toList()),
right -> componentGenerators().get(1).shrink(random, right)
.stream()
.map(Either::makeRight)
.collect(toList()));
}
代码示例来源:origin: pholser/junit-quickcheck
@Test public void nonShrinkingGeneratorAttemptingToShrink() {
thrown.expect(IllegalStateException.class);
nonShrinkingGenerator.shrink(null, new Object());
}
}
代码示例来源:origin: pholser/junit-quickcheck
@Override public List<Polygon> doShrink(
SourceOfRandomness r,
Polygon larger) {
Generator<Point> pointGen = gen().type(Point.class);
return singletonList(
new Polygon(
larger.points.stream()
.map(p -> pointGen.shrink(r, p).get(0))
.collect(toList())));
}
}
代码示例来源:origin: pholser/junit-quickcheck
@Test public void actOfShrinking() {
assertEquals(emptyList(), generator.shrink(null, new Object()));
}
代码示例来源:origin: com.pholser/junit-quickcheck-guava
@Override public List<Optional> doShrink(
SourceOfRandomness random,
Optional larger) {
if (!larger.isPresent())
return new ArrayList<>();
List<Optional> shrinks = new ArrayList<>();
shrinks.add(Optional.absent());
shrinks.addAll(
componentGenerators().get(0)
.shrink(random, larger.get())
.stream()
.map(Optional::fromNullable)
.collect(toList()));
return shrinks;
}
代码示例来源:origin: com.pholser/junit-quickcheck-generators
@Override public List<Optional> doShrink(
SourceOfRandomness random,
Optional larger) {
if (!larger.isPresent())
return new ArrayList<>();
List<Optional> shrinks = new ArrayList<>();
shrinks.add(Optional.empty());
shrinks.addAll(
componentGenerators().get(0)
.shrink(random, larger.get())
.stream()
.map(Optional::of)
.collect(toList()));
return shrinks;
}
代码示例来源:origin: com.pholser/junit-quickcheck-core
@Override public List<Object> doShrink(SourceOfRandomness random, Object larger) {
List<Weighted<Generator<?>>> shrinkers =
composed.stream()
.filter(w -> w.item.canShrink(larger))
.collect(toList());
Generator<?> choice = Items.chooseWeighted(shrinkers, random);
return new ArrayList<>(choice.shrink(random, larger));
}
代码示例来源:origin: com.pholser/junit-quickcheck-core
public List<Object> shrink(Object larger) {
return generator.canShrink(larger)
? new ArrayList<>(generator.shrink(random(), larger))
: emptyList();
}
内容来源于网络,如有侵权,请联系作者删除!