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

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

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

Generator.magnitude介绍

[英]Gives a hint to the shrinking process as to the magnitude of the given value. The shrinking process will prefer trying values of greater magnitude before values of lesser magnitude. If not overridden, this implementation returns "one".

Note to generator writers: Do not worry about normalizing a magnitude to a positive value; the shrinking mechanism will take care of it.
[中]就给定值的大小给出收缩过程的提示。收缩过程将倾向于在较小值之前尝试较大值。如果未被覆盖,此实现将返回“一”。
*生成器编写者注意:*不要担心将幅值规格化为正值;收缩机制将处理它。

代码示例

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

@Override
  public BigDecimal magnitude(Object value) {
    return delegate.magnitude(value);
  }
}

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

@Override public BigDecimal magnitude(Object value) {
  int length = Array.getLength(value);
  if (length == 0)
    return ZERO;
  BigDecimal elementsMagnitude =
    IntStream.range(0, length)
      .mapToObj(i -> component.magnitude(Array.get(value, i)))
      .reduce(ZERO, BigDecimal::add);
  return BigDecimal.valueOf(length).multiply(elementsMagnitude);
}

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

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

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

@Override public BigDecimal magnitude(Object value) {
  Collection<?> narrowed = narrow(value);
  if (narrowed.isEmpty())
    return ZERO;
  BigDecimal elementsMagnitude =
    narrowed.stream()
      .map(e -> componentGenerators().get(0).magnitude(e))
      .reduce(ZERO, BigDecimal::add);
  return BigDecimal.valueOf(narrowed.size()).multiply(elementsMagnitude);
}

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

@Override public BigDecimal magnitude(Object value) {
  Map<?, ?> narrowed = narrow(value);
  if (narrowed.isEmpty())
    return BigDecimal.ZERO;
  BigDecimal keysMagnitude =
    narrowed.keySet().stream()
      .map(e -> componentGenerators().get(0).magnitude(e))
      .reduce(BigDecimal.ZERO, BigDecimal::add);
  BigDecimal valuesMagnitude =
    narrowed.values().stream()
      .map(e -> componentGenerators().get(1).magnitude(e))
      .reduce(BigDecimal.ZERO, BigDecimal::add);
  return BigDecimal.valueOf(narrowed.size())
    .multiply(keysMagnitude)
    .add(valuesMagnitude);
}

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

@Override public BigDecimal magnitude(Object value) {
    ArrayList<?> narrowed = narrow(value);

    if (narrowed.isEmpty())
      return ZERO;

    BigDecimal elementsMagnitude =
      narrowed.stream()
        .map(e -> componentGenerators().get(0).magnitude(e))
        .reduce(ZERO, BigDecimal::add);
    return BigDecimal.valueOf(narrowed.size()).multiply(elementsMagnitude);
  }
}

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

@Override public BigDecimal magnitude(Object value) {
    HashMap<?, ?> narrowed = narrow(value);

    if (narrowed.isEmpty())
      return ZERO;

    BigDecimal keysMagnitude =
      narrowed.keySet().stream()
        .map(e -> componentGenerators().get(0).magnitude(e))
        .reduce(ZERO, BigDecimal::add);
    BigDecimal valuesMagnitude =
      narrowed.values().stream()
        .map(e -> componentGenerators().get(1).magnitude(e))
        .reduce(ZERO, BigDecimal::add);
    return BigDecimal.valueOf(narrowed.size())
      .multiply(keysMagnitude)
      .add(valuesMagnitude);
  }
}

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

@Override public BigDecimal magnitude(Object value) {
  return componentGenerators().get(0).magnitude(((Box) value).contents());
}

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

@Override public BigDecimal magnitude(Object value) {
  Pair<?, ?> narrowed = narrow(value);
  return componentGenerators().get(0).magnitude(narrowed.first())
    .multiply(componentGenerators().get(1).magnitude(narrowed.second()));
}

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

@Override public BigDecimal magnitude(Object value) {
  int length = Array.getLength(value);
  if (length == 0)
    return ZERO;
  BigDecimal elementsMagnitude =
    IntStream.range(0, length)
      .mapToObj(i -> component.magnitude(Array.get(value, i)))
      .reduce(ZERO, BigDecimal::add);
  return BigDecimal.valueOf(length).multiply(elementsMagnitude);
}

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

@Override public BigDecimal magnitude(Object value) {
  Collection<?> narrowed = narrow(value);
  if (narrowed.isEmpty())
    return ZERO;
  BigDecimal elementsMagnitude =
    narrowed.stream()
      .map(e -> componentGenerators().get(0).magnitude(e))
      .reduce(ZERO, BigDecimal::add);
  return BigDecimal.valueOf(narrowed.size()).multiply(elementsMagnitude);
}

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

@Override public BigDecimal magnitude(Object value) {
  Map<?, ?> narrowed = narrow(value);
  if (narrowed.isEmpty())
    return BigDecimal.ZERO;
  BigDecimal keysMagnitude =
    narrowed.keySet().stream()
      .map(e -> componentGenerators().get(0).magnitude(e))
      .reduce(BigDecimal.ZERO, BigDecimal::add);
  BigDecimal valuesMagnitude =
    narrowed.values().stream()
      .map(e -> componentGenerators().get(1).magnitude(e))
      .reduce(BigDecimal.ZERO, BigDecimal::add);
  return BigDecimal.valueOf(narrowed.size())
    .multiply(keysMagnitude)
    .add(valuesMagnitude);
}

相关文章