Skip to content
Open
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
15 changes: 14 additions & 1 deletion lib/fares/fares.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ defmodule Fares do
# For the time being, these stops are ONLY served by the Winthrop Ferry
@winthrop_ferry_stops ["Boat-Aquarium", "Boat-Fan", "Boat-Quincy", "Boat-Winthrop"]

@loop_ferry_stops ["Boat-Commonwealth", "Boat-Aquarium", "Boat-Lovejoy", "Boat-Logan"]

@type ferry_name ::
:ferry_cross_harbor
| :ferry_inner_harbor
Expand Down Expand Up @@ -102,20 +104,31 @@ defmodule Fares do

def calculate_ferry(origin, destination)
when "Boat-Long" in [origin, destination] and "Boat-Logan" in [origin, destination] do
:ferry_cross_harbor
:ferry_east_boston
end

def calculate_ferry(origin, destination)
when "Boat-Long" in [origin, destination] and "Boat-Lewis" in [origin, destination] do
:ferry_east_boston
end

def calculate_ferry(origin, destination)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion/Question (non-blocking): I'm somewhat new to this code, but would it simplify this if we made a list of inner harbor stops, something like:

@inner_harbor_stops [
  "Boat-Lewis",
  "Boat-Logan",
  "Boat-Long",
  # etc...
]

and then compared like

def calculate_ferry(origin, destination)
    when origin in @inner_harbor_stops
    and destination in @inner_harbor_stops do
  :ferry_east_boston
end

I'm not sure that would work quite as simply as I just said, because 👇 trip starts and ends in the inner harbor, but goes out to Quincy in between, which does justify the $6.50 cost.... but I do think there's gotta be an easier way than trying to list out all of the possible origin/destination pairs.

Image

Maybe if we checked the origin and destination and all intermediate stops? I dunno <-- and that's part of why this comment is non-blocking! 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there's a simple way to calculate ferry fares based on intermediate stops given the current code structure. It seems only to from and route are the only things used in the fare calculation when no transfers are involved.

when "Boat-Long-North-5B" in [origin, destination] and "Boat-Lewis" in [origin, destination] do
:ferry_east_boston
end

def calculate_ferry(origin, destination)
when "Boat-Charlestown" in [origin, destination] and
"Boat-Long-South" in [origin, destination] do
:ferry_inner_harbor
end

def calculate_ferry(origin, destination)
when origin in @loop_ferry_stops and destination in @loop_ferry_stops and
origin != destination do
:ferry_east_boston
end

def calculate_ferry(origin, destination) when "Boat-Logan" in [origin, destination] do
:commuter_ferry_logan
end
Expand Down
4 changes: 2 additions & 2 deletions test/fares/fares_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ defmodule FaresTest do
expected_name =
cond do
has_logan? and has_charlestown? -> :ferry_cross_harbor
has_long? and has_logan? -> :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
Expand All @@ -90,7 +90,7 @@ defmodule FaresTest do
end

assert Fares.fare_for_stops(:ferry, origin_id, destination_id) == {:ok, expected_name},
"Unexpected result for #{origin_id} to #{destination_id}"
"Unexpected result for #{origin_id} to #{destination_id}, expected #{expected_name}"
Comment thread
lvachon1 marked this conversation as resolved.
end
end
end
Expand Down
Loading