In a property-based test setting like Haskell's quickcheck for custom data structures, how do you generate test data for n-ary properties of relations, e.g., transitivity or symmetry? The implementation language does not matter, I think.
Here is a naive C++ example using rapidcheck (just because I have this tool at hand, right now):
rc::check("Double equality is symmetric.", [](double a, double b) {
RC_ASSERT(!(a == b) || (b == a)); // a == b ==> b == a
});
In such a naive case it is quite unlikely that the tool will generate many examples where the premise (a == b
) actually holds, so you end up wasting a lot of effort on meaningless tests. It gets even worse for 3-ary relations like transitivity.
Is there a general technique to tackle these issues? Do I need to generate equal pairs (for some constructive definition of "equals")? What about stuff like orderings?