-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addy - Goeun - Edges - OO Ride Share #14
base: master
Are you sure you want to change the base?
Conversation
…thod to test that start time is before end time.
…er class for Trip Dispatcher
…s in before do block
…r to link trips to a drive during Load Trips method
…to driven_trips miss
…input is not a trip.
…ivers trips after taking into the trip cost and rideshare cost
…test for net_expenditures, made net_expenditures in driver.rb
…ver status and add trip is correctly working with request trip method. refactor unit test to check that end time was NilClass in request_trip
…hemself, and to return a message if there are no available drivers
…and returns nil if there are no available drivers
…g trips in progress in driver
…Driver class methods of net_expenditure, average_rating, and toatal revenue to ignore rides in progress.
Ride ShareWhat We're Looking For
|
end | ||
end | ||
|
||
def add_trip(trip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this method does exactly the same as User
's version of add_trip
so you can just leave the method out.
|
||
rating = 0.0 | ||
nil_count = 0 | ||
@driven_trips.each do |trip| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but you can also use select
to filter out incomplete trips.
return ((total_revenue - (1.65 * (@driven_trips.length - nil_count))) * 0.8) | ||
end | ||
|
||
def net_expenditures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
#{passengers.count} passengers>" | ||
end | ||
|
||
def find_available_driver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done, good helper method!
it "intializes the trip with cost, rating and end time set as nil" do | ||
trip = @dispatcher.request_trip(1) | ||
|
||
expect(trip.cost).must_be_instance_of NilClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also simply use
expect(trip.cost).must_be_nil
@trip = RideShare::Trip.new(@trip_data) | ||
end | ||
|
||
it "calculates the duration of trip in seconds" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also test incomplete trips.
OO Ride Share
Congratulations! You're submitting your assignment!
Comprehension Questions
User
for Wave 3 to add the in-progress-trip because it would be the same code asadd_trip
method. We also decided to return anil
if there are no available drivers. We thought about returning a string (but made our code WET) or ArgumentError (but it felt more like a probable edge case than a programming error) but decidednil
made most sense.Trip
is an object that is called frequently inTripDispatcher
,User
, andDriver
but it is not worked in as an inherited class. ATrip
loaded or added as its own object and can be used dynamically.User
andDriver
Driver
is a subclass ofUser
.User
keeps an array all trips a User takes as a passenger andDriver
keeps an array of all trips a User drives. The array that stores all the hashes of each trip a user rides as a passenger will also contain IDs of the driver of each trip, while the inverse is true for theDriver
subclass, that the hashes stored in the array of driven trips will have an passenger ID that links to theUser
class.Driver
class we wrote a test to test that the total revenue method will go through a driver’s driven trips, and sum the cost of all of the trips, subtract the appropriate fees, and assign the driver their commission, then divide by the array’s length. This should return a Driver’s total revenue. This test is nominal because it is a basic function of the method that we expect it to perform every time.super
to pass inUser
functionality inDriver
. We gained a better understanding of the relationship between parent and child classes as well as composition relationships. We know how to raise ArgumentErrors better now! We feel pretty good about reading csv files!