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

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

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

Generator.types介绍

暂无

代码示例

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

NullableGenerator(Generator<T> delegate) {
  super(delegate.types());
  this.delegate = delegate;
}

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

/**
 * <p>Tells whether this generator is allowed to participate in the
 * {@link Shrink} process for the given "larger" value.</p>
 *
 * <p>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.</p>
 *
 * @param larger the "larger" value
 * @return whether this generator can participate in "shrinking" the larger
 * value
 */
public boolean canShrink(Object larger) {
  return types().get(0).isInstance(larger);
}

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

/**
 * <p>Attempts to "narrow" the given object to the type this generator
 * produces.</p>
 *
 * <p>This is intended for use only by junit-quickcheck itself, and not by
 * creators of custom generators.</p>
 *
 * @param wider target of the narrowing
 * @return narrowed the result of the narrowing
 * @throws ClassCastException if the narrowing cannot be performed
 */
protected final T narrow(Object wider) {
  return types().get(0).cast(wider);
}

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

private void registerTypes(Generator<?> generator) {
  for (Class<?> each : generator.types())
    registerHierarchy(each, generator);
}

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

private void ensureCorrectType(Generator<?> generator) {
  org.javaruntype.type.Type<?> parameterTypeToken =
    Types.forJavaLangReflectType(type(), typeVariables);
  for (Class<?> each : generator.types()) {
    if (!maybeWrap(parameterTypeToken.getRawClass()).isAssignableFrom(maybeWrap(each))) {
      throw new IllegalArgumentException(
        format(
          EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE,
          each,
          From.class.getName(),
          parameterName));
    }
  }
}

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

/**
 * <p>Attempts to "narrow" the given object to the type this generator
 * produces.</p>
 *
 * <p>This is intended for use only by junit-quickcheck itself, and not by
 * creators of custom generators.</p>
 *
 * @param wider target of the narrowing
 * @return narrowed the result of the narrowing
 * @throws ClassCastException if the narrowing cannot be performed
 */
protected final T narrow(Object wider) {
  return types().get(0).cast(wider);
}

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

/**
 * <p>Tells whether this generator is allowed to participate in the
 * {@link Shrink} process for the given "larger" value.</p>
 *
 * <p>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.</p>
 *
 * @param larger the "larger" value
 * @return whether this generator can participate in "shrinking" the larger
 * value
 */
public boolean canShrink(Object larger) {
  return types().get(0).isInstance(larger);
}

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

private void registerTypes(Generator<?> generator) {
  for (Class<?> each : generator.types())
    registerHierarchy(each, generator);
}

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

private void ensureCorrectType(Generator<?> generator) {
  org.javaruntype.type.Type<?> parameterTypeToken =
    Types.forJavaLangReflectType(type(), typeVariables);
  for (Class<?> each : generator.types()) {
    if (!maybeWrap(parameterTypeToken.getRawClass()).isAssignableFrom(maybeWrap(each))) {
      throw new IllegalArgumentException(
        format(
          EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE,
          each,
          From.class.getName(),
          parameterName));
    }
  }
}

相关文章