Module

Jack

Package
purescript-jack
Repository
jystic/purescript-jack

Re-exports from Jack.Combinators

#suchThatMaybe Source

suchThatMaybe :: forall a. Gen a -> (a -> Boolean) -> Gen (Maybe a)

Tries to generate a value that satisfies a predicate.

#suchThat Source

suchThat :: forall a. Gen a -> (a -> Boolean) -> Gen a

Generates a value that satisfies a predicate.

#sized Source

sized :: forall a. (Int -> Gen a) -> Gen a

Construct a 'Gen' that depends on the size parameter.

#scale Source

scale :: forall a. (Int -> Int) -> Gen a -> Gen a

Update the current size by mapping a function over it.

#resize Source

resize :: forall a. Int -> Gen a -> Gen a

Overrides the size parameter. Returns a 'Gen' which uses the given size

#oneOfRec Source

oneOfRec :: forall a. Array (Gen a) -> Array (Gen a) -> Gen a

Randomly selects from one of the jacks in either the non-recursive or the recursive array. When a selection is made from the recursive array, the size is halved. When the size gets to one or less, selections are no longer made from the recursive array. /The first argument (i.e. the non-recursive input array) must be non-empty./

#oneOf Source

oneOf :: forall a. Array (Gen a) -> Gen a

Randomly selects one of the jacks in the array. /The input array must be non-empty./

#noShrink Source

noShrink :: forall a. Gen a -> Gen a

Prevent a 'Gen' from shrinking.

#maybeOf Source

maybeOf :: forall a. Gen a -> Gen (Maybe a)

Generates a 'Nothing' some of the time.

#listOfN' Source

listOfN' :: forall a. Int -> Int -> Gen a -> Gen (List a)

Generates a list between 'n' and 'm' in length.

#listOfN Source

listOfN :: forall a. Int -> Gen a -> Gen (List a)

Generates a list of the given length.

#listOf1 Source

listOf1 :: forall a. Gen a -> Gen (NonEmpty List a)

Generates a non-empty list of random length. The maximum length depends on the size parameter.

#listOf Source

listOf :: forall a. Gen a -> Gen (List a)

Generates a list of random length. The maximum length depends on the size parameter.

#justOf Source

justOf :: forall a. Gen (Maybe a) -> Gen a

Runs a generator that produces 'Maybe a' until it produces a 'Just'.

#frequency Source

frequency :: forall a. Array (Tuple Int (Gen a)) -> Gen a

Uses a weighted distribution to randomly select one of the jacks in the array.

#elements Source

elements :: forall a. Array a -> Gen a

Randomly selects one of the values in the array. /The input array must be non-empty./

#chooseInt Source

chooseInt :: Int -> Int -> Gen Int

Generates an integral number.

#chooseChar Source

chooseChar :: Char -> Char -> Gen Char

Generates a 'Char' in the given range.

#boundedInt Source

boundedInt :: Gen Int

Generates an 'Int'. The number is chosen from the entire range of valid 'Int' values, this is [-2^31, 2^31).

#boundedChar Source

boundedChar :: Gen Char

Generates a 'Char'. The character is chosen from the entire range of valid 'Char' values, this is [0, 65535].

#arrayOfN' Source

arrayOfN' :: forall a. Int -> Int -> Gen a -> Gen (Array a)

Generates an array between 'n' and 'm' in length.

#arrayOfN Source

arrayOfN :: forall a. Int -> Gen a -> Gen (Array a)

Generates an array of the given length.

#arrayOf1 Source

arrayOf1 :: forall a. Gen a -> Gen (NonEmpty Array a)

Generates a non-empty array of random length. The maximum length depends on the size parameter.

#arrayOf Source

arrayOf :: forall a. Gen a -> Gen (Array a)

Generates an array of random length. The maximum length depends on the size parameter.

Re-exports from Jack.Gen

#Gen Source

newtype Gen a

A generator for random values of type @a@ that includes all the possible shrink scenarios for @a@.

Constructors

Instances

#runGen Source

runGen :: forall a. Gen a -> Random (Tree a)

#reshrinkLazy Source

reshrinkLazy :: forall a. (a -> List a) -> Gen a -> Gen a

Apply an additional shrinker to all generated trees.

#reshrink Source

reshrink :: forall a. (a -> Array a) -> Gen a -> Gen a

Apply an additional shrinker to all generated trees.

#mkGen_ Source

mkGen_ :: forall a. Random a -> Gen a

Create a non-shrinking 'Gen' from a 'Random'.

#mkGen Source

mkGen :: forall a. (a -> List a) -> Random a -> Gen a

Create a 'Gen' from a shrink function and a 'Random'.

#mapTree Source

mapTree :: forall b a. (Tree a -> Tree b) -> Gen a -> Gen b

Map over the 'Tree' inside a 'Gen'.

#mapRandom Source

mapRandom :: forall b a. (Random (Tree a) -> Random (Tree b)) -> Gen a -> Gen b

Map over the 'Random' inside of 'Gen'.

Re-exports from Jack.Property

#Result Source

data Result

Constructors

Instances

#Property Source

newtype Property

#sampleTree Source

sampleTree :: forall a e. Size -> Int -> Gen a -> Eff (random :: RANDOM | e) (List (Tree a))

Generate some example trees.

#renderResult Source

#printSampleTree Source

printSampleTree :: forall a e. Show a => Gen a -> Eff (console :: CONSOLE, random :: RANDOM | e) Unit

#printSample Source

printSample :: forall a e. Show a => Gen a -> Eff (console :: CONSOLE, random :: RANDOM | e) Unit

Generate some example outcomes (and shrinks) and prints them to 'stdout'.

#forAllRender Source

forAllRender :: forall a. (a -> String) -> Gen a -> (a -> Property) -> Property

#forAll Source

forAll :: forall a. Show a => Gen a -> (a -> Property) -> Property

#check' Source

check' :: forall e. Int -> Property -> Eff (console :: CONSOLE, random :: RANDOM | e) Boolean

#check Source

check :: forall e. Property -> Eff (console :: CONSOLE, random :: RANDOM | e) Boolean

#assertNotEq Source

assertNotEq :: forall a. Eq a => Show a => a -> a -> Property

#assertEq Source

assertEq :: forall a. Eq a => Show a => a -> a -> Property

#(===) Source

Operator alias for Jack.Property.assertEq (non-associative / precedence 4)

#(=/=) Source

Operator alias for Jack.Property.assertNotEq (non-associative / precedence 4)

Re-exports from Jack.Runner

#jackMain Source

jackMain :: forall e. Array String -> Eff (console :: CONSOLE, random :: RANDOM | e) Unit

#checkModules Source

checkModules :: forall e. Array String -> Eff (console :: CONSOLE, random :: RANDOM | e) Boolean

#checkModule Source

checkModule :: forall e. String -> Eff (console :: CONSOLE, random :: RANDOM | e) Boolean

Re-exports from Jack.Shrink

#shrinkTowards Source

shrinkTowards :: forall a. Ord a => EuclideanRing a => a -> a -> List a

Shrink an integral by edging towards a destination number.

#shrinkOne Source

shrinkOne :: forall a. (a -> List a) -> List a -> List (List a)

Shrink each of the elements in input list using the supplied shrinking function.

#shrinkList Source

shrinkList :: forall a. List a -> List (List a)

Produce a smaller permutation of the input list.

#sequenceShrinkOne Source

sequenceShrinkOne :: forall a. List (Tree a) -> Tree (List a)

Turn a list of trees in to a tree of lists, opting to shrink only the elements of the list (i.e. the size of the list will always be the same).

#sequenceShrinkList Source

sequenceShrinkList :: forall a. List (Tree a) -> Tree (List a)

Turn a list of trees in to a tree of lists, opting to shrink both the list itself and the elements in the list during traversal.

#sequenceShrink Source

sequenceShrink :: forall a. (List (Tree a) -> List (List (Tree a))) -> List (Tree a) -> Tree (List a)

Turn a list of trees in to a tree of lists, using the supplied function to merge shrinking options.

#removes Source

removes :: forall a. Int -> List a -> List (List a)

Permutes a list by removing 'k' consecutive elements from it:

removes 2 [1,2,3,4,5,6] == [[3,4,5,6],[1,2,5,6],[1,2,3,4]]

#halves Source

halves :: forall a. Ord a => EuclideanRing a => a -> List a

Produces a list containing the results of halving a number over and over again.

halves 30 == [30,15,7,3,1] halves 128 == [128,64,32,16,8,4,2,1] halves (-10) == [-10,-5,-2,-1]

#consNub Source

consNub :: forall a. Eq a => a -> List a -> List a

Re-exports from Jack.Tree

#Tree Source

data Tree a

A rose tree which represents a random generated outcome, and all the ways in which it can be made smaller.

This tree is exactly the same as 'Data.Tree' in every way except that Applicative '<*>' and Monad '>>=' walk the tree in the reverse order. This modification is critical for shrinking to reach a minimal counterexample.

Constructors

Instances

#unfoldTree Source

unfoldTree :: forall b a. (b -> a) -> (b -> List b) -> b -> Tree a

Build a 'Tree' from an unfolding function and a seed value.

#unfoldForest Source

unfoldForest :: forall b a. (b -> a) -> (b -> List b) -> b -> List (Tree a)

Build a list of trees from an unfolding function and a seed value.

#shrinks Source

shrinks :: forall a. Tree a -> List (Tree a)

All the possible shrinks of this outcome. This should be ordered smallest to largest as if property still fails with the first shrink in the list then we will commit to that path and none of the others will be tried (i.e. there is no backtracking).

#outcome Source

outcome :: forall a. Tree a -> a

The generated outcome.

#foldTree Source

foldTree :: forall x b a. (a -> x -> b) -> (List b -> x) -> Tree a -> b

Fold over a 'Tree'.

#foldForest Source

foldForest :: forall x b a. (a -> x -> b) -> (List b -> x) -> List (Tree a) -> x

Fold over a list of trees.

#filterTree Source

filterTree :: forall a. (a -> Boolean) -> Tree a -> Tree a

Recursively discard any shrinks whose outcome does not pass the predicate. /Note that the root outcome can never be discarded./

#filterForest Source

filterForest :: forall a. (a -> Boolean) -> List (Tree a) -> List (Tree a)

Recursively discard any trees whose outcome does not pass the predicate.

#expandTree Source

expandTree :: forall a. (a -> List a) -> Tree a -> Tree a

Apply an additional unfolding function to an existing tree.

The root outcome remains intact, only the shrinks are affected, this applies recursively, so shrinks can only ever be added using this function.

If you want to replace the shrinks altogether, try:

unfoldTree f (outcome oldTree)