Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator fails on nested case classes with sealed traits #46

Open
calippo opened this issue May 27, 2016 · 0 comments
Open

Generator fails on nested case classes with sealed traits #46

calippo opened this issue May 27, 2016 · 0 comments

Comments

@calippo
Copy link

calippo commented May 27, 2016

I'm having trouble trying to generate samples from nested case classes containing sealed traits.
When I try to generate an instance of a nested case class that contains sealed traits, the generator often fails, returning None.

Gen is supposed to fail when filtering is wrong. In my experiments Gen is failing even though I'm not applying any filter (also, it looks like gen.retryUntil(_ => true) is ignored and None is often returned).

I was not able to isolate the problem. Here is my experiment :)

package object models {
  case class C(e: String, f: OffsetDateTime, g: OffsetDateTime, c: Option[String], big: BigInt)
  case class B(e: String, f: OffsetDateTime, g: OffsetDateTime, outcome: Planet, outcome2: Planet, c: C)
  case class A(a: String, b: String, c: Option[String], d: B, outcome: Planet, outcome2: Planet)

  sealed abstract trait Planet
  object Planet {
    case object Earth extends Planet
    case object Sun extends Planet
    case object Moon extends Planet
  }
}

object Test extends App {
  import org.scalacheck.Shapeless._
  import org.scalacheck._
  import models._

  implicit val offsetDateTimeArbitrary: Arbitrary[OffsetDateTime] = Arbitrary(Gen.const(OffsetDateTime.now()))
  val gen = implicitly[Arbitrary[A]].arbitrary

  val n = 1000
  println(Seq.fill(n)(gen.retryUntil(_ => true).sample).flatten.length == n)
}

note: I'm using scala 2.11.7 and "scalacheck-shapeless_1.13" % "1.1.0-RC1".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant