Skip to content

Commit

Permalink
Option Arbitrary delegates to Option Gen
Browse files Browse the repository at this point in the history
Resolves typelevel#401.
  • Loading branch information
ceedubs committed May 12, 2018
1 parent 0f46e16 commit d25d89c
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/main/scala/org/scalacheck/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object Arbitrary extends ArbitraryLowPriority with ArbitraryArities {

/** separate trait to have same priority as ArbitraryArities */
private[scalacheck] sealed trait ArbitraryLowPriority {
import Gen.{const, choose, sized, frequency, oneOf, buildableOf, resize}
import Gen.{const, choose, sized, frequency, oneOf, buildableOf}

/** Creates an Arbitrary instance */
def apply[T](g: => Gen[T]): Arbitrary[T] = new Arbitrary[T] {
Expand Down Expand Up @@ -336,13 +336,7 @@ private[scalacheck] sealed trait ArbitraryLowPriority {

/** Arbitrary instance of the Option type */
implicit def arbOption[T](implicit a: Arbitrary[T]): Arbitrary[Option[T]] =
Arbitrary(sized(n =>
// When n is larger, make it less likely that we generate None,
// but still do it some of the time. When n is zero, we always
// generate None, since it's the smallest value.
frequency(
(n, resize(n / 2, arbitrary[T]).map(Some(_))),
(1, const(None)))))
Arbitrary(Gen.option(a.arbitrary))

/** Arbitrary instance of the Either type */
implicit def arbEither[T, U](implicit at: Arbitrary[T], au: Arbitrary[U]): Arbitrary[Either[T, U]] =
Expand Down

0 comments on commit d25d89c

Please sign in to comment.