-
Notifications
You must be signed in to change notification settings - Fork 37
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
Queues - Anna Barklund - ride-share-two #44
base: master
Are you sure you want to change the base?
Conversation
…les in the support directory for the tests
…ated two test csv-files for trip trip_spec_true.csv and trip_spec_false.csv.
…aned up comments for describe and it. Updated spec_helper.rb
…port files with headers. Trip#self.all_trips_for_driver tested and passed.
…assed. Created rider.rb and rider_spec.rb
…dy tested via the Trip class.
…e sections should be commented out when running the tests. Changed Driver#self.find to have a begin/rescue for cases when an id is not found. Subsequently changed the driver_spec for this method. Cleaned up trip_spec with respect to let()
… the rider_id isnot found. Subsequently updated the related test. Updated Rider#previous_trips tofunction correctly with uniq. Added tests for #previous_trips.
…Trip#self.find_all_trips_for_rider
…of individual parameters.
…bsequent edge test cases to driver_spec
…ed test cases for the methods initialize and self.all in class Driver with subsequent updating these methods topass the tests.
…any ArgumentErrors for the Trip methods initialize and self.all. Updated the Trip code to pass the tests. Updated support/trip_spec_false.csv with 20 trips and made 6 of them invalid. Updated the tests for the Trip method self.all
…od initialize. changed the code to pass the tests. Added a private method self.invalide_phone_num? to check if a phonenumber is valid according to North American Numbering Plan.
…escribe #self.find_all_trips_for_driver do in trip_spec.rb
…scribe #self.find_all_trips_for_rider do in trip_spec.rb
…Updated support/trip_spec_false.csv to cover all row at testing.
Ride ShareWhat We're Looking For
Great work overall! This code is clean and readable, your tests cover everything I'm looking for and your git habits appear strong. Keep up the good work. |
end | ||
|
||
it "Test of calculation of the average of the rating with number of rides == 0 " do | ||
driver100 = RideSharing::Driver.find(100) |
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.
Because you defined driver100
in the let block above, you don't need to re-find it here.
found_driver = self.all.select { |driver| driver.id == driver_id} | ||
begin | ||
raise ArgumentError.new("Id number #{driver_id} does not exist") if found_driver == [] | ||
rescue ArgumentError => exception |
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.
Typically you don't rescue
an exception that you yourself raise
. Instead, raise
-ing an exception is used to communicate to whoever called this method that there was a problem, and rescue
is used if some method raise
s an exception you know how to handle.
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.
In fact, you don't really even need to puts
anything here - returning nil
is sufficient to let the caller know that there was no Driver
with that ID.
return list_of_trips.map { |trip| trip.rating}.sum.to_f/ list_of_trips.length | ||
else | ||
puts "#{@name} with id##{@id} has not yet taken any trips.\nHence the average rating cannot be calcualted" | ||
return Float::NAN |
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.
As above, you don't need to puts
here - returning NAN
is sufficient.
end | ||
|
||
def previous_drivers | ||
drivers = list_of_trips.map { |trip| trip.find_driver}.delete_if {|driver| driver == nil}.uniq { |driver| driver.id} |
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.
Good use of enumerables here!
All of these are clear in what they do, but it still works out to a pretty long line. Something like
drivers = list_of_trips.map { |trip| trip.find_driver}
drivers.delete_if! {|driver| driver == nil}
drivers.uniq! { |driver| driver.id}
might be a little easier to read.
return drivers | ||
end | ||
|
||
private |
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.
Nice use of private
to hide methods that aren't part of your API.
Ride Share
Congratulations! You're submitting your assignment!
Comprehension Questions