Space-Hala Haddad and Becca Roach#12
Conversation
Merge branch 'master' of https://github.com/halahaddad1/oo-ride-share
Merge branch 'master' of https://github.com/halahaddad1/oo-ride-share
Merge branch 'master' of https://github.com/halahaddad1/oo-ride-share
OO Ride ShareMajor Learning Goals/Code Review
Testing Requirements
Overall Feedback
Code Style Bonus AwardsWas the code particularly impressive in code style for any of these reasons (or more...?)
|
kaidamasaki
left a comment
There was a problem hiding this comment.
Good job. Here are some tips to clean things up. :)
| unless super(id) > 0 | ||
| raise ArgumentError | ||
| end |
There was a problem hiding this comment.
I'm pretty sure super doesn't do what you think it does. For initialize doesn't return a value it just initializes the CsvRecord and raises an ArgumentError if there's a bad id so checking here is unnecessary.
| unless super(id) > 0 | |
| raise ArgumentError | |
| end |
| @vin = vin | ||
|
|
||
| unless vin.length == 17 | ||
| raise ArgumentError |
There was a problem hiding this comment.
Including a message that contains the bad argument is helpful for debugging and your users.
| raise ArgumentError | |
| raise ArgumentError, "Bad vin: #{vin}" |
|
|
||
| module RideShare | ||
| class Trip < CsvRecord | ||
| attr_reader :id, :passenger, :passenger_id, :start_time, :end_time, :cost, :rating |
There was a problem hiding this comment.
I'm not clear on why you removed :id from this list.
| unless passenger_id == nil | ||
| if passenger_id < 1 | ||
| raise ArgumentError | ||
| end | ||
| end |
There was a problem hiding this comment.
Can be simplified as:
| unless passenger_id == nil | |
| if passenger_id < 1 | |
| raise ArgumentError | |
| end | |
| end | |
| raise ArgumentError, "Bad passenger_id: #{passenger_id}" unless passenger_id.nil? || passenger_id >= 1 |
| def available_drivers | ||
| available_drivers_list = [] | ||
| @drivers.each do |driver| | ||
| if driver.status == :AVAILABLE && (driver.trips.each { |trip| trip.end_time != nil }) |
There was a problem hiding this comment.
You almost certainly want all? here not each. (each always returns the original array, all? returns a boolean.)
| if driver.status == :AVAILABLE && (driver.trips.each { |trip| trip.end_time != nil }) | |
| if driver.status == :AVAILABLE && (driver.trips.all? { |trip| trip.end_time != nil }) |
| best_driver = nil | ||
| available_drivers_list.each do |driver| | ||
| # Pick first driver in array of available drivers that has nil or no trips | ||
| if driver.trips == nil || driver.trips == [] |
There was a problem hiding this comment.
Can be made a little clearer with:
| if driver.trips == nil || driver.trips == [] | |
| if driver.trips.nil? || driver.trips.empty? |
| driver2.add_trip(trip) | ||
| driver2.add_trip(trip2) | ||
|
|
||
| expect(driver2.total_revenue).must_equal ((43 + 56) - (1.65 * 2)) * 0.8 |
There was a problem hiding this comment.
You should use must_be_close_to when comparing Floats because they are imprecise.
| @dispatcher2.available_drivers.each do |driver| | ||
| if driver.status == :UNAVAILABLE | ||
| return false | ||
| else | ||
| return true | ||
| end | ||
| end |
There was a problem hiding this comment.
This method doesn't actually check all statuses. It only checks the first status since it returns on the first time through the each loop.
You probably wanted to use .all? instead of .each:
| @dispatcher2.available_drivers.each do |driver| | |
| if driver.status == :UNAVAILABLE | |
| return false | |
| else | |
| return true | |
| end | |
| end | |
| @dispatcher2.available_drivers.all? do | |
| driver.status != :UNAVAILABLE | |
| end |
Assignment Submission: OO Ride Share
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection