@hegeldev/hegel
    Preparing search index...

    Class Pool<T>

    A pool of previously generated values, for stateful tests.

    Create one per test case with new Pool(tc) (typically in the test body, alongside the initial state) and populate it with add. To draw from the pool, pass the generators it hands out to TestCase.draw:

    Drawing from an empty pool rejects the current step, as if by tc.assume(false).

    interface Allocator {
    live: Set<number>;
    handles: hegel.stateful.Pool<number>;
    }

    const allocator: hegel.stateful.StateMachine<Allocator> = {
    rules: {
    alloc: (_tc, state) => {
    const handle = allocate();
    state.live.add(handle);
    state.handles.add(handle);
    },
    free: (tc, state) => {
    // Draws a handle that a previous `alloc` step put in the pool.
    const handle = tc.draw(state.handles.valuesConsumed());
    release(handle);
    state.live.delete(handle);
    },
    },
    };

    hegel.test((tc) => {
    const state = { live: new Set<number>(), handles: new hegel.stateful.Pool<number>(tc) };
    hegel.stateful.run(tc, allocator, state);
    });

    Type Parameters

    • T
    Index

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get size(): number

      The number of values currently in the pool.

      Returns number

    Methods

    • Add a value to the pool.

      Parameters

      • value: T

      Returns void

    • A generator that removes each value it yields from the pool.

      Returns Generator<T>

    • A generator over the values in the pool; drawing does not remove them.

      Returns Generator<T>