I am trying to create a custom
Shrinker for a tree-like data type in order to use
Fuzz.custom for my fuzz tests for this data type.
My current Fuzzers use Fuzz.oneOf and an Int to make sure that the tree will only go five layers deep. The tests are starting to really slow down a lot, particularly when a test fails, but even successful runs are taking much longer than I am used to.
Looking at the Shrink module, I believe that I understand what is going on, but I do not see how to actually create the Shrinker that I need. That is, a
Shrinker is an alias for an
a -> LazyList a function, but the
LazyList type is an internal type that I cannot create directly. Thus, Shrinkers can only be created using the functions in the Shrink module. I do not see how to create a Shrinker for a custom type at all, without doing something extremely convoluted with the
I like the Tree example that is down in the “What are Shrinkers and why do we need them?” section of the module’s documentation. However, it does not explain how to actually write the Shrinker that is used in that example. Can anyone show me how to create a Shrinker for that Tree?
EDIT: I have an update about the test execution speed that caused me to want to do this, in case anyone is in a similar situation for a similar reason. When I added another branch to my convoluted tree-like data type, it crossed some threshold and could not complete the tests at all. They crashed after 20 minutes, due to running out of memory. Reducing the tree depth from 5 to 3 caused the tests to complete in ~15 seconds, which is good enough for me for now. While I would still like to know how to create a completely custom Shrinker, it is now a matter of getting better error messages when tests fail.