In chapter 7, we worked through the design of a functional library for expressing parallel computations. We introduced the idea that an API should form an algebra —that is, a collection of data types, functions over these data types, and, importantly, laws or properties that express relationships between these functions. We also hinted at the idea that it might be possible to somehow validate these laws automatically. Validation is an important step, as we need to know that the code we write conforms with the laws we have imposed on our program. It would be of great benefit if we could somehow automate this validation process.
This chapter takes us toward a simple but powerful library for automated property-based testing. The general idea of such a library is to decouple the specification of program behavior from the creation of test cases. The programmer focuses on specifying the behavior of a program and giving high-level constraints on the test cases. The framework then automatically generates test cases that satisfy these constraints and runs tests to validate that the program behaves as specified.