TheSeamau5 / elm-check

Property Based Testing in Elm
70 stars 20 forks source link

Todo for next version #10

Open TheSeamau5 opened 9 years ago

TheSeamau5 commented 9 years ago
TheSeamau5 commented 9 years ago

Finally cracked how it would work! Yay!

import Random exposing (Generator)
import Lazy.List exposing (LazyList)
import Shrink exposing (Shrinker)
import RoseTree exposing (RoseTree(..))

type alias Investigator a = Generator (RoseTree a)

shrinkTree : Shrinker a -> a -> RoseTree a 
shrinkTree shrink a = 
  let 
      list = 
        shrink a 
  in 
      Rose a (Lazy.List.map (shrinkTree shrink) list)

makeInvestigator : Generator a -> Shrinker a -> Investigator a
makeInvestigator gen shrink = 
  Random.map (shrinkTree shrink) gen

map : (a -> b) -> Investigator a -> Investigator b
map = 
  Random.map << RoseTree.map