plutus-core-1.30.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusCore.Generators.QuickCheck.Split

Synopsis

Documentation

smallLengthInt Source #

Up to what length a list is considered "short".

sublistNInt → [a] → Gen [a] Source #

Generate a sublist of the given size of the given list. Preserves the order of elements.

toMaxChunkNumberIntInt Source #

Calculate the maximum number of chunks to split a list of the given list into.

toChunkNumberIntIntInt Source #

Calculate the number of ways to divide a list of length len into chunkNum chunks. Equals to C(len - 1, chunksNum - 1).

toChunkFrequenciesInt → [(Int, Int)] Source #

Return a list of pairs, each of which consists of

  1. the frequency at which a chunk length needs to be picked by the generation machinery
  2. the chunk length itself
>>> toChunkFrequencies (-1)
[]
>>> toChunkFrequencies 0
[]
>>> toChunkFrequencies 1
[(1,1)]
>>> toChunkFrequencies 5
[(1,1),(4,2),(6,3),(4,4),(1,5)]
>>> toChunkFrequencies 10
[(3,1),(6,2),(9,3),(12,4),(15,5),(18,6),(21,7)]
>>> toChunkFrequencies 50
[(3,1),(4,2),(5,3),(6,4),(7,5),(8,6),(9,7),(10,8),(11,9),(12,10),(13,11),(14,12),(15,13)]

toChunks ∷ [Int] → [a] → [[a]] Source #

Split the given list in chunks. The length of each chunk, apart from the final one, is taken from the first argument.

>>> toChunks [3, 1] "abcdef"
["abc","d","ef"]

multiSplit1InInt → [a] → Gen [NonEmptyList a] Source #

Split a list into the given number of chunks. Concatenating the resulting lists gives back the original one. Doesn't generate empty chunks.

multiSplit1 ∷ [a] → Gen [NonEmptyList a] Source #

Split a list into chunks at random. Concatenating the resulting lists gives back the original one. Doesn't generate empty chunks.

halveBool → [a] → ([a], [a]) Source #

Return the left and the right halves of the given list. The first argument controls whether the middle element of a list having an odd length goes into the left half or the right one.

>>> halve True [1 :: Int]
([1],[])
>>> halve True [1, 2 :: Int]
([1],[2])
>>> halve True [1, 2, 3 :: Int]
([1,2],[3])
>>> halve False [1 :: Int]
([],[1])
>>> halve False [1, 2 :: Int]
([1],[2])
>>> halve False [1, 2, 3 :: Int]
([1],[2,3])

insertManyPreferRight ∷ ∀ a. BoolDouble → a → [a] → Gen [a] Source #

Insert a value into a list an arbitrary number of times. The first argument controls whether to allow inserting at the beginning of the list, the second argument is the probability of inserting an element at the end of the list.

insertManyPreferLeftBoolDouble → a → [a] → Gen [a] Source #

Insert a value into a list an arbitrary number of times. The first argument controls whether to allow inserting at the end of the list, the second argument is the probability of inserting an element at the beginning of the list.

insertManyPreferEndsDouble → a → [a] → Gen [a] Source #

Insert a value into a list an arbitrary number of times. The first argument is the probability of inserting an element at an end of the list (i.e. either the beginning or the end, not combined). See multiSplit1 for what this function allows us to do.

multiSplit0Double → [a] → Gen [[a]] Source #

Split a list into chunks at random. Concatenating the resulting lists gives back the original one. Generates empty chunks. The first argument is the probability of generating at least one empty chunk as the first element of the resulting list. It is also the probability of generating an empty chunk as the last element of the resulting list. The probability of generating empty chunks decreases as we go from either of the ends of the resulting list (this is so that we are more likely to hit a corner case related to handling elements at the beginning or the end of a list).