trait
TestRandom extends Random with Restorable
Type Members
-
trait
UnsafeAPI extends AnyRef
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
final
def
==(arg0: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
def
clone(): AnyRef
-
-
-
def
finalize(): Unit
-
final
def
getClass(): Class[_]
-
def
hashCode(): Int
-
final
def
isInstanceOf[T0]: Boolean
-
-
final
def
notify(): Unit
-
final
def
notifyAll(): Unit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
-
def
toString(): String
-
final
def
wait(): Unit
-
final
def
wait(arg0: Long, arg1: Int): Unit
-
final
def
wait(arg0: Long): Unit
TestRandomallows for deterministically testing effects involving randomness.TestRandomoperates in two modes. In the first mode,TestRandomis a purely functional pseudo-random number generator. It will generate pseudo-random values just likescala.util.Randomexcept that no internal state is mutated. Instead, methods likenextIntdescribe state transitions from one random state to another that are automatically composed together through methods likeflatMap. The random seed can be set usingsetSeedandTestRandomis guaranteed to return the same sequence of values for any given seed. This is useful for deterministically generating a sequence of pseudo-random values and powers the property based testing functionality in ZIO Test.In the second mode,
TestRandommaintains an internal buffer of values that can be "fed" with methods such asfeedIntsand then when random values of that type are generated they will first be taken from the buffer. This is useful for verifying that functions produce the expected output for a given sequence of "random" inputs.TestRandomwill automatically take values from the buffer if a value of the appropriate type is available and otherwise generate a pseudo-random value, so there is nothing you need to do to switch between the two modes. Just generate random values as you normally would to get pseudo-random values, or feed in values of your own to get those values back. You can also use methods likeclearIntsto clear the buffer of values of a given type so you can fill the buffer with new values or go back to pseudo-random number generation.