com.pholser.junit.quickcheck.generator.Generator.canShrink()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中com.pholser.junit.quickcheck.generator.Generator.canShrink()方法的一些代码示例,展示了Generator.canShrink()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Generator.canShrink()方法的具体详情如下:
包路径:com.pholser.junit.quickcheck.generator.Generator
类名称:Generator
方法名:canShrink

Generator.canShrink介绍

[英]Tells whether this generator is allowed to participate in the Shrink process for the given "larger" value.

Unless overridden, the only criterion for whether a generator is allowed to participate in shrinking a value is if the value can be safely cast to the type of values the generator produces.
[中]说明是否允许此生成器参与给定“较大”值的收缩过程。
除非重写,否则是否允许生成器参与收缩值的唯一标准是该值是否可以安全地转换为生成器生成的值类型。

代码示例

代码示例来源:origin: pholser/junit-quickcheck

@Override
public boolean canShrink(Object larger) {
  return delegate.canShrink(larger);
}

代码示例来源:origin: pholser/junit-quickcheck

@Override public boolean canShrink(Object larger) {
  return composed.stream()
    .map(w -> w.item)
    .anyMatch(g -> g.canShrink(larger));
}

代码示例来源:origin: pholser/junit-quickcheck

public BigDecimal magnitude(Object value) {
  return generator.canShrink(value)
    ? generator.magnitude(value).abs()
    : ZERO;
}

代码示例来源:origin: pholser/junit-quickcheck

@Override public BigDecimal magnitude(Object value) {
  List<Weighted<Generator<?>>> shrinkers =
    composed.stream()
      .filter(w -> w.item.canShrink(value))
      .collect(toList());
  return shrinkers.get(0).item.magnitude(value);
}

代码示例来源:origin: pholser/junit-quickcheck

@Override public boolean canShrink(Object larger) {
  return super.canShrink(larger) && codePointsInRange((String) larger);
}

代码示例来源: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

/**
 * {@inheritDoc}
 *
 * <p>Generators first ensure that they {@linkplain #canShrink(Object) can
 * participate} in shrinking the given value, and if so, they
 * {@linkplain #doShrink(SourceOfRandomness, Object) produce shrinks}.</p>
 */
@Override public final List<T> shrink(SourceOfRandomness random, Object larger) {
  if (!canShrink(larger)) {
    throw new IllegalStateException(
      getClass() + " not capable of shrinking " + larger);
  }
  return doShrink(random, narrow(larger));
}

代码示例来源:origin: pholser/junit-quickcheck

@Test public void capabilityOfShrinkingDependsOnComponents() {
  when(first.canShrink(9)).thenReturn(true);
  when(second.canShrink(9)).thenReturn(false);
  when(third.canShrink(9)).thenReturn(true);
  assertTrue(composite.canShrink(9));
}

代码示例来源:origin: pholser/junit-quickcheck

@Test public void capabilityOfShrinkingFalseIfNoComponentsCanShrinkAValue() {
  when(first.canShrink(8)).thenReturn(false);
  when(second.canShrink(8)).thenReturn(false);
  when(third.canShrink(8)).thenReturn(false);
  assertFalse(composite.canShrink(8));
}

代码示例来源:origin: pholser/junit-quickcheck

@Test public void abilityToShrink() {
  assertTrue(generator.canShrink(new Object()));
}

代码示例来源:origin: pholser/junit-quickcheck

@Test public void shrinkingChoosesAComponentCapableOfShrinkingTheValue() {
    stub(first.canShrink(7)).toReturn(true);
    stub(second.canShrink(7)).toReturn(false);
    stub(third.canShrink(7)).toReturn(true);
    when(first.types()).thenReturn(singletonList(Integer.class));
    when(first.doShrink(random, 7)).thenReturn(asList(3, 6));
    when(random.nextInt(9)).thenReturn(1);

    assertEquals(asList(3, 6), composite.shrink(random, 7));
    verify(first, atLeastOnce()).doShrink(random, 7);
  }
}

代码示例来源:origin: com.pholser/junit-quickcheck-core

@Override public boolean canShrink(Object larger) {
  return composed.stream()
    .map(w -> w.item)
    .anyMatch(g -> g.canShrink(larger));
}

代码示例来源:origin: com.pholser/junit-quickcheck-core

@Override public BigDecimal magnitude(Object value) {
  List<Weighted<Generator<?>>> shrinkers =
    composed.stream()
      .filter(w -> w.item.canShrink(value))
      .collect(toList());
  return shrinkers.get(0).item.magnitude(value);
}

代码示例来源:origin: com.pholser/junit-quickcheck-core

public BigDecimal magnitude(Object value) {
  return generator.canShrink(value)
    ? generator.magnitude(value).abs()
    : ZERO;
}

代码示例来源:origin: com.pholser/junit-quickcheck-generators

@Override public boolean canShrink(Object larger) {
  return super.canShrink(larger) && codePointsInRange((String) larger);
}

代码示例来源: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();
}

代码示例来源:origin: com.pholser/junit-quickcheck-core

/**
 * {@inheritDoc}
 *
 * <p>Generators first ensure that they {@linkplain #canShrink(Object) can
 * participate} in shrinking the given value, and if so, they
 * {@linkplain #doShrink(SourceOfRandomness, Object) produce shrinks}.</p>
 */
@Override public final List<T> shrink(SourceOfRandomness random, Object larger) {
  if (!canShrink(larger)) {
    throw new IllegalStateException(
      getClass() + " not capable of shrinking " + larger);
  }
  return doShrink(random, narrow(larger));
}

相关文章