advancedtelematic / quickcheck-state-machine

Test monadic programs using state machine based models
Other
203 stars 25 forks source link

Make model available to shrinker #262

Closed edsko closed 5 years ago

edsko commented 5 years ago

At the moment, the type of the shrinker is

shrinker :: cmd Symbolic -> [cmd Symbolic]

This means the shrinker for commands has no context available at all. When we take shrinking serious, this is quite a limitation. I've been trying to workaround this in a million different ways but I get stuck each time.

I propose that we generalize the type to

shrinker :: model Symbolic -> cmd Symbolic -> [cmd Symbolic]

so that the shrinker has the context available. Initially I thought that this would make shrinking more expensive, which is why I didn't go down this route before. But thinking about it more I now realize that this is not actually true: after all, shrinking is always followed by a validation step, so we compute the model anyway for all shrinks.

What this means is that shrinking cannot be the current shrinkList-then-validCommands; instead it must combine the two.

@stevana I will start working on a patch to do this. If you think this is a terrible idea, let me know ASAP, but I think it will make the library more general, without making shrinking more expensive.

stevana commented 5 years ago

I think this generalisation makes sense.

edsko commented 5 years ago

Awesome! Then I will work on a patch :)

stevana commented 5 years ago

Fixed in referenced PR.