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

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

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

Generator.generate介绍

暂无

代码示例

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

private Object[] arguments(SourceOfRandomness random, GenerationStatus status) {
    Object[] args = new Object[parameters.length];

    for (int i = 0; i < args.length; ++i)
      args[i] = parameterGenerators.get(i).generate(random, status);

    return args;
  }
}

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

public Object generate() {
  Object nextValue;
  for (nextValue = generator.generate(random(), this);
    !evaluate(nextValue);
    nextValue = generator.generate(random(), this));
  return nextValue;
}

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

@Override public Object invoke(Object proxy, Method method, Object[] args)
  throws Throwable {
  if (Object.class.equals(method.getDeclaringClass()))
    return handleObjectMethod(proxy, method, args);
  if (method.isDefault())
    return handleDefaultMethod(proxy, method, args);
  SourceOfRandomness source = new SourceOfRandomness(new Random());
  source.setSeed(Arrays.hashCode(args));
  GenerationStatus status =
    new SimpleGenerationStatus(new GeometricDistribution(), source, attempts);
  return returnValueGenerator.generate(source, status);
}

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

@Override public T generate(SourceOfRandomness random, GenerationStatus status) {
  Class<T> type = types().get(0);
  Object generated = instantiate(type);
  for (Field each : fields) {
    setField(
      each,
      generated,
      gen().field(each).generate(random, status),
      true);
  }
  return type.cast(generated);
}

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

@Override public Pair<?, ?> generate(SourceOfRandomness random, GenerationStatus status) {
  return new Pair<>(
    componentGenerators().get(0).generate(random, status),
    componentGenerators().get(1).generate(random, status),
    x != null);
}

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

public static <T> T functionValue(Generator<T> generator, Object[] args) {
    SourceOfRandomness source = new SourceOfRandomness(new Random());
    source.setSeed(Arrays.hashCode(args));
    return generator.generate(source, null);
  }
}

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

@Override public Segment generate(
  SourceOfRandomness r,
  GenerationStatus s) {
  Generator<Point> pointGen = gen().type(Point.class);
  return new Segment(
    pointGen.generate(r, s),
    pointGen.generate(r, s));
}

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

@Override public Either<?, ?> generate(
  SourceOfRandomness random,
  GenerationStatus status) {
  return random.nextBoolean()
    ? makeLeft(componentGenerators().get(0).generate(random, status))
    : makeRight(componentGenerators().get(1).generate(random, status));
}

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

@Test public void choosingFromSubtypes() {
  Generator<? extends Number> g =
    repo.oneOf(Float.class, Double.class, BigDecimal.class);
  Number n = g.generate(random, null);
  assertThat(
    n,
    anyOf(
      instanceOf(Float.class),
      instanceOf(Double.class),
      instanceOf(BigDecimal.class)));
}

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

@Override public B generate(SourceOfRandomness r, GenerationStatus s) {
    String someString = gen().type(String.class).generate(r, s);
    int someInt = gen().type(int.class).generate(r, s);

    return new B(someString, someInt);
  }
}

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

@SuppressWarnings("unchecked")
  @Override public A generate(
    SourceOfRandomness random,
    GenerationStatus status) {
    A a = new A();
    a.foo = (Foo) gen().field(A.class, "foo")
      .generate(random, status);
    a.boxOfFoo = (Box<Foo>) gen().field(A.class, "boxOfFoo")
      .generate(random, status);
    return a;
  }
}

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

@SuppressWarnings("unchecked")
  @Override public A generate(SourceOfRandomness r, GenerationStatus s) {
    String someString = gen().type(String.class).generate(r, s);
    int someInt = gen().type(int.class).generate(r, s);
    Generator<List> listOfB = gen().type(List.class, B.class);

    A a = new A(someString, someInt);
    a.setListOfB(listOfB.generate(r, s));

    return a;
  }
}

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

@SuppressWarnings("unchecked")
  @Override public A generate(
    SourceOfRandomness random,
    GenerationStatus status) {
    A a = new A();
    a.b = gen().type(Box.class, Foo.class).generate(random, status);
    return a;
  }
}

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

@Override public A generate(
    SourceOfRandomness random,
    GenerationStatus status) {
    A a = new A();
    a.foo = gen().type(Foo.class).generate(random, status);
    return a;
  }
}

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

@Override public A generate(
    SourceOfRandomness random,
    GenerationStatus status) {
    A a = new A();
    a.b = gen().constructor(B.class, int.class)
      .generate(random, status);
    return a;
  }
}

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

@Override public A generate(
    SourceOfRandomness random,
    GenerationStatus status) {
    A a = new A();
    a.b = gen().constructor(B.class, Foo.class, Box.class)
      .generate(random, status);
    return a;
  }
}

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

@Override public A generate(
    SourceOfRandomness random,
    GenerationStatus status) {
    A a = new A();
    a.b = gen().type(Box[].class).generate(random, status);
    return a;
  }
}

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

@Override public A generate(
    SourceOfRandomness random,
    GenerationStatus status) {
    A a = new A();
    a.b = gen().fieldsOf(B.class).generate(random, status);
    return a;
  }
}

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

@Override public A generate(
    SourceOfRandomness random,
    GenerationStatus status) {
    A a = new A();
    a.foos = gen().type(Foo[][].class).generate(random, status);
    return a;
  }
}

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

@Test public void choosingFromGenerators() {
    Generator<? extends Number> g = repo.oneOf(new AByte(), new AShort());

    Number n = g.generate(random, null);

    assertThat(
      n,
      anyOf(instanceOf(Byte.class), instanceOf(Short.class)));
  }
}

相关文章