org.scalatest.prop

Chooser

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
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Chooser
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. 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 from or to.

    Implementations of this function should be tolerant about the ordering of from or to -- that it should behave appropriately if from is less than to semantically.

    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

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  18. def toString(): String

    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped