elm-explorations / test

Write unit and fuzz tests for Elm code.
https://package.elm-lang.org/packages/elm-explorations/test/latest
BSD 3-Clause "New" or "Revised" License
237 stars 39 forks source link

The document of `custom` has a mistake. #164

Closed Hexirp closed 3 years ago

Hexirp commented 3 years ago

The description of custom has a mistake on its code snippet .

https://github.com/elm-explorations/test/blob/74076ea9869d1ac70c8c7f674c87946784911506/src/Fuzz.elm#L93-L118

It uses Random.bool, however Random of elm/random 1.0.0 doesn't contain bool.

Hexirp commented 3 years ago

I suggest:

     type Question 
         = Name String 
         | Age Int 

     question = 
         let 
             generator = 
                 uniform True [False]
                     |> Random.andThen 
                         (\b -> 
                             if b then 
                                 Random.map Name genName 

                             else 
                                 Random.map Age (Random.int 0 120) 
                         ) 

             shrinker question = 
                 case question of 
                     Name n -> 
                         Shrink.string n |> Shrink.map Name 

                     Age i -> 
                         Shrink.int i |> Shrink.map Age 
         in 
         Fuzz.custom generator shrinker 
drathier commented 3 years ago

Good catch! Wanna make a PR?