Search⌘ K
AI Features

Dividing with ?LETSHRINK

Explore how the ?LETSHRINK macro in PropEr helps break down complex generated data into smaller parts for more efficient shrinking. Learn to apply this technique to recursive and branched structures like trees, improving your ability to isolate failure causes during property-based testing. Understand how using ?LETSHRINK enhances shrinking performance by allowing PropEr to select simpler subsets without losing the benefits of initial large test data.

We'll cover the following...

The ?LETSHRINK macro

As we use PropEr, we sometimes get stuck with generators creating huge data structures that take a long time to shrink and often don’t give very interesting results back. This often happens when some very low-probability failure is triggered, meaning that the framework had to generate a lot of data to find it, and has limited chances of shrinking things in a significant manner.

Whenever that happens, the ?LETSHRINK([Pattern, ...], [Generator, ...], Expression) is what we need. Let’s take a look at how we can use the generators in practice.

?LETSHRINK([A,B,C], [list(number()), list(number()), list(number())], 
        A ++ B ++ C)

The macro looks a lot like a regular ?LET macro, but with a few constraints. The first two arguments must always be lists, and the third argument is an operation ...