Imposing Restrictions
Explore how to impose restrictions on custom generators in PropEr to refine test data. Learn to use the such_that macro for filtering and let macro for transformations, improving the efficiency of property-based tests by excluding undesired inputs or transforming generated values.
We'll cover the following...
Why impose restrictions?
A common trait of all default generators is that they’re pretty broad in the data they generate, and from time to time, we’ll want to exclude specific counterexamples. In fact, we already needed to do that when we used the non_empty() generator to remove empty lists or binaries from the generated data set. Such a filter generator can be implemented with the ?SUCHTHAT(InstanceOfType, TypeGenerator, BooleanExp) macro.
The such_that macro
The macro works in a similar manner as let. The type_generator is bound to instance_of_type ...