A pool of previously generated values. A pool lets data flow from one rule to another, so a rule can act on a handle or identifier that an earlier rule produced rather than on a freshly drawn value.
More...
template<typename T>
class hegel::stateful::Pool< T >
A pool of previously generated values. A pool lets data flow from one rule to another, so a rule can act on a handle or identifier that an earlier rule produced rather than on a freshly drawn value.
Create one with its constructor and populate it with add. To draw from the pool, use the generators values_reusable (returns a value without removing it) and values_consumed (removes and returns a value).
A Pool is neither copyable nor movable. A state that embeds a pool is passed to run by reference and never copied.
Example: a resource allocator. The alloc rule creates a fresh resource and deposits it in the pool. The free rule draws one of those resource back out and releases it.
struct Allocator
int next_handle = 0;
std::vector<hegel::stateful::Rule<Allocator>> rules() {
return {
int h = m.next_handle++;
m.handles.add(h);
m.state.insert(h);
}),
hegel::stateful::Rule<Allocator>(
"free", [](hegel::TestCase& tc, Allocator& m) {
"h",
m.state.erase(h);
}),
};
}
};
HEGEL_TEST(allocator_state_machine)(hegel::TestCase& tc) {
Allocator machine(tc);
}
Handle to the currently-executing test case.
Definition test_case.h:40
T draw(const generators::Generator< T > &gen) const
Draw a random value from a generator.
Definition core.h:264
A pool of previously generated values. A pool lets data flow from one rule to another,...
Definition stateful.h:122
A rule is one possible action in a stateful test.
Definition stateful.h:289
Base class for a state machine. Holds the state and declares the rules and the invariants that act on...
Definition stateful.h:406
#define HEGEL_TEST(name,...)
Define a Hegel property test.
Definition hegel.h:575
Generator< T > values_consumed(Pool< T > &p)
Returns a value from the pool and removes it.
Definition stateful.h:242
void run(M &machine, TestCase &tc, const RunParams ¶ms={})
Executes a stateful test by repeatedly applying randomly chosen rules from machine to it and checking...
Definition stateful.h:508
- Template Parameters
-
| T | The type of variables in the pool. |