org.scalatest.prop.HavingSize
This trait is mixed in to Generators that have a well-defined notion of "size".
Broadly speaking, this applies when T is a type that has a size
method. For example, Generator.setGenerator (also known as CommonGenerators.sets) has the HavingSize trait because Set has a size
method.
Generators with this trait provide several functions that allow you to create more-specialized Generators, with specific size bounds.
Type parameters
-
T
-
the type that this Generator produces
Attributes
-
Graph
-
-
Supertypes
-
class Object
trait Matchable
class Any
-
Known subtypes
-
Members list
Create a version of this Generator that produces values of exactly the specified size.
Create a version of this Generator that produces values of exactly the specified size.
For example, consider:
val stringSets: Generator[Set[String]] =
Generator.setGenerator[String]
val singleStringSets: Generator[Set[String]] =
stringSets.havingSize(1)
The singleStringSets
Generator will always produce Sets of exactly one String.
Value parameters
-
len
-
the size of the values to produce
Attributes
-
Returns
-
a new Generator that produces values of that size
Create a version of this Generator that produces values within the specified size range.
Create a version of this Generator that produces values within the specified size range.
The bounds are inclusive: the resulting Generator may produce values with a size of to
or from
.
For example, consider:
val stringSets: Generator[Set[String]] =
Generator.setGenerator[String]
val smallStringSets: Generator[Set[String]] =
stringSets.havingSizesBetween(0, 3)
The smallStringSets
Generator will always produce Sets of zero through three Strings.
Value parameters
-
from
-
The smallest desired size to produce
-
to
-
The largest desired size to produce
Attributes
-
Returns
-
a Generator that will only produce values within that size range
Create a version of this Generator whose legal sizes are adjusted by a specified function.
Create a version of this Generator whose legal sizes are adjusted by a specified function.
For example:
def currentLimit: PosZInt = ...
def limitedSize(szp: SizeParam): SizeParam = {
val limit = currentLimit
val sz = if (szp.maxSize < limit) szp.maxSize else limit
szp.copy(size = sz)
}
val sizelimitedLists = lists[Int].havingSizesDeterminedBy(limitedSize)
This doesn't hard-code the size of the sizeLimitedLists
Generator, but allows the maximum size to be clamped based on a dynamic currentLimit
function.
Value parameters
-
f
-
a transformation function that takes the current SizeParam and returns a new one
Attributes
-
Returns
-
a Generator that will base its sizes on the given function