Does Haskell QuickCheck have the state machine based features that John Hughes' describes in the following talk and paper -
- http://publications.lib.chalmers.se/records/fulltext/232550/local_232550.pdf
- https://www.youtube.com/watch?v=zi0rHwfiX1Q
If not, how does one actually do stateful testing using Haskell's QuickCheck? For example, what is the best way to test a circular buffer using Haskell QuickCheck without reimplementing the core logic in the test itself.
I don't think there's any explicit support in QuickCheck, but I think the general approach in Haskell would be something like the following example.
It tests a test system (custom
List
instance) against a model (a real Haskell list). The key is to generate arbitrary sequences of stateful primitive operations (e.g.,Push
,Pop
, andIsEmpty
) and apply them to both the test system and the model in a monadic fashion, checking post conditions after each operation. In this case, the post conditions are just to test that operations that return values (pop
andisEmpty
) return the same values for the test system and model, but it could easily be modified to test other post conditions (or add pre-conditions).If a test fails, it will return a minimal sequence of operations applied to the empty list that causes the post conditions to fail.