plutarch-quickcheck-2.2.2: Quickcheck for Plutarch.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Plutarch.Test.QuickCheck.Modifiers

Synopsis

Types

newtype GenCurrencySymbol (p :: AdaSymbolPresence) Source #

A helper (opaque) newtype for QuickCheck use with CurrencySymbols. Has a type-level tag to indicate whether or not it could potentially contain a CurrencySymbol. We provide instances of Arbitrary, CoArbitrary and Function around this newtype, intended to act on the CurrencySymbol inside it.

The easiest way to use this newtype is by pattern matching:

forAll arbitrary $ \(GenCurrencySymbol @WithAdaSymbol sym) -> ...

You can also 're-wrap' for shrinking:

shrink $ GenCurrencySymbol @WithAdaSymbol sym

However, as GenCurrencySymbol instances do not shrink, there's not much point.

Since: 2.1.3

Instances

Instances details
Arbitrary (GenCurrencySymbol 'WithAdaSymbol) Source #

This instance occasionally has the ability to produce the ADA symbol (that is, the empty CurrencySymbol). However, this is weighted quite heavily in favour of the ADA symbol: in theory, assuming every byte is equally probable (a safe assumption, since CurrencySymbols are in general hashes), the odds of getting the ADA symbol should be

\[ frac{1}{2^{8 \cdot 28 = 224} + 1} \]

However, in this case, the odds are actually

\[ \frac{1}{2^{62} + 1} \]

This is a limitation of probability distributions as implemented by QuickCheck, which uses Int for this purpose. Keep this in mind when using this generator: if you're unsure, it's better to 'seed' the WithoutAdaSymbol instance to a probability you're happy with using frequency.

This instance does not shrink, as it makes very little sense to.

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Arbitrary (GenCurrencySymbol 'WithoutAdaSymbol) Source #

This instance never produces the ADA symbol. Like the corresponding WithAdaSymbol instance, this instance does not shrink.

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

CoArbitrary (GenCurrencySymbol p) Source #

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Function (GenCurrencySymbol p) Source #

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Show (GenCurrencySymbol p) Source #

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Eq (GenCurrencySymbol p) Source #

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

newtype GenValue (adaMod :: Type -> Type) (otherMod :: Type -> Type) Source #

A helper (opaque) newtype for QuickCheck use with Values. Has two type arguments, to indicate, in order, what kind of amounts ADA and non-ADA entries are allowed to have.

The Values wrapped inside this type are phase-1 valid; the only validity we can't guarantee is to do with amounts, as these depend on choice of modifiers.

The easiest way to use this newtype is by pattern matching:

forAll arbitrary $ \(GenValue @NonNegative @Positive val) -> ...

In this case, the ADA entry in val would contain a non-negative amount, but any other entry would contain a strictly positive one.

You can also 're-wrap' for shrinking:

shrink $ GenValue @NonNegative @Positive val

Note

As GenValue relies heavily on Coercible to work, the newtype constructors of your modifiers need to be in scope, or you will get strange errors. For example, if you want to do

GenValue @NonNegative @Positive val <- arbitrary

you must have both the NonNegative and Positive types, as well as their newtype constructors, imported.

Since: 2.1.3

Constructors

GenValue Value 

Instances

Instances details
(Arbitrary (adaMod Integer), Arbitrary (otherMod Integer), forall a. Coercible (adaMod a) a, forall a. Coercible (otherMod a) a) => Arbitrary (GenValue adaMod otherMod) Source #

This instance ensures phase-1 validity up to amounts. Specifically, the following are guaranteed to hold irrespective of 'tag choices':

  • Entries whose CurrencySymbol and TokenName match are unique.
  • 'Outer' map entries are sorted by CurrencySymbol.
  • 'Inner' map entries are sorted by TokenName.
  • An ADA entry always exists: this corresponds to a mapping from the CurrencySymbol "" to the TokenName "" and an amount.
  • ADA entries have singleton 'inner maps'.
  • Non-ADA entries have non-empty 'inner maps'.

The kind of amount generated for ADA and non-ADA entries is controlled by the two tags: the first determines how the ADA amount will get generated, while the second determines how any non-ADA amounts get generated. Thus, GenValue 'NonNegative 'Positive will mean the ADA entry has a zero or positive amount, but any other entry will be strictly positive.

In order to ensure all invariants hold, the shrinker for GenValue can only perform the following on the underlying Value:

  • Remove non-ADA 'outer map' entries;
  • Remove 'inner map' entries; and
  • Shrink the amounts associated with an entry according to the tags.

More specifically, neither CurrencySymbol or TokenMap keys will be shrunk.

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Methods

arbitrary :: Gen (GenValue adaMod otherMod) Source #

shrink :: GenValue adaMod otherMod -> [GenValue adaMod otherMod] Source #

CoArbitrary (GenValue adaMod otherMod) Source #

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Methods

coarbitrary :: GenValue adaMod otherMod -> Gen b -> Gen b Source #

Function (GenValue adaMod otherMod) Source #

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Methods

function :: (GenValue adaMod otherMod -> b) -> GenValue adaMod otherMod :-> b Source #

Show (GenValue adaMod otherMod) Source #

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Methods

showsPrec :: Int -> GenValue adaMod otherMod -> ShowS Source #

show :: GenValue adaMod otherMod -> String Source #

showList :: [GenValue adaMod otherMod] -> ShowS Source #

Eq (GenValue adaMod otherMod) Source #

Since: 2.1.3

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Methods

(==) :: GenValue adaMod otherMod -> GenValue adaMod otherMod -> Bool Source #

(/=) :: GenValue adaMod otherMod -> GenValue adaMod otherMod -> Bool Source #

data TimeDelta (mod :: Type -> Type) (n :: Nat) Source #

Represents a change in POSIXTime. The mod argument gives the kind of change, represented by a QuickCheck modifier, while the n argument is a closed (inclusive) upper bound on the magnitude of the change.

For example, TimeDelta Positive 100 represents a change in POSIXTime from 1 to 100 units, while TimeDelta NonPositive 250 represents a change in POSIXTime from 0 to -250. Modifiers intended to work with this type are:

The instances for TimeDelta reflect this decision: while other modifiers could potentially be useful, this ensures that we have safe behaviour and efficient instances.

NonZero is treated a bit specially in that the magnitude indicated by n is in both the negative and positive direction. Thus, TimeDelta NonZero 50 spans the union of [-50, -1] and [1, 50].

Shrinking a TimeDelta will shrink towards zero: more specifically, it will reduce the magnitude of the change.

To control what TimeDelta you get, the easiest method is a type signature:

forAll arbitrary $ \(delta :: TimeDelta NonNegative 100) -> ...

Since: 2.1.4

Instances

Instances details
(KnownNat n, 1 <= n) => Arbitrary (TimeDelta Negative n) Source #

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

KnownNat n => Arbitrary (TimeDelta NonNegative n) Source #

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

KnownNat n => Arbitrary (TimeDelta NonPositive n) Source #

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

(KnownNat n, 1 <= n) => Arbitrary (TimeDelta NonZero n) Source #

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

(KnownNat n, 1 <= n) => Arbitrary (TimeDelta Positive n) Source #

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

(forall a b. Coercible a b => Coercible (mod a) (mod b), CoArbitrary (mod Integer)) => CoArbitrary (TimeDelta mod n) Source #

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Methods

coarbitrary :: TimeDelta mod n -> Gen b -> Gen b Source #

(forall a b. Coercible a b => Coercible (mod a) b) => Function (TimeDelta mod n) Source #

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Methods

function :: (TimeDelta mod n -> b) -> TimeDelta mod n :-> b Source #

Monoid (TimeDelta NonNegative n) Source #

Non-negative deltas are monoids with the zero delta as the identity.

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Monoid (TimeDelta NonPositive n) Source #

Non-positive deltas are monoids with the zero delta as the identity.

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Semigroup (TimeDelta Negative n) Source #

Strictly negative deltas are semigroups under addition.

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Semigroup (TimeDelta NonNegative n) Source #

Non-negative deltas are semigroups under addition.

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Semigroup (TimeDelta NonPositive n) Source #

Non-positive deltas are semigroups under addition.

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Semigroup (TimeDelta Positive n) Source #

Strictly positive deltas are semigroups under addition.

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

(forall a. Show a => Show (mod a)) => Show (TimeDelta mod n) Source #

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Methods

showsPrec :: Int -> TimeDelta mod n -> ShowS Source #

show :: TimeDelta mod n -> String Source #

showList :: [TimeDelta mod n] -> ShowS Source #

(forall a. Eq a => Eq (mod a)) => Eq (TimeDelta mod n) Source #

Since: 2.1.4

Instance details

Defined in Plutarch.Test.QuickCheck.Modifiers

Methods

(==) :: TimeDelta mod n -> TimeDelta mod n -> Bool Source #

(/=) :: TimeDelta mod n -> TimeDelta mod n -> Bool Source #

Functions

timeDeltaProperty :: forall (n :: Nat) (mod :: Type -> Type). Coercible (mod POSIXTime) Integer => (POSIXTime -> Property) -> POSIXTime -> TimeDelta mod n -> Property Source #

A CPS-style Property handler for applying a TimeDelta to a POSIXTime. If the application of the delta to the time would produce an impossible result (that is, the resulting time is negative), this will automatically fail the property test with an informative message; otherwise, it will apply the delta, and produce a new POSIXTime, which it will pass to the function argument to determine the outcome.

The arguments are ordered to conveniently use with forAll and similar.

Since: 2.1.4

withTimeDelta :: forall (n :: Nat) (mod :: Type -> Type) (r :: Type). Coercible (mod POSIXTime) Integer => (Maybe POSIXTime -> r) -> POSIXTime -> TimeDelta mod n -> r Source #

A generic CPS-style handler for the application of a TimeDelta. The handler function argument will be passed Nothing if applying the TimeDelta would produce an impossible (that is, negative) POSIXTime, and a Just with the new POSIXTime otherwise.

Since: 2.1.4