Search⌘ K
AI Features

Imposing Restrictions

Explore how to impose restrictions on custom data generators in PropEr using the ?SUCHTHAT filter and ?LET transformation macros. Understand when to use filtering versus transformation to efficiently exclude unwanted data from your test cases, improving the precision of property-based testing in Erlang.

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 ?SUCHTHAT macro

The macro works in a similar manner as ?LET. The TypeGenerator is bound ...