diff options
-rw-r--r-- | src/main/java/au/id/zancanaro/javacheck/Generators.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/au/id/zancanaro/javacheck/Generators.java b/src/main/java/au/id/zancanaro/javacheck/Generators.java index bf1b1b3..eab3eed 100644 --- a/src/main/java/au/id/zancanaro/javacheck/Generators.java +++ b/src/main/java/au/id/zancanaro/javacheck/Generators.java @@ -80,6 +80,19 @@ public final class Generators { }; } + public static <T> Generator<List<T>> listOf(Generator<T> gen, int minElements, int maxElements) { + return (random, size) -> { + Generator<Integer> countGen = sized(s -> integer(minElements, maxElements)); + int count = countGen.generate(random, size).getValue(); + return Generator.list(count, gen).generate(random, size) + .filter(list -> + minElements <= list.size() + && list.size() < maxElements); + }; + } + + ; + public static <T> Generator<List<T>> listOf(Generator<T> gen) { return (random, size) -> { Generator<Integer> countGen = sized(s -> integer(0, s)); |