Documentation

Plausible.Arbitrary

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 involves 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 #

References #

class Plausible.Arbitrary (α : Type u) :

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, but Gen is already a reserved keyword in Plausible, so we call this typeclass Arbitrary 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
        instance Plausible.Sigma.Arbitrary {α : Type u_1} {β : Type u_2} [Plausible.Arbitrary α] [Plausible.Arbitrary β] :
        Plausible.Arbitrary ((_ : α) × β)
        Equations
          def Plausible.Char.arbitraryFromList (p : Nat) (chars : List Char) (pos : 0 < chars.length) :

          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
            Instances For

              Pick a simple ASCII character 2/3s of the time, and otherwise pick any random Char encoded by the next Nat (or \0 if there is no such character)

              Equations
                Equations