import pytest
#from .exemplar_generators import EXEMPLAR_PRIMITIVE_GENERATORS
from .context import tohu
from tohu.v6.primitive_generators import Integer
from tohu.v6.derived_generators import Apply

def test_spawn_apply_generator():
    """
    Test that an Apply generator can be spawned and the spawned version produces the same elements.
    """
    num_items = 50

    def add(x, y):
        return x + y

    a = Integer(10, 99)
    b = Integer(10, 99)
    g = Apply(add, a, b)

    a.reset(seed=11111)
    b.reset(seed=22222)
    g.reset(seed=12345)

    # Let g generate a few items
    items_g_pre_spawn = list(g.generate(num_items))

    # Spawn g and let both generate a few more items
    h = g.spawn()
    items_g_post_spawn = list(g.generate(num_items))
    items_h_post_spawn = list(h.generate(num_items))

    # Reset h (together with a and b) and re-generate the full list of items
    a.reset(seed=11111)
    b.reset(seed=22222)
    h.reset(seed=12345)
    items_h_all = list(h.generate(2*num_items))

    # Verify that the items generated by h after spawning
    # as well as the full sets of items are identical.
    assert items_h_post_spawn == items_g_post_spawn
    assert items_h_all == items_g_pre_spawn + items_g_post_spawn

Add test that an Apply generator can be spawned and the spawned version produces the same elements
Add test that an Apply generator can be spawned and the spawned version produces the same elements
