Gen
Monad #
This monad is used to formulate randomized computations with a parameter to specify the desired size of the result. This is a port of the Haskell QuickCheck library.
Main definitions #
Gen
monad
Tags #
random testing
References #
Monad to generate random examples to test properties with.
It has a Nat
parameter so that the caller can decide on the
size of the examples.
Equations
- SlimCheck.Gen α = ReaderT (ULift.{?u.10, 0} ℕ) Rand α
Instances For
Lift BoundedRandom.randomR
to the Gen
monad.
Equations
- SlimCheck.Gen.choose α lo hi h x = Random.randBound α lo hi h
Instances For
Generate a Nat
example between x
and y
(exclusively).
Equations
- SlimCheck.Gen.chooseNatLt lo hi h = Subtype.map Nat.pred ⋯ <$> SlimCheck.Gen.choose ℕ lo.succ hi ⋯
Instances For
Get access to the size parameter of the Gen
monad.
Equations
- SlimCheck.Gen.getSize = do let __do_lift ← read pure __do_lift.down
Instances For
Apply a function to the size parameter.
Equations
- SlimCheck.Gen.resize f x = withReader (ULift.up ∘ f ∘ ULift.down) x
Instances For
Given a list of example generators, choose one to create an example.
Equations
- SlimCheck.Gen.oneOf xs pos = do let __discr ← ULiftable.up (SlimCheck.Gen.chooseNatLt 0 xs.size pos) match __discr with | { down := ⟨x, ⋯⟩ } => xs.get ⟨x, h2⟩
Instances For
Given a list of examples, choose one to create an example.
Equations
- SlimCheck.Gen.elements xs pos = do let __discr ← ULiftable.up (SlimCheck.Gen.chooseNatLt 0 xs.length pos) match __discr with | { down := ⟨x, ⋯⟩ } => pure xs[x]
Instances For
Generate a random permutation of a given list.
Equations
- One or more equations did not get rendered due to their size.
- SlimCheck.Gen.permutationOf [] = pure ⟨[], ⋯⟩
Instances For
Given two generators produces a tuple consisting out of the result of both
Equations
- x.prodOf y = do let __discr ← ULiftable.up x match __discr with | { down := a } => do let __discr ← ULiftable.up y match __discr with | { down := b } => pure (a, b)
Instances For
Execute a Gen
inside the IO
monad using size
as the example size
Equations
- x.run size = IO.runRand (liftM (ReaderT.run x { down := size }))