Gen.between
I think is the one I'm thinking of
Apologies in advance for the super vague question - still investigating.
We have some tests that were setting Seed(0)
generating several instances of a fairly large generator.
After doing some rounds of upgrades (Scala 2.12 patch from 12 to 13), we noticed that the values generated are no longer the same.
So my question is - are all Seeds born equal? Could there be something special about our poor choice of seed 0?
Scalacheck is 1.14.0, but 1.15.4 has the same behaviour. I'm really clutching at straws here, everything else failed :)
property("genEntity") = {
val genEntity: Gen[List[Entity]] = {
for {
id <- Arbitrary.arbitrary[Int]
codes <- Gen.containerOf[Set,String](Arbitrary.arbitrary[String])
code <- codes.toList
} yield {
Entity(id, code)
}
}
Prop.forAllNoShrink(genEntity) { (entities: List[Entity]) =>
Prop.collect(entities.size) {
entities.size >= 0
}
}
}
Hi all,
Consider this code:
var seen = 0
var filtered = 0
private val genInt =
Arbitrary
.arbInt
.arbitrary
.map { v => seen += 1; v }
.filter(_ % 2 == 1)
.map { v => filtered += 1; v }
private implicit val arbInt: Arbitrary[Int] = Arbitrary(genInt)
test("uniqueGen") {
var listed = 0
check { ints: List[Int] =>
listed += ints.length
println(s"$seen/$filtered/$listed")
true
}
}
running tests results in Gave up after 5 successful property evaluations. 51 evaluations were discarded.
And the logs are:
0/0/0
4/3/3
114/43/3
310/100/4
0/0/0
0/0/0
4/1/1
19/7/7
155/47/11
From my POV this check should succeed, shoudn't it?
Gen.buildableOfN
) and then your Gen[Int] has a filter for oddsthat causes ScalaCheck to exhaust the number of attempts. You might try retryUntil
instead of filter
but that suggests a different implementation.
generateId
method based on instance of Random. I want to create a generator that produces valid values using that method. But as far as I can see all access to constructors is private in Gen, so I wonder how can I create that one (I will need to access Seed to provide Random based on it to the generateId
method)?