Search⌘ K

Gathering Statistics: Aggregating

Explore the aggregate function to collect and analyze test data categories in Erlang property-based testing. Understand how to generate and track statistics for custom generators, improving test coverage and identifying areas for enhanced input generation.

We'll cover the following...

Aggregate

The aggregate function is similar to the collect function with one simple exception. The aggregate function can take a list of categories to store. Let’s look at the function in action.

Code

Let’s start off with a basic property that uses the function. Take a look at it in the code below:

-module(prop_generators).
-include_lib("proper/include/proper.hrl").
-compile(export_all).

prop_aggregate() ->
    Suits = [club, diamond, heart, spade],
    ?FORALL(Hand, vector(5, {oneof(Suits), choose(1,13)}),
            aggregate(Hand, true)). % `true' makes it always pass
The aggregate function

This property’s generator creates a hand of five cards in a list. The ...