Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/elevator/hall_orders/cost.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,17 @@ defmodule Elevator.HallOrders.Cost do
normalized_state =
if state.direction in [:up, :down], do: state, else: %{state | direction: :down}

initial_time_ms =
if normalized_state.behavior == :door_open and elem(target, 0) != normalized_state.floor do
Elevator.door_open_duration_ms()
else
0
end

if target_cleared?(orders, target) do
0
else
do_simulate(orders, normalized_state, target, 0, @max_simulation_steps)
do_simulate(orders, normalized_state, target, initial_time_ms, @max_simulation_steps)
end
end

Expand Down
7 changes: 7 additions & 0 deletions test/single/cost_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ defmodule Test.Single.CostTest do
@travel_duration_ms + Elevator.door_open_duration_ms()
end

test "one floor away request includes current open-door delay" do
set_state(floor: 0, direction: :up, behavior: :door_open)

assert Cost.compute_cost({1, :hall_up}, %{}) ==
2 * Elevator.door_open_duration_ms() + @travel_duration_ms
end

test "unknown floor yields unreachable cost" do
set_state(floor: :unknown, direction: :down, behavior: :idle)

Expand Down
Loading