First of all, Scalacheck already has an offset, so in addition to other Int values, 0, 1, -1, Int.MaxValue and Int.MinValue most likely to be selected. Therefore, if you are worried, do not worry about it. Similarly, blank lines are likely to be generated.
But if you want to reproduce this behavior for something else, use Gen.oneOf or Gen.frequency , possibly in combination with Gen.choose . Since oneOf and frequency take Gen as a parameter, you can combine special cases with generator generators.
For example:
val myArb: Arbitrary[Int] = Arbitrary(Gen.frequency( 1 -> -1, 1 -> 0, 1 -> 1, 3 -> Arbitrary.arbInt.arbitrary ))
Pretty much depends on what you requested, with a 50% chance of arbitrary ints (which would be due to the prejudice I spoke of) and 16.6% for each of -1, 0 and 1.
Daniel C. Sobral
source share