shapeless-contrib
shapeless-contrib copied to clipboard
"Gave up after only n tests." with heavily nested case classes
The following test fails with a message like "! Nested.nested: Gave up after only 7 passed tests. 501 tests were discarded.".
object NestedArbitrarySpec extends Properties("Nested") {
private val ok = (_: Any) => true
case class Mixed(longField: Long, doubleField: Double, stringField: String,
longFieldO: Option[Long], doubleFieldO: Option[Double], stringFieldO: Option[String],
longFieldR: List[Long], doubleFieldR: List[Double], stringFieldR: List[String])
case class Nested(longField: Long, longFieldO: Option[Long], longFieldR: List[Long],
mixedField: Mixed, mixedFieldO: Option[Mixed], mixedFieldR: List[Mixed])
property("nested") = {
forAll(implicitly[Arbitrary[Nested]].arbitrary)(ok)
}
}
I got it to work by removing the resizing logic. I can submit a PR for this but would like to understand better why it's there in the first place.
diff --git a/scalacheck/src/main/scala/package.scala b/scalacheck/src/main/scala/package.scala
index 4d84403..9e6bad5 100644
--- a/scalacheck/src/main/scala/package.scala
+++ b/scalacheck/src/main/scala/package.scala
@@ -13,15 +13,9 @@ object scalacheck {
def emptyProduct = Arbitrary(Gen.const(HNil: HNil))
def product[H, T <: HList](h: Arbitrary[H], t: Arbitrary[T]) =
- Arbitrary(Gen.sized { size =>
- if (size == 0)
- Gen.fail
- else {
- val resizedH = Gen.resize(size.abs/2, h.arbitrary)
- val resizedT = Gen.resize(size.abs - size.abs/2, t.arbitrary)
- for { h <- resizedH; t <- resizedT }
- yield h :: t
- }})
+ Arbitrary {
+ for (h <- h.arbitrary; t <- t.arbitrary) yield h :: t
+ }
def emptyCoproduct = Arbitrary[CNil](_emptyCoproduct)