How do I write a test in QuickCheck that tests the purpose of a function without repeating its implementation?
First, note that sometimes, a quickcheck property that states that a function behaves according to its current implementation is not completely worthless. You can use it for regression tests if you ever change the implementation. For example, if you optimize the definition of your fn
to use clever data structures, the Quickcheck property based on the old, more straight-forward implementation might prove helpful.
Second, you often want your Quickcheck properties to check high-level and declarative properties of your functions, while the implementation is usually lower-level and more directly executable. In this case, you could specify such properties as:
forall lists of points ps and directions d, the point
fn ps d
is in the list ps.forall lists of points ps, directions d, and forall points p in ps, the point p is not further along in the direction d than the point
fn ps d
.forall points p and forall directions d,
fn [p, origin] d
is p.
I'm not totally sure about the underlying geometry, so my examples might be stupid. But I hope the examples convey the general idea: The quickcheck properties could check for properties of the specification "being further along in a direction" without mentioning the particular algorithm.