Roll-over excess time from tasks.

This commit is contained in:
Dan Albert
2023-08-13 22:46:00 -07:00
parent 8c6b360e65
commit c00f853f34
6 changed files with 23 additions and 18 deletions

View File

@@ -14,8 +14,8 @@ class TestAction(WaypointAction):
def update_state(
self, state: ActionState, time: datetime, duration: timedelta
) -> None:
pass
) -> timedelta:
return timedelta()
def iter_tasks(self, ctx: TaskContext) -> Iterator[Task]:
yield from []

View File

@@ -39,19 +39,21 @@ def test_hold_tick() -> None:
t0 = datetime(1999, 3, 28)
task = Hold(lambda: t0 + timedelta(minutes=5), meters(8000), kph(400))
state = ActionState(task)
task.update_state(state, t0, timedelta())
assert not task.update_state(state, t0, timedelta())
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=1), timedelta(minutes=1))
assert not task.update_state(state, t0 + timedelta(minutes=1), timedelta(minutes=1))
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=2), timedelta(minutes=1))
assert not task.update_state(state, t0 + timedelta(minutes=2), timedelta(minutes=1))
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=3), timedelta(minutes=1))
assert not task.update_state(state, t0 + timedelta(minutes=3), timedelta(minutes=1))
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=4), timedelta(minutes=1))
assert not task.update_state(state, t0 + timedelta(minutes=4), timedelta(minutes=1))
assert not state.is_finished()
task.update_state(state, t0 + timedelta(minutes=5), timedelta(minutes=1))
assert not task.update_state(state, t0 + timedelta(minutes=5), timedelta(minutes=1))
assert state.is_finished()
task.update_state(state, t0 + timedelta(minutes=6), timedelta(minutes=1))
assert task.update_state(
state, t0 + timedelta(minutes=6), timedelta(minutes=1)
) == timedelta(minutes=1)
assert state.is_finished()