Provides various specialized Generators that are often useful.
This exists as both a trait that you can mix into your classes, and an object that you can import -- choose whichever better suits your tests. However, you usually should not need to pull this in directly, since it is already mixed into both GeneratorDrivenPropertyChecks and TableDrivenPropertyChecks.
This incorporates the standard Generators defined in the Generator object, so you generally shouldn't need both.
- Companion:
- object
Value members
Concrete methods
Create a Generator that returns values in the specified range.
Create a Generator that returns values in the specified range.
This is the general-purpose function that underlies all of the other xxsBetween()
functions in
CommonGenerators. It works with any type for which there is an Ordering, a Generator, and
a Chooser, making it easy to create Generators for ranges within that type.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
. (However "less than or equal"
is defined for this type.)
The "edges" -- the edge case values -- for this type will be taken from the implicit
Generator. This function then filters out any that aren't within the specified range,
and adds the from
and to
values as edges.
The implicit Chooser is used to pick random values of the type. That should do most of the heavy lifting.
Since this underlies the more-specific xxsBetween()
functions, you may use either those
or this when appropriate. For example, this:
intsBetween(1, 100)
and
between(1, 100)
are functionally identical so long as the types of the parameters are clear to the compiler. Use whichever suits your project's coding style better.
- Type parameters:
- T
the type to choose a value from
- Value parameters:
- chooser
an instance of
Chooser[T]
, which should usually be in implicit scope- from
the lower bound of the range to choose from
- gen
an instance of
Generator[T]
, which should usually be in implicit scope- ord
an instance of
Ordering[T]
, which should usually be in implicit scope- to
the upper bound of the range to choose from
- Returns:
a new Generator, that produces values in the specified range
Create a Generator that returns Bytes in the specified range.
Create a Generator that returns Bytes in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns Chars in the specified range.
Create a Generator that returns Chars in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Generate a bunch of values from a Generator, and distribute them into buckets.
Generate a bunch of values from a Generator, and distribute them into buckets.
This function mainly exists for the purpose of testing your Generator, and making sure that it is actually creating data with the sort of distribution you expect. You provide the Generator, the number of values to create, and a function that "classifies" each value with a String; it returns a Classification that collates all of the results. You can then look at the Classification to see if the proportions match your expectations.
For example, consider this simple classification of small numbers:
val classification: Classification =
CommonGenerators.classify(10000, CommonGenerators.intsBetween(0, 9))
{
case x if (x % 2) == 0 => "even"
case _ => "odd"
}
As expected, the results come out evenly:
classification: org.scalatest.prop.Classification =
50% odd
50% even
The options provided in the PartialFunction do not have to be comprehensive; it is legal for some generated values to not match any of the choices. In this case, those values will not be accounted for in the resulting Classification.
- Type parameters:
- A
the type to be generated
- Value parameters:
- count
the number of values to generate
- genOfA
the Generator to use
- pf
a PartialFunction that takes the generated values, and sorts them into "buckets" by String names
- Returns:
statistics on how many values wound up in each bucket
Create a Generator that returns Doubles in the specified range.
Create a Generator that returns Doubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Given a number of Generators, this creates one that invokes each of its constituents with roughly the same frequency.
Given a number of Generators, this creates one that invokes each of its constituents with roughly the same frequency.
Consider this example:
val numbers: Generator[Char] = ... // generates only digits
val letters: Generator[Char] = ... // generates only letters
val punct: Generator[Char] = ... // generates only punctuation
val chars: Generator[Char] = evenly(numbers, letters, punct)
The chars
Generator should produce numbers, letters and punctuation, each about a third
of the time.
Keep in mind that the distribution is invoked randomly, so these are rough proportions. As you invoke the Generator more times, you should see results that are closer and closer to an equal distribution, but the random element will generally keep it inexact.
As usual, the resulting Generator will use the Randomizer passed in to Generator.next to choose which of the constituent Generators to invoke. So if you use the same seed to initialize your Randomizer, you should get the same results.
Note that all of the constituent Generators must produce the same type.
Create a Generator that returns FiniteDoubles in the specified range.
Create a Generator that returns FiniteDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns FiniteFloats in the specified range.
Create a Generator that returns FiniteFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns Floats in the specified range.
Create a Generator that returns Floats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Given a number of Generators, and the weightings for each one, this creates a Generator that invokes each of its components according to its weighting.
Given a number of Generators, and the weightings for each one, this creates a Generator that invokes each of its components according to its weighting.
For example, consider this:
val evens: Generator[Int] = ... // generates even Ints
val odds: Generator[Int] = ... // generates odd Ints
val zeros: Generator[Int] = specificValue(0)
val mixed: Generator[Int] = frequency(
(5, evens),
(4, odds),
(1, zeros)
)
The total weighting is (5 + 4 + 1) = 10. So the resulting Generator will produce an even number (10 / 5) = 50% the time, an odd number (10 / 4) = 40% of the time, and zero (10 / 1) = 10% of the time.
Keep in mind that the distribution is invoked randomly, so these are rough proportions. As you invoke the Generator more times, you should see results that are closer and closer to the specified proportions, but the random element will generally keep it inexact.
As usual, the resulting Generator will use the Randomizer passed in to Generator.next to choose which of the constituent Generators to invoke. So if you use the same seed to initialize your Randomizer, you should get the same results.
Note that all of the constituent Generators must produce the same type.
Given a Generator that produces values of type A, this returns one that produces ''functions'' that return a T.
Given a Generator that produces values of type A, 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 A.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
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 function1s call (and its variations, up through function22s) 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 depend
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
- Returns:
a Generator that produces functions that take values of A and returns values of B
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
See function1s.
The instancesOf
function (which has overloads depending on how many parameters you need)
is one way to create a Generator for case classes and other situations where you
want to build a type out of other types.
The instancesOf
function (which has overloads depending on how many parameters you need)
is one way to create a Generator for case classes and other situations where you
want to build a type out of other types.
To understand how it works, look at this example:
case class Person(name: String, age: Int)
implicit val persons: Generator[Person] =
instancesOf(Person) { p =>
(p.name, p.age)
} (strings, posZIntValues)
What's going on here? instancesOf
is taking two types (String and Int),
a function (a case class constructor) that turns those types into a third type (Person
),
and a second function that takes a Person
and deconstructs it back to its component
pieces. From those, it creates a Generator.
The last parameters -- the (strings, posZIntValues)
-- are the Generators for
the component types. If you are good with using the default Generators for those types,
you can just let those parameters be resolved implicitly. (But in this case, that
could result in negative ages, which doesn't make any sense.)
After creating a Generator this way, you can use it like any other Generator in your property checks.
Alternatively, you can construct Generators for case classes using for comprehensions, like this:
implicit val persons: Generator[Person] = for {
name <- strings
age <- posZIntValues
}
yield Person(name, age)
Which approach you use is mainly up to personal taste and the coding standards of your project.
- Type parameters:
- A
the input type
- B
the target type to be generated
- Value parameters:
- construct
a constructor that builds the target type from its constituents; most often, a case class constructor
- deconstruct
a deconstructor function that takes the target type and breaks is down into its constituents
- genOfA
a Generator for the input type
- Returns:
a Generator for the target type
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
See the simple [A, B]
version of instancesOf()
for details.
Create a Generator that returns Ints in the specified range.
Create a Generator that returns Ints in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
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
- Returns:
a List of values of type T
Create a Generator that returns Longs in the specified range.
Create a Generator that returns Longs in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
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.
Create a Generator that returns NegDoubles in the specified range.
Create a Generator that returns NegDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegFiniteDoubles in the specified range.
Create a Generator that returns NegFiniteDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegFiniteFloats in the specified range.
Create a Generator that returns NegFiniteFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegFloats in the specified range.
Create a Generator that returns NegFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegInts in the specified range.
Create a Generator that returns NegInts in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegLongs in the specified range.
Create a Generator that returns NegLongs in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegZDoubles in the specified range.
Create a Generator that returns NegZDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegZFiniteDoubles in the specified range.
Create a Generator that returns NegZFiniteDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegZFiniteFloats in the specified range.
Create a Generator that returns NegZFiniteFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegZFloats in the specified range.
Create a Generator that returns NegZFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegZInts in the specified range.
Create a Generator that returns NegZInts in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NegZLongs in the specified range.
Create a Generator that returns NegZLongs in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NonZeroDoubles in the specified range.
Create a Generator that returns NonZeroDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NonZeroFiniteDoubles in the specified range.
Create a Generator that returns NonZeroFiniteDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NonZeroFiniteFloats in the specified range.
Create a Generator that returns NonZeroFiniteFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NonZeroFloats in the specified range.
Create a Generator that returns NonZeroFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NonZeroInts in the specified range.
Create a Generator that returns NonZeroInts in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns NonZeroLongs in the specified range.
Create a Generator that returns NonZeroLongs in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Given an existing Generator[T]
, this creates a Generator[Option[T]]
.
Given an existing Generator[T]
, this creates a Generator[Option[T]]
.
- Type parameters:
- T
the type that we are producing an Option of
- Value parameters:
- genOfT
a Generator that produces values of type T
- Returns:
a Generator that produces
Option[T]
Create a Generator that returns PosDoubles in the specified range.
Create a Generator that returns PosDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosFiniteDoubles in the specified range.
Create a Generator that returns PosFiniteDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosFiniteFloats in the specified range.
Create a Generator that returns PosFiniteFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosFloats in the specified range.
Create a Generator that returns PosFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosInts in the specified range.
Create a Generator that returns PosInts in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosLongs in the specified range.
Create a Generator that returns PosLongs in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosZDoubles in the specified range.
Create a Generator that returns PosZDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosZFiniteDoubles in the specified range.
Create a Generator that returns PosZFiniteDoubles in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosZFiniteFloats in the specified range.
Create a Generator that returns PosZFiniteFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosZFloats in the specified range.
Create a Generator that returns PosZFloats in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosZInts in the specified range.
Create a Generator that returns PosZInts in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
Create a Generator that returns PosZLongs in the specified range.
Create a Generator that returns PosZLongs in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
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.
Create a Generator that returns Shorts in the specified range.
Create a Generator that returns Shorts in the specified range.
The range is inclusive: both ''from'' and ''to'' may be produced by this Generator. Moreover, ''from'' and ''to'' are considered to be edge cases, so they usually ''will'' be produced in a typical run.
The value of from
must be less than or equal to the value of to
.
- Value parameters:
- from
one end of the desired range
- to
the other end of the desired range
- Returns:
a value within that range, inclusive of the bounds
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.
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.
Creates a Generator that will always return exactly the same value.
Creates a Generator that will always return exactly the same value.
This is specialized, but occasionally useful. It is mainly appropriate when you have a function that requires a Generator, but only one value makes sense for the Property you are evaluating.
- Type parameters:
- T
the type of that value
- Value parameters:
- theValue
the value to produce
- Returns:
a Generator that will always produce that value
Given a list of values of type T, this creates a Generator that will only produce those values.
Given a list of values of type T, this creates a Generator that will only produce those values.
The order in which the values are produced is random, based on the Randomizer passed
in to the next
function. It may produce the same value multiple times.
Given Generators for types A and B, get one that produces Tuples of those types.
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.
Concrete fields
A Generator of prime numbers.
A Generator of prime numbers.
As the name implies, this doesn't try to generate entirely arbitrary prime numbers. Instead, it takes the simpler and more efficient approach of choosing randomly from a hard-coded table of the first 1000 primes. As a result, the largest number that can be produced from this is 7919.
- Returns:
a Generator that will produce smallish prime numbers