It is well known that testing is an important part of the process of software engineering. Functional programs should be no exception. However functional programs are special in that often they can be totally described equationally. This is the fundamental idea behind QuickCheck, a tool that still dominates in the area of property-based testing. The idea? Generate test cases and automatically test them against the system. This year at ICFP there were a good collection of interesting talks and papers on using and extending this idea. Let’s talk about 2 that I saw:
-
First came Jan Midtgaard (et al)’s awesome demonstration of using QuickCheck to test compilers, finding obscure compiler bugs by randomly generating programs. If you have no tried testing compiler technology by randomly generating programs, you should try! It is very fun and there are many subtle points especially when you ask questions about side-effectful programs and Jan’s paper focuses on this particular subtelty. How can you test programs with undefined order-of-evaluation for instance? Generating
f(print 1, print 2)
has multiple valid answers depending on the order the arguments are evaluated! -
And then came the advancements on QuickSpec. 2010 gave us the original QuickSpec, which could, when given a program, enumerate laws about the program (discovering things like communitivity, associativity and identity laws) by testing. Max and Rudy have worked hard recently to extend this idea to be able to find laws involving implications and inequalities. This is a really neat feature. For example, they can discover things like
x <= 0 ==> x + abs x == 0
which is, while simple, certainly not a trivial property to discover.