Skip to content

Commit

Permalink
Implemented shrinkingSuggestions() for lazy()
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink committed Feb 3, 2020
1 parent 376a974 commit c544864
Showing 1 changed file with 13 additions and 7 deletions.
Expand Up @@ -80,6 +80,19 @@ void unique(@ForAll Random random) {
assertThat(suggestedValues).containsExactlyElementsOf(expectedValues);
}

@Property(tries = 10)
void lazy(@ForAll Random random) {
Arbitrary<Integer> arbitrary =
Arbitraries.lazy(() -> Arbitraries.of(1, 2, 3, 4, 5, 6));

Shrinkable<Integer> shrinkable = generateValue(arbitrary, 3);

Stream<Integer> suggestedValues = suggestedValues(shrinkable);
assertThat(suggestedValues).containsOnly(1, 2);
}



private <T> Stream<T> suggestedValues(Shrinkable<T> shrinkable) {
List<Shrinkable<T>> suggestions = shrinkable.shrinkingSuggestions();
return suggestions.stream().map(Shrinkable::value);
Expand All @@ -90,13 +103,6 @@ private <T> Shrinkable<T> generateValue(Arbitrary<T> arbitrary, T target) {
return generateUntil(generator, SourceOfRandomness.current(), value -> value.equals(target));
}

// @Property(tries = 10)
// void lazy(@ForAll Random random) {
// Arbitrary<Integer> arbitrary =
// Arbitraries.lazy(() -> Arbitraries.of(1, 2, 3, 4, 5, 6));
// assertAllValuesAreShrunkTo(1, arbitrary, random);
// }
//
// @Property(tries = 10)
// boolean forType(@ForAll Random random) {
// Arbitrary<Counter> arbitrary = Arbitraries.forType(Counter.class);
Expand Down

0 comments on commit c544864

Please sign in to comment.