diff --git a/core/jvm/src/test/scala/org/scalacheck/GenSpecification.scala b/core/jvm/src/test/scala/org/scalacheck/GenSpecification.scala index 6f439d8d..32c7dd29 100644 --- a/core/jvm/src/test/scala/org/scalacheck/GenSpecification.scala +++ b/core/jvm/src/test/scala/org/scalacheck/GenSpecification.scala @@ -291,6 +291,24 @@ object GenSpecification extends Properties("Gen") with GenSpecificationVersionSp } } + property("pick produces enough distinct combinations") = { + val (n, nElements, nCombinations) = (3, 5, 10) + // The number of samples to produce with Gen.pick, that is enough to assert + // that every possible combination appears at least once. It depends on + // nSamples, but there is no specific math behind it. Rather, it's just an + // empirically chosen value, that has yielded no failures over thousands of + // test cycles. + val nSamples = 200 + + val genPick = pick(n, 1 to nElements) + // not interested in different permutations, only in distinct combinations + .map(_.sorted) + + forAllNoShrink(listOfN(nSamples, genPick).map(_.distinct)) { distinctCombinations => + distinctCombinations.size == nCombinations + } + } + property("numChar") = forAll(numChar)(_.isDigit) property("calendar") = forAll(calendar) { cal => diff --git a/core/shared/src/main/scala/org/scalacheck/Gen.scala b/core/shared/src/main/scala/org/scalacheck/Gen.scala index da4f491a..7f736f96 100644 --- a/core/shared/src/main/scala/org/scalacheck/Gen.scala +++ b/core/shared/src/main/scala/org/scalacheck/Gen.scala @@ -1092,7 +1092,7 @@ object Gen extends GenArities with GenVersionSpecific { buf += t } else { val (x, s) = seed.long - val i = (x & Long.MaxValue % count).toInt + val i = ((x & Long.MaxValue) % count).toInt if (i < n) buf(i) = t seed = s }