org.scalacheck.ops

Note:

if you would like joda DateTime implicits to be included (as they were in past versions of scalacheck-ops), you will need to include the scalacheck-ops-joda library and import org.scalacheck.ops.time.joda._.

Type members

Classlikes

final class GenConfig
Companion:
object
object GenConfig
Companion:
class
sealed class GenExceededRetryLimit extends Exception

An exception thrown when a value cannot be pulled out from the Gen.sample method after a number of tries.

An exception thrown when a value cannot be pulled out from the Gen.sample method after a number of tries.

TODO: Convert to final class in next major version.

Companion:
object
final class GenFromConfig[T](gen: Gen[T], config: GenConfig, typeName: String)
final class GenFromConfigBuilder[T](gen: Gen[T]) extends AnyVal
final class GenOfPartiallyApplied[C[_]](dummy: Boolean) extends AnyVal
object GenOps
Companion:
class
final class GenOps[T](val gen: Gen[T]) extends AnyVal

Mixin for some helpful implicits when dealing with ScalaCheck generator monads.

Mixin for some helpful implicits when dealing with ScalaCheck generator monads.

Allows for better mixing of property checks with normal single take test cases with randomized values.

Companion:
object
trait SeedExtractor[-V]

A typeclass representing how convert the given type of seed value into a long so that it can be mixed in with the underlying random number generator org.scalacheck.rng.Seed.

A typeclass representing how convert the given type of seed value into a long so that it can be mixed in with the underlying random number generator org.scalacheck.rng.Seed.

Companion:
object
Companion:
class
final class SeededGen[S, T <: Tag, V](genFn: S @@ T => Gen[V])(implicit extractor: SeedExtractor[S])

Used instead of a Gen to require the caller to provide a rallyId that is used to deterministically alter the underlying seed of the resulting generator.

Used instead of a Gen to require the caller to provide a rallyId that is used to deterministically alter the underlying seed of the resulting generator.

If you use a SeededGen, the resulting generator will always generate the same results for the same seed.

Type parameters:
S

the seed type, must have an implicit SeedExtractor to mix in with the starting seed

T

the type of org.scalacheck.ops.SeededGen.Tag used to avoid exposing implicit type arguments on primitive values

V

the type of value produced by the generator

Value parameters:
genFn

a function from seed (typically implicit) to a generator

Note:

You only need to use this if you want to require the caller to pass a seed OR your generator depends on the value of the seed provided (passed along implicitly). Using a plain Gen will work as expected in all other contexts.

 trait ID extends SeededGen.Tag
 val genNamespacedID = SeededGen[String, ID, String] { implicit id =>
   for {
     inner <- Gen.identifier // doesn't need to be a SeededGen
   } yield s"thing-$id-$inner"
 }
 assert(gen.instance("1") startsWith "thing-1-")

You can treat a SeededGen as a Gen when inside the definition of a SeededGen if you make the given seed implicit.

 val gen = SeededGen[String, ID, Map[String, String]] { implicit id =>
   for {
     namespacedID <- genNamespacedID // implicitly converted from SeededGen to Gen because of the implicit id
     rank <- Gen.choose(1, 10)
   } yield Map(
     "id" -> namespacedID,
     "rank" -> rank.toString
   )
 }

Typically, it is most convenient to define a SeededGen alias so that you can benefit from type inference and hide the often repeated seed and tag types. For this, you should define an object that extends SeededGen#Companion. Instead of defining map and flatMap methods, this pattern opts to implicitly convert your SeededGen into a Gen where these methods are defined. This makes it easier to interlace Gen with SeededGen in the same for-yield comprehension. In order to access the seed, you can call your SeededGen builder and pass a block of code that takes an implicit seed and produces a Gen. In places where you don't want to define a full SeededGen, but you need access to the seed, you can use andThenWithSeed. If you don't need access to the seed, you can call andThen which will allow you to alter the underlying generator while keeping everything inside of a SeededGen.

Companion:
object
object SeededGen
Companion:
class
final class TypeName[T]
Companion:
object
Companion:
class

Deprecated classlikes

class EmptyGenSampleException[T](val generator: Gen[T], attempts: Long)(implicit evidence$1: ClassTag[T]) extends GenExceededRetryLimit

An exception thrown when a value cannot be pulled out from the Gen.sample method after a number of tries.

An exception thrown when a value cannot be pulled out from the Gen.sample method after a number of tries.

Deprecated
class GenOrThrow[T](val gen: Gen[T])(implicit evidence$1: ClassTag[T])

Provides the ability to convert a Gen into an Iterator

Provides the ability to convert a Gen into an Iterator

Type parameters:
T

the type of value produced by the generator

Value parameters:
gen

a generator of some kind

Deprecated

Value members

Deprecated and Inherited methods

def genToGenOrThrow[T : ClassTag](generator: Gen[T]): GenOrThrow[T]
Deprecated
Inherited from:
ScalaCheckImplicits

Implicits

Inherited implicits

implicit val arbChronology: Arbitrary[Chronology]
implicit val arbInstant: Arbitrary[Instant]
implicit val arbLocalDate: Arbitrary[LocalDate]
implicit lazy val arbLocalDateTime: Arbitrary[LocalDateTime]
implicit val arbLocalTime: Arbitrary[LocalTime]
implicit lazy val arbOffsetDateTime: Arbitrary[OffsetDateTime]
implicit val arbZoneId: Arbitrary[ZoneId]
implicit lazy val arbZonedDateTime: Arbitrary[ZonedDateTime]
implicit def genArbitrary[T](gen: Gen[T]): Arbitrary[T]

Converts a Gen to an Arbitrary so that you can pass a Gen anywhere that requires an Arbitrary.

Converts a Gen to an Arbitrary so that you can pass a Gen anywhere that requires an Arbitrary.

This seems like a good default:

 implicit val arbThing: Arbitrary[T] = genThing
Note:

this does not implicitly convert implicit Gens into Arbitrary, (1) this would undermine the purpose of having a separate Arbitrary type (2) making a Gen implicit is not a standard pattern anyway

Inherited from:
ArbitraryAsGen
implicit def genFromConfigBuilder[T](gen: Gen[T]): GenFromConfigBuilder[T]
Inherited from:
ImplicitGenFromConfig
implicit def genFromConfigOps[T](gen: Gen[T])(implicit gc: GenConfig, tn: TypeName[T]): GenFromConfig[T]
Inherited from:
ImplicitGenFromConfig
implicit def genObjectToGenOps(gen: Gen.type): GenOps.type
Inherited from:
ScalaCheckImplicits
implicit def genToGenOps[T](gen: Gen[T]): GenOps[T]
Inherited from:
ScalaCheckImplicits
implicit def shrinkTuple10[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple11[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple12[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple13[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple14[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink, N : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M, N)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple15[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink, N : Shrink, O : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple16[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink, N : Shrink, O : Shrink, P : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple17[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink, N : Shrink, O : Shrink, P : Shrink, Q : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple18[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink, N : Shrink, O : Shrink, P : Shrink, Q : Shrink, R : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple19[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink, N : Shrink, O : Shrink, P : Shrink, Q : Shrink, R : Shrink, S : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple20[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink, N : Shrink, O : Shrink, P : Shrink, Q : Shrink, R : Shrink, S : Shrink, T : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple21[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink, N : Shrink, O : Shrink, P : Shrink, Q : Shrink, R : Shrink, S : Shrink, T : Shrink, U : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)]
Inherited from:
ShrinkLargeTuples
implicit def shrinkTuple22[A : Shrink, B : Shrink, C : Shrink, D : Shrink, E : Shrink, F : Shrink, G : Shrink, H : Shrink, I : Shrink, J : Shrink, K : Shrink, L : Shrink, M : Shrink, N : Shrink, O : Shrink, P : Shrink, Q : Shrink, R : Shrink, S : Shrink, T : Shrink, U : Shrink, V : Shrink]: Shrink[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)]
Inherited from:
ShrinkLargeTuples
implicit def toJavaTimeGenOps(gen: Gen.type): JavaTimeGenOps.type
Inherited from:
JavaTimeImplicits
implicit def truncatedInstantGen(instantGen: Gen[Instant]): TruncatedInstantGen
implicit def truncatedLocalDateTimeGen(localDateTimeGen: Gen[LocalDateTime]): TruncatedLocalDateTimeGen

Deprecated and Inherited implicits

implicit def arbitraryGen[T](implicit arb: Arbitrary[T]): Gen[T]
Deprecated
Inherited from:
ArbitraryAsGen