shapeless-contrib icon indicating copy to clipboard operation
shapeless-contrib copied to clipboard

Arbitrary[Map[Int, List[Int]]]: Gave up after only 62 passed tests.

Open OlivierBlanvillain opened this issue 10 years ago • 3 comments

I'm getting a weird behavior in scalacheck while generating Map[Int, List[Int]] with an automatically derived Arbitrary. The issue can be reproduced with the following test, to be added to scalacheck/test/scala/ShrinkSpec.scala:

property("map") = {
  forAll(implicitly[Arbitrary[Map[Int, List[Int]]]].arbitrary)(ok)
}

Which leads to a:

[info] ! Map.map: Gave up after only 62 passed tests. 312 tests were discarded.

Any idea of what's going on here? My quick work around is to generate a Map[A, B] from a List[(A, B)] (I also have a generalized version to build anything with a CanBuildFrom from a List):

implicit def arbitraryMap[A, B]
  (implicit a: Arbitrary[List[(A, B)]]): Arbitrary[Map[A, B]] =
    Arbitrary(a.arbitrary.map(_.toMap))

OlivierBlanvillain avatar Jan 22 '16 12:01 OlivierBlanvillain

I would strongly recommend switching to scalacheck-shapeless if that's not too disruptive.

milessabin avatar Jan 22 '16 12:01 milessabin

I've just tried with scalacheck-shapeless and it seams to be affected by the same problem (I get the exact same error in my test).

OlivierBlanvillain avatar Jan 22 '16 13:01 OlivierBlanvillain

I suggest continuing this discussion on a scalacheck-shapeless issue ... @alexarchambault should be able to help out.

milessabin avatar Jan 22 '16 13:01 milessabin