Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Scalacheck/Scalatest PropertyCheckConfig being ignored?

I have a project with a lot of Scalacheck generators that is getting a GeneratorDrivenPropertyCheckFailedException with the message "Gave up after 0 successful property evaluations. 2 evaluations were discarded."

I want to have it try to evaluate it many more times like 500 (the default) would be fine, but I'm not seeing my configuration override actually being used.

I added this code to the test class and I'm still getting the exact same message. I've tried 'sbt clean' just to make sure something weird wasn't happening there.

implicit override val generatorDrivenConfig = PropertyCheckConfig(minSuccessful = 1, maxDiscarded = 500, workers = 1)

Why is my Scalacheck/Scalatest PropertyCheckConfig being ignored?

I'm using Scalatest 2.2.1 with Scalacheck 1.12.1 with Scala 2.10.4

like image 463
myyk Avatar asked Jan 06 '15 02:01

myyk


1 Answers

If you are filtering the generator (for instance, by using a suchThat), the generator can be creating a large number of values that don't satisfy your suchThat constraint and are therefore getting discarded. I've run into this when I constrain the length of strings. The one suggestion I can give you is to try and create your Gen a different way where you aren't discarding so many of them.

For example, here is what I first had for generating 4-character strings:

val gen4CharString = Gen.listOfN(4, (Gen.listOfN[Char] suchThat (s => s != "" && s.length == 4)))

This was causing too many generated values to be discarded, resulting in an error similar to the one you were seeing. Altering the generator like below eliminated the problem.

val gen4CharString = Gen.listOfN[Char] (4, Gen.alphaChar).map (_.mkString)
like image 93
Ram Rajamony Avatar answered Nov 15 '22 20:11

Ram Rajamony