sealed abstract class Arbitrary[T] extends Serializable
Define an arbitrary generator for properties
The Arbitrary module defines implicit generator instances for common types.
The implicit definitions of Arbitrary provide type-directed Gens so they are available for properties, generators, or other definitions of Arbitrary.
ScalaCheck expects an implicit Arbitrary instance is in scope for Props that are defined with functions, like Prop.forAll and so on.
For instance, the definition for Arbitrary[Boolean] is used by
Prop.forAll to automatically provide a Gen[Boolean] when one
of the parameters is a Boolean:
Prop.forAll { (b: Boolean) =>
b || !b
}Thanks to Arbitrary, you don't need to provide an explicit
Gen instance to Prop.forAll. For instance, this is
unnecessary:
val genBool: Gen[Boolean] = Gen.oneOf(true,false) Prop.forAll(genBool) { (b: Boolean) => b || !b }
Since an arbitrary Gen for Boolean is defined in Arbitrary,
it can be summoned with Arbitrary.arbitrary in cases where you
need to provide one explicitly:
val genBool: Gen[Boolean] = Arbitrary.arbitrary[Boolean] val genSmallInt: Gen[Int] = Gen.choose(0, 9) Prop.forAll(genBool, genSmallInt) { (b: Boolean, i: Int) => i < 10 && b || !b }
For a user-defined MyClass, writing the following requires that
there exists an implicit Arbitrary[MyClass] instance:
Prop.forAll { (myClass: MyClass) =>
...
}The implicit definition of Arbitrary[MyClass] would look like:
implicit val arbMyClass: Arbitrary[MyClass] = Arbitrary { ... }
The factory method Arbitrary(...) expects a generator of type
Gen[MyClass] then it will return an instance of Arbitrary[MyClass].
- Source
- Arbitrary.scala
- Alphabetic
- By Inheritance
- Arbitrary
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()