|
Hegel 0.3.5
Property-based testing for C++
|
The base class of all generators. More...
#include <core.h>
Public Member Functions | |
| template<typename F> | |
| Generator< std::invoke_result_t< F, T > > | map (F f) const |
| */ | |
| template<typename F> | |
| std::invoke_result_t< F, T > | flat_map (F &&f) const |
| Chain generators for dependent generation. | |
| Generator< T > | filter (std::function< bool(const T &)> pred) const |
| Filter generated values by a predicate. | |
The base class of all generators.
| T | The type to generate values for |
|
inline |
Filter generated values by a predicate.
Creates a Generator that only produces values satisfying the predicate. The new Generator has the same type as this Generator.
So for example, if you want sorted lists of length N, you should generate sorted lists of length N, not generate random lists and filter by a predicate of 'length == N && is_sorted'. (Although the latter is logically correct, it would be a performance nightmare, so Hegel doesn't let you do it that way.)
For example, if you want sorted lists of length N, you should generate lists of length N and sort them, not generate random lists and filter by a predicate of 'length == N && is_sorted'.
| pred | Predicate that values must satisfy |
|
inline |
Chain generators for dependent generation.
Given a Generator<T> and a function T -> Generator<S>, creates a Generator<S>. Useful when generation parameters depend on previously generated values.
| F | Function type (T -> Generator<S>) |
| f | Function that takes a T and returns a Generator<S> |
|
inline |
*/
Transform generated values with a function.
Given a Generator<T> and a function T -> S, creates a Generator<S>.
This works by generating values from the Generator<T> and applying a transformation to each value.
Here's an example of how you'd use this:
| F | Function type (T -> S) |
| f | Transformation function with signature S f(T) |