Companion to the Generator trait, which contains many of the standard implicit Generators.
For the most part, you should not need to use the values and functions in here directly; the useful values in here are generally aliased in CommonGenerators (albeit with different names), which in turn is mixed into GeneratorDrivenPropertyChecks and TableDrivenPropertyChecks.
Note that this provides Generator
s for the common Scalactic types, as well as the common standard library ones.
Attributes
Members list
Implicits
Implicits
Given Generators for two types, L and R, this provides one for Either[L, R]
.
Given a Generator that produces values of type T, this returns one that produces ''functions'' that return a T.
Given a Generator that produces values of type T, this returns one that produces ''functions'' that return a T.
The functions produced here are nullary -- they take no parameters, they just spew out values of type T.
Type parameters
- T
-
the type to produce
Value parameters
- genOfT
-
a Generator that produces values of T
Attributes
- Returns
-
a Generator that produces functions that return values of type T
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
Create a Generator of functions from type A to type B.
Create a Generator of functions from type A to type B.
Note that the generated functions are, necessarily, pretty random. In practice, the function you get from a function1Generator (and its variations, up through function22Generator) takes the hashes of its input values, combines those with a randomly-chosen number, and combines them in order to choose the generated value B.
That said, each of the generated functions ''is'' deterministic: given the same input parameters and the same randomly-chosen number, you will always get the same B result. And the toString
function on the generated function will show the formula you need to use in order to recreate that, which will look something like:
(a: Int, b: String, c: Float) => org.scalatest.prop.valueOf[String](a, b, c)(131)
The number and type of the a
, b
, c
, etc, parameters, as well as the type parameter of valueOf, will on the function type you are generating, but they will always follow this pattern. valueOf is the underlying function that takes these parameters and the randomly-chosen number, and returns a value of the specified type.
So if a property evaluation fails, the display of the generated function will tell you how to call valueOf to recreate the failure.
The typeInfo
parameters are automatically created via macros; you should generally not try to pass them manually.
Type parameters
- A
-
the input type for the generated functions
- B
-
the result type for the generated functions
Value parameters
- genOfB
-
a Generator for the desired result type B
- typeInfoA
-
automatically-created type information for type A
- typeInfoB
-
automatically-created type information for type B
Attributes
- Returns
-
a Generator that produces functions that take values of A and returns values of B
Generate functions that take an Int and return a modified Int.
Generate functions that take an Int and return a modified Int.
This Generator is useful for testing edge cases of some higher-order functions. Besides obvious functions (returning the same Int, returning that Int plus 1), it tests overflow situations such as adding Int.MaxValue, negation, and other such cases.
Attributes
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
See function1Generator.
Given an existing Generator[T]
, this creates a Generator[List[T]]
.
Given an existing Generator[T]
, this creates a Generator[List[T]]
.
Type parameters
- T
-
the type that we are producing a List of
Value parameters
- genOfT
-
a Generator that produces values of type T
Attributes
- Returns
-
a List of values of type T
Given a Generator that produces Tuples of key/value pairs, this gives you one that produces Maps with those pairs.
Given a Generator that produces Tuples of key/value pairs, this gives you one that produces Maps with those pairs.
If you are simply looking for random pairing of the key and value types, this is pretty easy to use: if both the key and value types have Generators, then the Tuple and Map ones will be automatically and implicitly created when you need them.
The resulting Generator also has the HavingSize trait, so you can use it to generate Maps with specific sizes.
Type parameters
- K
-
the type of the keys for the Map
- V
-
the type of the values for the Map
Value parameters
- genOfTuple2KV
-
a Generator that produces Tuples of K and V
Attributes
- Returns
-
a Generator of Maps from K to V
Given Generators for two types, G and B, this provides one for G Or B
.
Given a Generator that produces values of type T, this creates one for a Set of T.
Given a Generator that produces values of type T, this creates one for a Set of T.
Note that the Set type is considered to have a "size", so you can use the configuration parameters Configuration.minSize and Configuration.sizeRange to constrain the sizes of the resulting Set
s when you use this Generator.
The resulting Generator also has the HavingSize trait, so you can use it to generate Sets with specific sizes.
Type parameters
- T
-
the type to produce
Value parameters
- genOfT
-
a Generator that produces values of type T
Attributes
- Returns
-
a Generator that produces
Set[T]
.
Given a Generator that produces Tuples of key/value pairs, this gives you one that produces SortedMaps with those pairs.
Given a Generator that produces Tuples of key/value pairs, this gives you one that produces SortedMaps with those pairs.
If you are simply looking for random pairing of the key and value types, this is pretty easy to use: if both the key and value types have Generators, then the Tuple and SortedMap ones will be automatically and implicitly created when you need them.
The resulting Generator also has the HavingSize trait, so you can use it to generate SortedMaps with specific sizes.
Type parameters
- K
-
the type of the keys for the SortedMap
- V
-
the type of the values for the SortedMap
Value parameters
- genOfTuple2KV
-
a Generator that produces Tuples of K and V
Attributes
- Returns
-
a Generator of SortedMaps from K to V
Given a Generator that produces values of type T, this creates one for a SortedSet of T.
Given a Generator that produces values of type T, this creates one for a SortedSet of T.
Note that the SortedSet type is considered to have a "size", so you can use the configuration parameters Configuration.minSize and Configuration.sizeRange to constrain the sizes of the resulting SortedSet
s when you use this Generator.
The resulting Generator also has the HavingSize trait, so you can use it to generate SortedSets with specific sizes.
Type parameters
- T
-
the type to produce
Value parameters
- genOfT
-
a Generator that produces values of type T
Attributes
- Returns
-
a Generator that produces
SortedSet[T]
.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
Given Generators for types A and B, get one that produces Tuples of those types.
Given Generators for types A and B, get one that produces Tuples of those types.
tuple2Generator (and its variants, up through tuple22Generator) will create Generators on demand for essentially arbitrary Tuples, so long as you have Generators in implicit scope for all of the component types.
Type parameters
- A
-
the first type in the Tuple
- B
-
the second type in the Tuple
Value parameters
Attributes
- Returns
-
a Generator that produces the desired types, Tupled together.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
See tuple2Generator.
Given a Generator for type T, this creates one for a Vector of T.
Given a Generator for type T, this creates one for a Vector of T.
Note that the Vector type is considered to have a "size", so you can use the configuration parameters Configuration.minSize and Configuration.sizeRange to constrain the sizes of the resulting Vector
s when you use this Generator.
The resulting Generator also has the HavingLength trait, so you can use it to generate Vectors with specific lengths.
Type parameters
- T
-
the type to produce
Value parameters
- genOfT
-
a Generator that produces values of type T
Attributes
- Returns
-
a Generator that produces values of type
Vector[T]
Allow Generators of a type to be used as Generators of a supertype.
Allow Generators of a type to be used as Generators of a supertype.
Given:
- You have a type
T
T
has a supertypeU
- You have a Generator that produces values of
T
This allows you to pass that Generator[T]
as a Generator[U]
.
We do this instead of making Generator covariant, because then an implicit search for a Generator[U]
would always be satisfied if it found just a Generator[T]
, and would then not generate anything except the subtype. That would be sound, but you wouldn't get a good variety of supertype values. This way, the subtype/supertype conversion is somewhat better-controlled.
Type parameters
Value parameters
- ev
-
implicit evidence that T is a subtype of U
- genOfT
-
a Generator that produces values of T
Attributes
- Returns
-
a
Generator[U]
derived from theGenerator[T]