Ejemplo 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);
  }
Ejemplo n.º 2
0
 private <N> Generator<Pair<P, T>> generatorFunction() {
   return (prng, step) -> {
     P p = ps.next(prng, step);
     return Pair.of(p, conversion.apply(p));
   };
 }
Ejemplo n.º 3
0
 private <N> Shrink<Pair<P, T>> shrinker() {
   return (pair, context) ->
       ps.shrink(pair._1, context).map(pre -> Pair.of(pre, conversion.apply(pre)));
 }