Hegel 0.18.2
Property-based testing for C++
Loading...
Searching...
No Matches
hegel::generators::IGenerator< T > Class Template Referenceabstract

The interface of a generator that draws without printing. More...

#include <core.h>

Inheritance diagram for hegel::generators::IGenerator< T >:
hegel::generators::IPrintableGenerator< T >

Public Types

using value_type = T
 The type of value this generator makes.

Public Member Functions

virtual T do_draw (const TestCase &tc) const =0
 Draw a value.
virtual uint64_t label () const
 The label that identifies this generator to the engine.
virtual T do_draw_filtered (const TestCase &tc, const std::function< bool(const T &)> &predicate) const
 Draw a value that predicate accepts, for filter().

Detailed Description

template<typename T>
class hegel::generators::IGenerator< T >

The interface of a generator that draws without printing.

Implement it to write a generator of your own. A generator that only implements IGenerator is not printable: make_generator() wraps it in an AnyGenerator, which TestCase::draw_silent() accepts and TestCase::draw() does not. To make it printable, implement IPrintableGenerator instead, or call AnyGenerator::print_with() or AnyGenerator::print_as_repr() on the handle.

do_draw() makes the value from draws on the test case: through other generators, with TestCase::draw_silent().

Every draw from a generator runs in a span (a group of draws that the engine shrinks as a unit) labelled with its label(), opened by the TestCase draw it is made through. A generator of your own is labelled with the name of its type unless it overrides label().

Template Parameters
TThe type of value the generator makes

Member Function Documentation

◆ do_draw()

template<typename T>
virtual T hegel::generators::IGenerator< T >::do_draw ( const TestCase & tc) const
pure virtual

Draw a value.

Parameters
tcThe test case to draw from.
Returns
The value.

Implemented in hegel::generators::IPrintableGenerator< T >.

◆ do_draw_filtered()

template<typename T>
virtual T hegel::generators::IGenerator< T >::do_draw_filtered ( const TestCase & tc,
const std::function< bool(const T &)> & predicate ) const
inlinevirtual

Draw a value that predicate accepts, for filter().

Draws at most three values, each in a span that is discarded when predicate rejects its value, then rejects the test case. A generator whose draws change state outside the choice sequence overrides this to undo what its rejected attempts did.

Parameters
tcThe test case to draw from.
predicateThe condition the value must satisfy.
Returns
The value.

◆ label()

template<typename T>
virtual uint64_t hegel::generators::IGenerator< T >::label ( ) const
inlinevirtual

The label that identifies this generator to the engine.

A generator built from other generators combines its own label with theirs (combine_labels()).

Returns
The label.

The documentation for this class was generated from the following file: