Closed TheSeamau5 closed 9 years ago
One thing that is key is for List to be lazy. If List is not lazy, then it gets really easy to use up too much memory as each generator contains also the entire shrink tree.
Example code:
type alias Investigator a = Generator (RoseTree a)
type alias Shrinker a = a -> LazyList a
rt : Int -> Shrinker Int -> RoseTree Int
rt root shrinker =
Rose root (LazyList.map (\r -> rt r shrinker) (shrinker root))
map : (a -> b) -> Investigator a -> Investigator b
map f invA =
Random.map (RoseTree.map f) invA
This will appear in the next version
Clojure's test.check gets shrinking for free by fusing the generators and the shrinkers together.
The way they do this is by defining generators as follows:
Where a rose tree is defined as:
This would allow generators (currently Investigators) to be monads, functors, and all those nice things