trait Chooser[T] extends AnyRef
A simple one-method trait to allow you to pick values within a range.
Quite often in test code, you need to pick a specific value for a given type within a
range. This typeclass represents that notion. You can think of it as the
generalization of functions in Randomizer such as chooseChar, chooseFloat
or choosePosInt. It is appropriate to use this typeclass when you are writing
a function that needs this notion of "choosing", and works for multiple
types.
In principle, this typeclass makes sense for any ordered type with a finite number of values. However, it is a bit different from scala.math.Ordering in that it is specifically built around ScalaTest's Randomizer. This is not attempting to choose truly random values; it is choosing pseudo-random values via Randomizer, so that the results can be replayed for debugging if necessary. This is very important: all "randomness" in making the choice should come from the provided Randomizer.
This typeclass is used as the basis for CommonGenerators.between, so that you can use that function with your own types by creating an implicit instance of Chooser. (Note that such types will also requires instances of Generator and Ordering.)
- T
A type to choose a value of.
- Source
- Chooser.scala
- Alphabetic
- By Inheritance
- Chooser
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
choose(from: T, to: T)(rnd: Randomizer): (T, Randomizer)
Choose a value in the given range.
Choose a value in the given range.
The results should be inclusive: that is, it should be possible for this function to return
fromorto.Implementations of this function should be tolerant about the ordering of
fromorto-- that it should behave appropriately iffromis less thantosemantically.This function should use the provided Randomizer in making its choice, and should then return the next Randomizer. (Which is returned from all functions on Randomizer.)
- from
one end of the target range, inclusive
- to
the other end of the target range, inclusive
- rnd
the Randomizer to use for choosing a value
- returns
the selected value, and the next Randomizer
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[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.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
- @native() @throws( ... )