Class: Hegel::Stateful::Pool
- Inherits:
-
Object
- Object
- Hegel::Stateful::Pool
- Defined in:
- lib/hegel/stateful/pool.rb,
sig/hegel.rbs
Overview
A pool of previously generated values, for a later stateful rule to draw one back out. Build one from the running test case, inside the machine's own constructor:
Hegel::Stateful::Pool.new(tc)
#add records a value under a fresh variable id (hegel_pool_add); #size
and #empty? read the Ruby-side count directly. Drawing goes through the
two generators below, not through this class's own storage, so a
chosen id is drawn (and shrunk, and recorded in a failure report) the
same way any other value is: #values_reusable leaves the drawn value in
the pool, #values_consumed removes it. hegel-rust's own Pool
A caller never frees a pool. docs/adr/0011 has the reason: #initialize
opens the native handle through Hegel::TestCase#new_pool, which records
it on tc itself, and Hegel::Runner frees every pool a test case
recorded once that test case is done -- the same "the test case owns
what it opened" split this library already uses for a state-machine
handle.
Defined Under Namespace
Classes: ValuesConsumed, ValuesReusable
Instance Method Summary collapse
-
#add(value) ⇒ Pool
Records
valueunder a fresh variable id from hegel_pool_add. -
#empty? ⇒ Boolean
True when no values are in the pool.
-
#initialize(tc) ⇒ Pool
constructor
A new instance of Pool.
-
#size ⇒ Integer
Number of values currently in the pool.
-
#values_consumed ⇒ ValuesConsumed
A Hegel::Generator over this pool's values: drawing it removes the chosen value, so it is never drawn again.
-
#values_reusable ⇒ ValuesReusable
A Hegel::Generator over this pool's values: drawing it leaves the chosen value in place, so the same value can be drawn again.
Constructor Details
#initialize(tc) ⇒ Pool
Returns a new instance of Pool.
30 31 32 33 34 |
# File 'lib/hegel/stateful/pool.rb', line 30 def initialize(tc) @tc = tc @pool = tc.new_pool @values = {} end |
Instance Method Details
#add(value) ⇒ Pool
Records value under a fresh variable id from hegel_pool_add.
Returns self, Set#add's own contract -- hegel-rust's own Pool::add
returns nothing instead, since Rust has no builder-chaining idiom for
this method to match.
50 51 52 53 54 |
# File 'lib/hegel/stateful/pool.rb', line 50 def add(value) variable_id = @tc.pool_add(@pool) @values[variable_id] = value self end |
#empty? ⇒ Boolean
True when no values are in the pool.
42 43 44 |
# File 'lib/hegel/stateful/pool.rb', line 42 def empty? @values.empty? end |
#size ⇒ Integer
Number of values currently in the pool.
37 38 39 |
# File 'lib/hegel/stateful/pool.rb', line 37 def size @values.size end |
#values_consumed ⇒ ValuesConsumed
A Hegel::Generator over this pool's values: drawing it removes the chosen value, so it is never drawn again.
64 65 66 |
# File 'lib/hegel/stateful/pool.rb', line 64 def values_consumed ValuesConsumed.new(@pool, @values) end |
#values_reusable ⇒ ValuesReusable
A Hegel::Generator over this pool's values: drawing it leaves the chosen value in place, so the same value can be drawn again.
58 59 60 |
# File 'lib/hegel/stateful/pool.rb', line 58 def values_reusable ValuesReusable.new(@pool, @values) end |