| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusCore.Generators.QuickCheck.Builtin
Contents
Synopsis
- class ArbitraryBuiltin a where
- arbitraryBuiltin :: Gen a
- shrinkBuiltin :: a -> [a]
- nextInterestingBound :: DefaultUni]
Documentation
class ArbitraryBuiltin a where #
Same as Arbitrary but specifically for Plutus built-in types, so that we are not tied to
the default implementation of the methods for a built-in type.
Minimal complete definition
Nothing
Methods
arbitraryBuiltin :: Gen a #
default arbitraryBuiltin :: Arbitrary a => Gen a #
shrinkBuiltin :: a -> [a] #
default shrinkBuiltin :: Arbitrary a => a -> [a] #
Instances
| ArbitraryBuiltin Text # |
|
Defined in PlutusCore.Generators.QuickCheck.Builtin Methods arbitraryBuiltin :: Gen Text] # | |
| ArbitraryBuiltin Vector a] # | |
| ArbitraryBuiltin a => ArbitraryBuiltin [a] # | |
Defined in PlutusCore.Generators.QuickCheck.Builtin | |
| (ArbitraryBuiltin a, ArbitraryBuiltin b) => ArbitraryBuiltin (a, b) # | |
Defined in PlutusCore.Generators.QuickCheck.Builtin | |
nextInterestingBound :: Integer -> Integer #
magnitudesPositive :: (Integer -> Integer) -> Integer -> [(Integer, Integer)] #
A list of ranges.
>>>import Data.Int>>>magnitudesPositive (* 10) (toInteger (maxBound :: Int16))[(1,10),(11,100),(101,1000),(1001,10000),(10001,32767)]>>>magnitudesPositive nextInterestingBound (toInteger (maxBound :: Int64))[(1,127),(128,32767),(32768,2147483647),(2147483648,9223372036854775807)]
arbitraryPositive :: (Integer -> Integer) -> Integer -> Gen Integer #
Generate asymptotically larger positive negative numbers (sans zero) with exponentially lower chance, stop at the geometric mean of the range and start increasing the probability of generating larger numbers, so that we generate we're most likely to generate numbers that are either fairly small or really big. Numbers at the beginning of the range are more likely to get generated than at the very end, but only by a fairly small factor. The size parameter is ignored, which is perhaps wrong and should be fixed.
arbitraryNegative :: (Integer -> Integer) -> Integer -> Gen Integer #
Same as arbitraryPositive except produces negative integers.
shrinkIntegralFast :: Integral a => a -> [a] #
Same as shrinkIntegral except includes the square root of the given number (or of its
negative if the number is negative, in which case the square root is negated too). We need the
former because shrinkIntegral at most divides the number by two, which makes the number smaller
way too slow, hence we add square root to speed up the process.
>>>shrinkIntegralFast (0 :: Integer)[]>>>shrinkIntegralFast (1 :: Integer)[0]>>>shrinkIntegralFast (9 :: Integer)[0,3,5,7,8]>>>shrinkIntegralFast (-10000 :: Integer)[0,10000,-100,-5000,-7500,-8750,-9375,-9688,-9844,-9922,-9961,-9981,-9991,-9996,-9998,-9999]
genConstrTag :: Gen Data object using a spine :: [()] as a hint. It's helpful to make the spine a
list of units rather than a Word or something, because we have useful functions for arbitrary
list splitting.
pureIfNull :: (Foldable f, Applicative f) => a -> f a -> f a #
toCellCandidatesNumber :: Int -> Int #
Return how many candidates to randomly choose from to fill the given number of cells. For example, if we only need to fill a single cell, we choose from 6 different candidates, and if we need to fill 5 cells, we choose from 11 candidates.
>>>map (\i -> (i, toCellCandidatesNumber i)) [1..13][(1,6),(2,6),(3,6),(4,8),(5,11),(6,14),(7,18),(8,22),(9,27),(10,31),(11,36),(12,41),(13,46)]
genShortHex :: K #
Generate a ByteString by picking one of the predetermined ones, given a number of
cells to fill (see toCellCandidatesNumber). The idea is that we want to occasionally generate
the same CurrencySymbol or TokenName for different Values to have decent test coverage,
hence to make name clashing more likely we pick from a predetermined set of
ByteStrings. Otherwise the chance of generating the same ByteString for two
different K -> name) -> [b] -> Gen [(name, b)] #
Annotate each element of the give list with a name, given a function turning
ByteString into names.
newtype NoArbitrary a #
A wrapper for satisfying an Arbitrary a constraint without implementing an Arbitrary
instance for a.
Constructors
| NoArbitrary | |
Fields
| |
Instances
| Arbitrary (NoArbitrary a) # | |
Defined in PlutusCore.Generators.QuickCheck.Builtin | |
newtype AsArbitraryBuiltin a #
For providing an Arbitrary instance deferring to ArbitraryBuiltin. Useful for implementing
ArbitraryBuiltin for a polymorphic built-in type by taking the logic for handling spines from
the Arbitrary class and the logic for handling elements from ArbitraryBuiltin.
Constructors
| AsArbitraryBuiltin | |
Fields
| |
Instances
| ArbitraryBuiltin a => Arbitrary (AsArbitraryBuiltin a) # | |
Defined in PlutusCore.Generators.QuickCheck.Builtin Methods arbitrary :: Gen (AsArbitraryBuiltin a) # shrink :: AsArbitraryBuiltin a -> [AsArbitraryBuiltin a] # | |
| DefaultUniApply to one of the elements of the spine and throw away the head
(because the head of an application can't be of the same kind as the whole application).
We don't have higher-kinded built-in types, so we don't do this kind of shrinking for any kinds
other than *. shrinkDropBuiltinSameKind :: Esc (a :: k)) -> [MaybeSomeTypeOf k] # Shrink a function application by shrinking either the function or the argument. The kind is preserved. shrinkBuiltinSameKind :: DefaultUni] # Shrink a built-in type by dropping a part of it or dropping the whole built-in type in favor of
a some minimal one (see shrinkBuiltinType :: DefaultUni)] # | |