def test_should_apply_all_features():
    new_model = model & (
        PausedBy(partial(eq, 5)),
        BoundedBy(min=10, max=20),
    )
    maxing_step = SimulationStep(x0=flop, inputs=(6, ), duration=1)
    pausing_step = maxing_step._replace(inputs=(5, ))
    assert new_model.min == latest_sample(new_model(pausing_step))
    assert new_model.max == latest_sample(new_model(maxing_step))
def test_reset():
    """
    Should be reset to starting value when condition met
    """
    resettable = model & ResetBy(reset_cond=partial(eq, 0))

    assert latest_sample(resettable(sim_step)) == 20
Exemple #3
0
def test_pauses():
    """
    Should not flip when paused
    """
    var = model & PausedBy(id)
    step = SimulationStep(x0=1, inputs=(1, ), duration=1)

    assert latest_sample(var(step)) == 1
def test_paramterless_feature_creation():
    @feature_type()
    def Inverted(var, sim_step):
        ts, xs = var(sim_step)
        return (ts, tuple(-x for x in xs))

    step = SimulationStep(x0=flip, duration=1, inputs=tuple())
    assert -flop == latest_sample((model & Inverted())(step))
def test_coefficient_applied():
    coefficients = (1, 2, 3)
    step = models.SimulationStep(x0=0, duration=100, inputs=(3, 4, 5))
    var = models.LinearCombination(name='',
                                   human_name='',
                                   start=0,
                                   coefficients=coefficients)

    assert util.latest_sample(var(step)) == 26
Exemple #6
0
def test_process_interface():
    """
    Should behave like a variable
    """
    var = model & PausedBy(never)
    step = SimulationStep(x0=1, inputs=(0, ), duration=1)

    assert var.name == model.name
    assert var.start == model.start
    assert latest_sample(var(step)) == 0
Exemple #7
0
def is_on(ctrl, step):
    return latest_sample(ctrl(step)) == ctrl.on
Exemple #8
0
def test_onoff_off_when_signal_above_set_point():
    step = SimulationStep(x0=0, duration=1, inputs=(1, 0))
    ctrl = controller(start=0, hyst=0, on=1, off=0)
    assert latest_sample(ctrl(step)) == ctrl.off
Exemple #9
0
def test_onoff_adheres_to_variable_protocol():
    step = SimulationStep(x0=0, duration=1, inputs=(0, 0))
    ctrl = controller(start=0, hyst=0, on=1, off=0)
    assert ctrl.name == 'abcd'
    assert ctrl.start == 0
    assert latest_sample(ctrl(step)) in (ctrl.on, ctrl.off)
def test_latest_sample():
    assert latest_sample((tuple(range(20)), tuple(range(20, 40)))) == 39
def test_counter_one_step():
    ctr = counter(start=10, step=1)
    assert util.latest_sample(ctr(sim_step)) == 1
def test_counter_respects_counter():
    ctr = counter(start=0, step=2)
    assert util.latest_sample(ctr(sim_step)) == 2
def test_counter_counts_backwards():
    ctr = counter(start=0, step=-1)
    assert util.latest_sample(ctr(sim_step)) == -1