So let's start with: don't use elm-check, use the new elm-test
<http://package.elm-lang.org/packages/elm-community/elm-test/2.0.0/> that
includes fuzz testing out of the box. A Fuzzer is basically a producer.
A recursive fuzzer is fine in theory. The problem you're running into is
that you're making a *tree* of arbitrary depth, and I think you are indeed
recursing forever. If a randomly-generated tree manages to get deeper than
a few levels (as is guaranteed when you have 100 of them), it's almost
impossible to get simultaneous leaves by chance to stop the tree from
growing until it runs out of memory or stack frames. The simplest solution
is to limit the height of the tree to two; a more sophisticated function
can use a decaying exponential or whatever to make branching less likely as
you get deeper.
That's the big idea but there are a few details worth mentioning. Fuzzers
don't support *map2* (and adding it is non-trivial), so we have to do some
contortion with creating fuzzers of tuples and then mapping over them.
Finally, don't be afraid to call *Fuzz.frequencyOrCrash* if you're
providing it a nonempty list literal.
Here is an example of a working Fuzzer Music:
fuzzMusic : Fuzzer Music
fuzzMusic =
Fuzz.frequencyOrCrash
[ ( 2, fuzzMusicSimple )
, ( 1, Fuzz.tuple ( fuzzMusicSimple, fuzzMusicSimple ) |> Fuzz.map
(uncurry Seq) )
, ( 1, Fuzz.tuple ( fuzzMusicSimple, fuzzMusicSimple ) |> Fuzz.map
(uncurry Par) )
]
fuzzMusicSimple : Fuzzer Music
fuzzMusicSimple =
Fuzz.tuple
( Fuzz.bool
, (Fuzz.intRange 1 8)
)
|> Fuzz.map
(\( b, i ) ->
if b then
Note i
else
Rest i
)
All of that said, I haven't tried a truly recursive Fuzzer and would love
to know if I'm totally wrong and it really is a recursive value problem,
not an infinite recursion problem.
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.