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
2 changes: 1 addition & 1 deletion lib/fares/fare_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ defmodule Fares.FareInfo do
},
%{
mode: :ferry,
inner_harbor_price: "3.70",
inner_harbor_price: "2.40",
inner_harbor_month_price: "90.00",
inner_harbor_month_price_reduced: "30.00",
cross_harbor_price: "9.75",
Expand Down
76 changes: 40 additions & 36 deletions lib/fares/fares.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ defmodule Fares do
@express_route_set MapSet.new(@express_routes)

# For the time being, these stops are ONLY served by the Winthrop Ferry
@winthrop_ferry_stops ["Boat-Aquarium", "Boat-Fan", "Boat-Quincy", "Boat-Winthrop"]

@winthrop_ferry_stops [
"Boat-Aquarium",
"Boat-Fan",
"Boat-Quincy",
"Boat-Winthrop",
"Boat-Logan"
]
@inner_harbor_winthrop [
"Boat-Aquarium",
"Boat-Fan",
"Boat-Logan"
]
@loop_ferry_stops ["Boat-Commonwealth", "Boat-Aquarium", "Boat-Lovejoy", "Boat-Logan"]

@type ferry_name ::
Expand Down Expand Up @@ -88,43 +98,33 @@ defmodule Fares do
end

def calculate_ferry(origin, destination, between)
when "Boat-Long" in [origin, destination] and "Boat-Logan" in [origin, destination] do
long_way_around_trip_logic(between)
end

def calculate_ferry(origin, destination, between)
when "Boat-Long" in [origin, destination] and "Boat-Lewis" in [origin, destination] do
when "Boat-Long" in [origin, destination] and "Boat-Logan" in [origin, destination]
when "Boat-Long" in [origin, destination] and "Boat-Lewis" in [origin, destination]
when "Boat-Long-North-5B" in [origin, destination] and "Boat-Lewis" in [origin, destination]
when origin in @loop_ferry_stops and destination in @loop_ferry_stops and
origin != destination
when origin in @winthrop_ferry_stops and destination in @winthrop_ferry_stops do
long_way_around_trip_logic(between)
end

def calculate_ferry(origin, destination, between)
def calculate_ferry(origin, destination)
when origin in @inner_harbor_winthrop and destination in @inner_harbor_winthrop
when origin in @loop_ferry_stops and destination in @loop_ferry_stops and
origin != destination
when "Boat-Long" in [origin, destination] and "Boat-Logan" in [origin, destination]
when "Boat-Long-North-5B" in [origin, destination] and "Boat-Lewis" in [origin, destination] do
long_way_around_trip_logic(between)
:ferry_inner_harbor
end

def calculate_ferry(origin, destination, between)
when origin in @loop_ferry_stops and destination in @loop_ferry_stops and
origin != destination do
long_way_around_trip_logic(between)
def calculate_ferry(origin, destination)
when origin in @winthrop_ferry_stops and destination in @winthrop_ferry_stops do
:ferry_winthrop
end

def calculate_ferry(origin, destination, _) do
calculate_ferry(origin, destination)
end

def long_way_around_trip_logic(between) do
cond do
"Hingham" in between or "Hull" in between ->
:commuter_ferry

"Quincy" in between ->
:ferry_winthrop

true ->
:ferry_harbor_loop
end
end

@spec calculate_ferry(String.t(), String.t()) :: ferry_name
def calculate_ferry(origin, destination)
when "Boat-George" in [origin, destination] do
Expand All @@ -136,11 +136,6 @@ defmodule Fares do
:ferry_lynn
end

def calculate_ferry(origin, destination)
when origin in @winthrop_ferry_stops or destination in @winthrop_ferry_stops do
:ferry_winthrop
end

def calculate_ferry(origin, destination)
when "Boat-Charlestown" in [origin, destination] and "Boat-Logan" in [origin, destination] do
:ferry_cross_harbor
Expand All @@ -152,14 +147,23 @@ defmodule Fares do
:ferry_inner_harbor
end

def calculate_ferry(origin, destination) when "Boat-Logan" in [origin, destination] do
:commuter_ferry_logan
end

def calculate_ferry(_origin, _destination) do
:commuter_ferry
end

def long_way_around_trip_logic(between) do
cond do
"Hingham" in between or "Hull" in between ->
:commuter_ferry

"Quincy" in between or "Winthrop Landing" in between ->
:ferry_winthrop

true ->
:ferry_inner_harbor
end
end

@spec silver_line_rapid_transit?(Route.id_t()) :: boolean
def silver_line_rapid_transit?(<<id::binary>>),
do: id in @silver_line_rapid_transit_set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ defmodule Dotcom.ContentRewriters.LiquidObjects.FareTest do
|> Repo.all()
|> fare_result(:ferry) == "$1.10 – $4.85"

assert fare_request("ferry_inner_harbor:reduced") == {:ok, "$1.85"}
assert fare_request("ferry_inner_harbor:reduced") == {:ok, "$1.20"}
assert fare_request("ferry_east_boston:reduced") == {:ok, "$1.10"}
assert fare_request("ferry_cross_harbor:reduced") == {:ok, "$4.85"}
assert fare_request("ferry:reduced") == {:ok, "$1.10 – $4.85"}
Expand Down
2 changes: 1 addition & 1 deletion test/dotcom_web/views/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ defmodule DotcomWeb.ViewHelpersTest do
end)

assert fares == [
"mTicket App, paper ferry ticket, contactless payment, or cash $3.70",
"mTicket App, paper ferry ticket, contactless payment, or cash $2.40",
"CharlieTicket $90.00",
"mTicket App $80.00"
]
Expand Down
102 changes: 78 additions & 24 deletions test/fares/fares_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ defmodule FaresTest do

setup :verify_on_exit!

def assert_ferry(origin, destination, expected_fare) do
{_, received_fare} = Fares.fare_for_stops(:ferry, origin, destination)

if origin != destination do
assert received_fare == expected_fare,
"Unexpected fare for #{origin} to #{destination}, got #{received_fare} expected #{expected_fare}"
else
assert true
end
end

describe "calculate_commuter_rail/2" do
test "when the origin is zone 6, finds the zone 6 fares" do
assert Fares.calculate_commuter_rail("6", "1A") == {:zone, "6"}
Expand All @@ -23,8 +34,12 @@ defmodule FaresTest do
end

describe "fare_for_stops/3" do
# a subset of possible ferry stops
@ferries ~w(Boat-Hingham Boat-Charlestown Boat-Logan Boat-Long-South Boat-Lewis Boat-Blossom Boat-Winthrop)
@winthrop_quincy_ferry ~W(Boat-Fan Boat-Winthrop Boat-Logan Boat-Aquarium Boat-Quincy)
@hingham_hull_ferry ~W(Boat-Hingham Boat-Logan Boat-Long Boat-Hull)
@charlestown_ferry ~W(Boat-Charlestown Boat-Long-South)
@harbor_loop_ferry ~W(Boat-Lovejoy Boat-Aquarium Boat-Commonwealth Boat-Logan)
@east_boston_ferry ~W(Boat-Lewis Boat-Long-North-5B)
@lynn_ferry ~W(Boat-Blossom Boat-Long-North-5C)

test "returns the name of the commuter rail fare given the origin and destination" do
zone_1a_stop = Stop.build(:stop, %{zone: "1A"})
Expand Down Expand Up @@ -65,32 +80,71 @@ defmodule FaresTest do
assert Fares.fare_for_stops(:commuter_rail, cr_stop.id, other_stop.id) == :error
end

test "returns the name of the ferry fare given the origin and destination" do
for origin_id <- @ferries,
destination_id <- @ferries do
both = [origin_id, destination_id]
has_logan? = "Boat-Logan" in both
has_charlestown? = "Boat-Charlestown" in both
has_long? = "Boat-Long" in both
has_long_south? = "Boat-Long-South" in both
has_east_boston? = "Boat-Lewis" in both
has_lynn? = "Boat-Blossom" in both
has_winthrop? = "Boat-Winthrop" in both
test "returns the proper fare given a valid origin and destination on the hingham/hull lines" do
for origin <- @hingham_hull_ferry,
destination <- @hingham_hull_ferry do
both = [origin, destination]
hingham? = "Boat-Hingham" in both
hull? = "Boat-Hull" in both

expected_fare =
cond do
hingham? -> :commuter_ferry
hull? -> :commuter_ferry
true -> :ferry_inner_harbor
end

assert_ferry(origin, destination, expected_fare)
end
end

test "returns the proper fare given a valid origin and destination on the charlestown line" do
for origin <- @charlestown_ferry,
destination <- @charlestown_ferry do
expected_fare = :ferry_inner_harbor
assert_ferry(origin, destination, expected_fare)
end
end

test "returns the proper fare given a valid origin and destination on the lynn line" do
for origin <- @lynn_ferry,
destination <- @lynn_ferry do
expected_fare = :ferry_lynn
assert_ferry(origin, destination, expected_fare)
end
end

test "returns the proper fare given a valid origin and destination on the east boston line" do
for origin <- @east_boston_ferry,
destination <- @east_boston_ferry do
expected_fare = :ferry_inner_harbor
assert_ferry(origin, destination, expected_fare)
end
end

test "returns the proper fare given a valid origin and destination on the harbor loop line" do
for origin <- @harbor_loop_ferry,
destination <- @harbor_loop_ferry do
expected_fare = :ferry_inner_harbor
assert_ferry(origin, destination, expected_fare)
end
end

test "returns the proper fare given a valid origin and destination on the winthrop or quincy lines" do
for origin <- @winthrop_quincy_ferry,
destination <- @winthrop_quincy_ferry do
both = [origin, destination]
winthrop? = "Boat-Winthrop" in both
quincy? = "Boat-Quincy" in both

expected_name =
expected_fare =
cond do
has_logan? and has_charlestown? -> :ferry_cross_harbor
has_long? and has_logan? -> :ferry_east_boston
has_long_south? and has_charlestown? -> :ferry_inner_harbor
has_long? and has_east_boston? -> :ferry_east_boston
has_lynn? -> :ferry_lynn
has_winthrop? -> :ferry_winthrop
has_logan? -> :commuter_ferry_logan
true -> :commuter_ferry
winthrop? -> :ferry_winthrop
quincy? -> :ferry_winthrop
true -> :ferry_inner_harbor
end

assert Fares.fare_for_stops(:ferry, origin_id, destination_id) == {:ok, expected_name},
"Unexpected result for #{origin_id} to #{destination_id}, expected #{expected_name}"
assert_ferry(origin, destination, expected_fare)
end
end

Expand Down
Loading