Saturday, May 02, 2009

FsCheck -- a quick hack for bytes

This exceptionally trivial piece of FsCheck:

surprised me by going Microsoft.FSharp.Core.FailureException : Geneflect: type not handled System.Byte. Especially so when the whole thing I was trying to write at the time was all about bytes, in arrays, in queues,...

So a little bit of diving into the FsCheck code later, a quick and dirty extension for handling bytes in Arbitrary.fs:

Later: now with fewer redundant parentheses and other clutter--

which now gives Ok, passed 100 tests. which is what I had been wanting in the first place.

Instrumenting the function under test as

shows a plausibly noisy set of inputs, so any remaining flaws will be subtle ones.

This example is believed to still be correct under the Feb 2010 CTP.


Kurt Schelfthout said...

Thanks Steve - FsCheck is currently indeed lacking some pretty important primitive generators (int64, float, long, uint come to mind, as well as byte, as you noticed).

Fortunately they're generally easy to write.

I'm sort of hoping that everyone that runs into this, posts or sends me generators. So thanks for stepping up, if you don't mind I'll add your byte generator to the FsCheck distribution.

Steve Gilham said...

Feel free! As the sidebar says "Code snippets released under the WTFPL".