Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scalacheck, generator for lists between size 5 and 12

I can find many examples of setting maximum sizes for generators, but how do I generate lists between a min and max length?

like image 999
Felix Avatar asked Jan 15 '16 13:01

Felix


1 Answers

A neat property about generators is they are composable, so you can simply compose a generator for the length of your list with a listOfN generator.

for {
  numElems <- Gen.choose(5, 12)
  elems <- Gen.listOfN(numElems, elemGenerator)
} yield elems
like image 61
Asa Avatar answered Sep 22 '22 18:09

Asa