예제 #1
0
def test_simulation_clock_single_day_10min_res():
    clock = SimulationClock(
        start_date=date(2020, 1, 2),
        end_date=date(2020, 1, 2),
        simulation_time_step=timedelta(minutes=10),
    )

    [clock.tick() for _ in range(39)]

    assert clock.time == time(16)
    with pytest.raises(SimulationEndException):
        clock.tick()
예제 #2
0
def test_simulation_clock_daily():
    clock = SimulationClock(
        start_date=date(2020, 1, 6),
        end_date=date(2020, 1, 8),
        simulation_time_step=timedelta(days=1),
    )

    [clock.tick() for _ in range(3)]

    assert clock.time == time(16)
    assert clock.date == date(2020, 1, 8)
    with pytest.raises(SimulationEndException):
        clock.tick()
예제 #3
0
def test_simulation_clock_multi_day_weekend():
    clock = SimulationClock(
        start_date=date(2020, 1, 3),
        end_date=date(2020, 1, 6),
        simulation_time_step=timedelta(minutes=30),
    )

    [clock.tick() for _ in range(26)]

    assert clock.time == time(16)
    assert clock.date == date(2020, 1, 6)
    with pytest.raises(SimulationEndException):
        clock.tick()
예제 #4
0
def test_simulation_clock_real_time():
    clock = SimulationClock(
        start_date=date(2020, 1, 2),
        end_date=date(2020, 1, 2),
        simulation_time_step=timedelta(minutes=30),
        real_time_per_tick=1,
    )

    t1 = real_time.time()

    [clock.tick() for _ in range(2)]

    t2 = real_time.time()

    assert np.isclose(t2 - t1, 2, atol=0.1)
예제 #5
0
def sim_clock():
    c = SimulationClock(
        start_date=date(2020, 1, 6),
        end_date=date(2020, 1, 8),
        simulation_time_step=timedelta(minutes=1),
    )
    return c