Skip to content

Commit

Permalink
Update time to BRD to 60, fix and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-sundstrom committed Dec 19, 2024
1 parent 6a06660 commit 428c9da
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/content/message/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Content.Message.Predictions do

{minutes, approximate?} =
cond do
prediction.stopped_at_predicted_stop? and (!terminal? or sec <= 30) -> {:boarding, false}
prediction.stopped_at_predicted_stop? and (!terminal? or sec <= 60) -> {:boarding, false}
!terminal? and sec <= 30 -> {:arriving, false}
!terminal? and sec <= 60 -> {:approaching, false}
min > 60 -> {60, true}
Expand Down
33 changes: 32 additions & 1 deletion test/content/messages/predictions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,25 @@ defmodule Content.Message.PredictionsTest do
assert Content.Message.to_string(msg) == "Ashmont BRD"
end


test "put boarding on the sign when train is stopped at terminal and departing in less than 60 seconds" do
prediction = %Predictions.Prediction{
seconds_until_departure: 59,
direction_id: 1,
route_id: "Mattapan",
destination_stop_id: "70261",
stopped_at_predicted_stop?: true,
boarding_status: "Stopped at station"
}

msg = Content.Message.Predictions.new(prediction, true, nil)

assert Content.Message.to_string(msg) == "Ashmont BRD"
end

test "does not put boarding on the sign too early when train is stopped at terminal" do
prediction = %Predictions.Prediction{
seconds_until_departure: 35,
seconds_until_departure: 61,
direction_id: 1,
route_id: "Mattapan",
destination_stop_id: "70261",
Expand All @@ -230,6 +246,21 @@ defmodule Content.Message.PredictionsTest do
assert Content.Message.to_string(msg) == "Ashmont 1 min"
end

test "puts minutes on sign when train is stopped at terminal but departure is >=1.5 minutes" do
prediction = %Predictions.Prediction{
seconds_until_departure: 92,
direction_id: 1,
route_id: "Mattapan",
destination_stop_id: "70261",
stopped_at_predicted_stop?: true,
boarding_status: "Stopped at station"
}

msg = Content.Message.Predictions.new(prediction, true, nil)

assert Content.Message.to_string(msg) == "Ashmont 2 min"
end

test "puts 1 min on the sign when train is not boarding, but is predicted to depart in less than a minute when offset" do
prediction = %Predictions.Prediction{
seconds_until_departure: 70,
Expand Down

0 comments on commit 428c9da

Please sign in to comment.