|
Hegel 0.18.2
Property-based testing for C++
|
The interface of a generator that draws without printing. More...
#include <core.h>
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(). | |
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().
| T | The type of value the generator makes |
|
pure virtual |
Draw a value.
| tc | The test case to draw from. |
Implemented in hegel::generators::IPrintableGenerator< T >.
|
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.
| tc | The test case to draw from. |
| predicate | The condition the value must satisfy. |
|
inlinevirtual |
The label that identifies this generator to the engine.
A generator built from other generators combines its own label with theirs (combine_labels()).