Port all the QuickChecks!
Check out our ports for the amazing QuickCheck unit test framework. Gravy, we've got a lot of ports. We currently maintain QuickCheck for six programming languages, and we're working on ports for four more. Interested in porting QuickCheck to your favorite programming language?
- node-quickcheck - the Node.js port
We suggest you start by reading the code from node-quickcheck, one of the most readable ports with friendly, familiar C-style syntax.
The beginnings of a QuickCheck port include:
- A function gen_int(), to generate random integers
- A function for_all(), to call the generator and pass the random values to a property function.
Once you build these two functions, you can test for_all for things like is_odd(int) and multiple_of_two(int). Write your own properties, and see if they hold true for all integers.
QuickCheck doesn't end there. The next few steps:
- A function gen_array(gen) that accepts a generator and populates an array with values from the generator.
- A function gen_string() that uses gen_array(gen_char) to generate random strings.
- A more abstract for_all() that can test properties of unknown types and arity.
The last bit is tricky, because in most languages, it's hard to write for_all(). You'll need to master lambdas, so that you can pass and accept properties and generators, and you'll need to dig around in documentation to find an apply(function, arguments[]) function that can pass random values to properties once you've generated the values. If you can't find such a function, you can try to make one, or require all properties to manually extract their arguments from a list. qc, the C port, does this.
Don't forget to test, test, test, QuickCheck itself! A buggy test framework is no help at all. Finally, you may not have to port QuickCheck yourself, odds are there's a decent port available for you at Wikipedia. But what's the fun in that?