I love that the name is ‘theft’, as in the phrase “property is theft”.
Is this a relatively idiomatic example? It seems a bit verbose, especially given the need for manual shrinking. I suppose maybe C just can’t do better, but it does seem a bit daunting. That said, I’m coming from the QuickCheck perspective, where things are quite terse, so maybe my perspective is altering my view.
In any case, more ways to test code is always a good thing in my book.
What counts as idiomatic is still up for grabs. :) I have several tests for code I was able to open-source on github, but I’d love to see any portable ideas for making it less verbose. I’d prefer to avoid heavy preprocessor use, though.
C is more explicit about a lot of things than Haskell, Clojure, or Erlang, and also isn’t quite as good with function composition (conjoining generators). The current implementation doesn’t exclude it either, though – if someone finds a good way to compose and derive generators/shrinking rules for types, they should be able to drop it in as an extension. (Something heavy on function composition may also be a bit too out-there for typical C / embedded developers.) In the mean time, it’s possible to set up manually, while I continue experimenting.
Also: Most of the verbosity there is shared between properties – once I’ve set up how to generate and shrink random byte buffers, I can just say “compressing should never cause the array to grow by more than 1/8th”, “the compression state machine should terminate”, “data should round-trip through compression/un-compression”, etc., and share the same generate and shrink functions.