Arbitrary
Typeclass #
The Arbitrary
typeclass represents types for which there exists a
random generator suitable for property-based testing, similar to
Haskell QuickCheck's Arbitrary
typeclass and Rocq/Coq QuickChick's Gen
typeclass.
(Note: the SampleableExt
involvs types which have both a generator & a shrinker,
and possibly a non trivial proxy
type,
whereas Arbitrary
describes types which have a generator only.)
Main definitions #
Arbitrary
typeclass
References #
The Arbitrary
typeclass represents types for which there exists a
random generator suitable for property-based testing.
- This is the equivalent of Haskell QuickCheck's
Arbitrary
typeclass. - In QuickChick, this typeclass is called
Gen
, butGen
is already a reserved keyword in Plausible, so we call this typeclassArbitrary
following the Haskell QuickCheck convention).
- arbitrary : Gen α
A random generator for values of the given type.
Instances
Samples from the generator associated with the Arbitrary
instance for a type,
using size
as the size parameter for the generator.
To invoke this function, you will need to specify what type α
is,
for example by doing runArbitrary (α := Nat) 10
.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Plausible.Sigma.Arbitrary = { arbitrary := do let p ← Plausible.Arbitrary.arbitrary.prodOf Plausible.Arbitrary.arbitrary pure ⟨p.fst, p.snd⟩ }
Equations
- Plausible.Nat.Arbitrary = { arbitrary := do let __do_lift ← Plausible.Gen.getSize let a ← Plausible.Gen.choose Nat 0 __do_lift ⋯ pure a.val }
Equations
- Plausible.Fin.Arbitrary = { arbitrary := do let __do_lift ← Plausible.Gen.getSize let m ← Plausible.Gen.choose Nat 0 (min __do_lift n) ⋯ pure (Fin.ofNat n.succ m.val) }
Equations
- Plausible.BitVec.Arbitrary = { arbitrary := do let __do_lift ← Plausible.Gen.getSize let m ← Plausible.Gen.choose Nat 0 (min __do_lift (2 ^ n)) ⋯ pure (BitVec.ofNat n m.val) }
Equations
- Plausible.UInt8.Arbitrary = { arbitrary := do let __do_lift ← Plausible.Gen.getSize let n ← Plausible.Gen.choose Nat 0 (min __do_lift UInt8.size) ⋯ pure (UInt8.ofNat n.val) }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Plausible.USize.Arbitrary = { arbitrary := do let __do_lift ← Plausible.Gen.getSize let n ← Plausible.Gen.choose Nat 0 (min __do_lift USize.size) ⋯ pure (USize.ofNat n.val) }
Equations
- One or more equations did not get rendered due to their size.
Equations
- Plausible.Bool.Arbitrary = { arbitrary := Plausible.Gen.chooseAny Bool }
This can be specialized into customized Arbitrary Char
instances.
The resulting instance has 1 / p
chances of making an unrestricted choice of characters
and it otherwise chooses a character from chars
with uniform probability.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
Equations
- Plausible.List.Arbitrary = { arbitrary := Plausible.Arbitrary.arbitrary.listOf }
Equations
- Plausible.ULift.Arbitrary = { arbitrary := do let x ← Plausible.Arbitrary.arbitrary pure { down := x } }
Equations
- Plausible.String.Arbitrary = { arbitrary := do let __do_lift ← Plausible.Arbitrary.arbitrary.listOf pure { data := __do_lift } }
Equations
- Plausible.Array.Arbitrary = { arbitrary := Plausible.Arbitrary.arbitrary.arrayOf }