Conversation
…to test and reflect Driver class.
OO Ride ShareMajor Learning Goals/Code Review
Testing Requirements
Overall Feedback
Additional FeedbackGenerally this assignment was pretty reasonable. Your issues here were mostly around attention to detail. You got dinged for a lot of little things but overall you made reasonable decisions and your code was well organized. This was awesome:
Code Style Bonus AwardsWas the code particularly impressive in code style for any of these reasons (or more...?)
|
| raise ArgumentError if !valid_statuses.include?(@status) | ||
|
|
||
| raise ArgumentError if id <= 0 || id.nil? | ||
|
|
||
| raise ArgumentError if vin.length != 17 |
There was a problem hiding this comment.
Remember, error messages are helpful for your users and for debugging.
| raise ArgumentError if !valid_statuses.include?(@status) | |
| raise ArgumentError if id <= 0 || id.nil? | |
| raise ArgumentError if vin.length != 17 | |
| raise ArgumentError, "Bad status: #{status}" if !valid_statuses.include?(@status) | |
| raise ArgumentError, "Bad id: #{id}" if id <= 0 || id.nil? | |
| raise ArgumentError, "Bad vin: #{vin}" if vin.length != 17 |
| total_ratings = 0 | ||
| @trips.each do |trip| | ||
| total_ratings += trip.rating | ||
| end |
There was a problem hiding this comment.
You can simplify this using sum:
| total_ratings = 0 | |
| @trips.each do |trip| | |
| total_ratings += trip.rating | |
| end | |
| total_ratings = @trips.sum { |trip| trip.rating } |
| @trips.each do |trip| | ||
| if trip.cost <= 1.65 | ||
| total_revenue += 0 | ||
| else | ||
| trip_pay = trip.cost - 1.65 | ||
| trip_pay = trip_pay * 0.80 | ||
| total_revenue += trip_pay | ||
| end | ||
| end |
There was a problem hiding this comment.
Using each makes sense here. The logic is kind of complicated.
In case you're curious about the Enumerable version:
| @trips.each do |trip| | |
| if trip.cost <= 1.65 | |
| total_revenue += 0 | |
| else | |
| trip_pay = trip.cost - 1.65 | |
| trip_pay = trip_pay * 0.80 | |
| total_revenue += trip_pay | |
| end | |
| end | |
| total_revenue = @trips.select { |trip| trip.cost > 1.65 }.sum { |trip| (trip.cost - 1.65) * 0.8 } |
| def update_status | ||
| @status = :UNAVAILABLE | ||
| end |
There was a problem hiding this comment.
update_status is misleading since this method only ever sets @status to one value.
I would probably name this something like mark_unavailable or just omit this method entirely since you already have an attr_accessor on @status.
|
|
||
|
|
||
| if driver | ||
| @driver = driver |
There was a problem hiding this comment.
Since you're only really using driver_id I wouldn't bother storing @driver as well since it could be confusing.
| @driver = RideShare::Driver.new( | ||
| id: 7, | ||
| name: "Merl Glover Driver", | ||
| vin: "16026202330372367", | ||
| status: :AVAILABLE, | ||
| trips: [] | ||
| ) | ||
| @passenger = RideShare::Passenger.new( | ||
| id: 9, | ||
| name: "Merl Glover III", | ||
| phone_number: "1-602-620-2330 x3723", | ||
| trips: [] | ||
| ) | ||
|
|
||
| @trip1 = RideShare::Trip.new( | ||
| id: 8, | ||
| driver: @driver, | ||
| passenger: @passenger, | ||
| start_time: Time.new(2016, 8, 8), | ||
| end_time: Time.new(2016, 8, 9), | ||
| cost: 10, | ||
| rating: 5 | ||
| ) | ||
| @passenger.add_trip(@trip1) | ||
|
|
||
| @trip2 = RideShare::Trip.new( | ||
| id: 9, | ||
| driver: @driver, | ||
| passenger: @passenger, | ||
| start_time: Time.new(2016, 8, 11), | ||
| end_time: Time.new(2016, 8, 12), | ||
| cost: 11, | ||
| rating: 5 | ||
| ) | ||
| @passenger.add_trip(@trip2) |
There was a problem hiding this comment.
Incorrect indentation:
| @driver = RideShare::Driver.new( | |
| id: 7, | |
| name: "Merl Glover Driver", | |
| vin: "16026202330372367", | |
| status: :AVAILABLE, | |
| trips: [] | |
| ) | |
| @passenger = RideShare::Passenger.new( | |
| id: 9, | |
| name: "Merl Glover III", | |
| phone_number: "1-602-620-2330 x3723", | |
| trips: [] | |
| ) | |
| @trip1 = RideShare::Trip.new( | |
| id: 8, | |
| driver: @driver, | |
| passenger: @passenger, | |
| start_time: Time.new(2016, 8, 8), | |
| end_time: Time.new(2016, 8, 9), | |
| cost: 10, | |
| rating: 5 | |
| ) | |
| @passenger.add_trip(@trip1) | |
| @trip2 = RideShare::Trip.new( | |
| id: 9, | |
| driver: @driver, | |
| passenger: @passenger, | |
| start_time: Time.new(2016, 8, 11), | |
| end_time: Time.new(2016, 8, 12), | |
| cost: 11, | |
| rating: 5 | |
| ) | |
| @passenger.add_trip(@trip2) | |
| @driver = RideShare::Driver.new( | |
| id: 7, | |
| name: "Merl Glover Driver", | |
| vin: "16026202330372367", | |
| status: :AVAILABLE, | |
| trips: [] | |
| ) | |
| @passenger = RideShare::Passenger.new( | |
| id: 9, | |
| name: "Merl Glover III", | |
| phone_number: "1-602-620-2330 x3723", | |
| trips: [] | |
| ) | |
| @trip1 = RideShare::Trip.new( | |
| id: 8, | |
| driver: @driver, | |
| passenger: @passenger, | |
| start_time: Time.new(2016, 8, 8), | |
| end_time: Time.new(2016, 8, 9), | |
| cost: 10, | |
| rating: 5 | |
| ) | |
| @passenger.add_trip(@trip1) | |
| @trip2 = RideShare::Trip.new( | |
| id: 9, | |
| driver: @driver, | |
| passenger: @passenger, | |
| start_time: Time.new(2016, 8, 11), | |
| end_time: Time.new(2016, 8, 12), | |
| cost: 11, | |
| rating: 5 | |
| ) | |
| @passenger.add_trip(@trip2) |
| @driver = RideShare::Driver.new( | ||
| id: 7, | ||
| name: "Merl Glover Driver", | ||
| vin: "16026202330372367", | ||
| status: :AVAILABLE, | ||
| trips: [] | ||
| ) | ||
| @passenger = RideShare::Passenger.new( | ||
| id: 9, | ||
| name: "Merl Glover III", | ||
| phone_number: "1-602-620-2330 x3723", | ||
| trips: [] | ||
| ) | ||
|
|
||
| @trip1 = RideShare::Trip.new( | ||
| id: 8, | ||
| driver: @driver, | ||
| passenger: @passenger, | ||
| start_time: Time.new(2016, 8, 8, 21, 00, 00), | ||
| end_time: Time.new(2016, 8, 8, 21, 10, 00), | ||
| cost: 10, | ||
| rating: 5 | ||
| ) | ||
| @passenger.add_trip(@trip1) | ||
|
|
||
| @trip2 = RideShare::Trip.new( | ||
| id: 9, | ||
| driver: @driver, | ||
| passenger: @passenger, | ||
| start_time: Time.new(2016, 8, 11, 20, 00, 00), | ||
| end_time: Time.new(2016, 8, 11, 20, 8, 00), | ||
| cost: 11, | ||
| rating: 5 | ||
| ) | ||
| @passenger.add_trip(@trip2) |
There was a problem hiding this comment.
Incorrect indentation (see above).
Also if you'd like to share a before block between two describe blocks you can move it up to their parent describe block. (Or create a new parent describe block.)
|
|
||
| expect(dispatcher.trips).must_be_kind_of Array | ||
| expect(dispatcher.passengers).must_be_kind_of Array | ||
| # expect(dispatcher.drivers).must_be_kind_of Array |
There was a problem hiding this comment.
I'm not clear on why you deleted this. The provided tests are part of the requirements.
| expect(@trip.end_time).must_be_nil | ||
| expect(@trip.cost).must_be_nil | ||
| expect(@trip.rating).must_be_nil |
| @dispatcher.drivers.each do |driver| | ||
| driver.status = :UNAVAILABLE | ||
| end | ||
| expect{@dispatcher.request_trip(3)}.must_raise ArgumentError |
There was a problem hiding this comment.
Adding some spacing can make this read a little clearer.
| expect{@dispatcher.request_trip(3)}.must_raise ArgumentError | |
| expect { @dispatcher.request_trip(3) }.must_raise ArgumentError |
kaidamasaki
left a comment
There was a problem hiding this comment.
Most of these are pretty minor things that will help going forward.
Assignment Submission: OO Ride Share
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection