Exemplo n.º 1
0
  /**
   * Converts theory to one about a different type using the given function retaining all precursor
   * values
   *
   * @param <N> type to convert to
   * @param mapping Function from type T to type N
   * @return a Subject2 relating to the state of a theory involving two values
   */
  public <N> Subject2<P, N> asWithPrecursor(Function<T, N> mapping) {
    Generator<Pair<P, N>> g =
        (prng, step) -> {
          P p = this.ps.next(prng, step);
          T t = this.conversion.apply(p);
          return Pair.of(p, mapping.apply(t));
        };

    Shrink<Pair<P, N>> s =
        (original, context) ->
            ps.shrink(original._1, context)
                .map(p -> Pair.of(p, conversion.andThen(mapping).apply(p)));

    Source<Pair<P, N>> gen = Source.of(g).withShrinker(s);
    return new PrecursorTheoryBuilder1<P, N>(state, gen, assumptions);
  }
Exemplo n.º 2
0
 private <N> Source<Pair<P, T>> convertedSource(Function<T, N> conversion2) {
   return Source.of(generatorFunction()).withShrinker(shrinker());
 }