Time - Lola - Yoyo#21
Conversation
…ater than start_time
… earlier than start time
…ed corresponding test
|
Cleaned up extra spaces and comments. |
OO Ride ShareMajor Learning Goals/Code Review
Testing Requirements
Overall Feedback
Additional FeedbackOverall, I think that this project clearly demonstrates that you all got a lot of learning out of this: your tests were clearly written, and your implementation all made sense. It's clear to me that this project is a victory :) You got through pretty a lot of the requirements. The biggest missing feature was implementing and testing compatibility of in-progress trips to the rest of your project. There are just some small subtle bugs, and there were enough of them, particularly around the logic of requesting a trip. Overall, your bugs were that you did everything twice on accident. Overall, I think that a good refactoring of trying to simplify logic would have saved you! I'm leaving some comments to try to lead you to thinking about that refactoring, but let me know if you have questions. I know that you all had some edge case tests on the Driver's average rating method, but you didn't anticipate a lot of other edge case tests for other instance methods. I'd encourage you to write more tests on instance methods that may rely on empty arrays or non-typical inputs. Based on the feedback I have this project, I would say "don't worry too much," but take this feedback as a sign to see what pieces of small logic, methods, and tests you may need to study more. Overall, the big learning goals of OOP and composition and inheritance were definitely met. Let me know if you have any questions on some of the more subtle logic detail that you had, or about anything in general! Code Style Bonus AwardsWas the code particularly impressive in code style for any of these reasons (or more...?)
|
| @trips.each do |trip| | ||
| rating_total += trip.rating | ||
| end | ||
| return rating_total / @trips.length.to_f.round(2) |
There was a problem hiding this comment.
This is a really good opportunity for refactoring to use an Enumerable method, like sum, instead of needing to increment rating_total in an each loop
| @@ -1,12 +1,12 @@ | |||
| require_relative 'test_helper' | |||
| require_relative "test_helper" | |||
There was a problem hiding this comment.
Bit of a nitpick, but the naming convention for these files should match the class that you're testing, so instead of trip_dispatch_test.rb, maybe trip_dispatcher_test.rb
| expect(driver.trips.length).must_equal 5 | ||
| end | ||
|
|
||
| it "Was the driver available" do |
There was a problem hiding this comment.
this test name feels vague, and i'm unsure what we're testing for. Could it have a more clear name?
| passengers_last_trip = passenger.trips[-1] | ||
| last_trips_driver = passengers_last_trip.driver_id | ||
| driver = dispatcher.find_driver(last_trips_driver) | ||
| expect(drivers.include?(last_trips_driver)).must_equal false |
There was a problem hiding this comment.
last_trips_driver is an ID... so it'll be 2 at this point. It won't be an instance of Driver. drivers is an array of instances of Drivers. It will never carry driver IDs by y'alls implementation. You all probably WANTED this line to be
expect(drivers.include?(driver)).must_equal falsesince driver is an instance of Driver, but it didn't pass
This test has the right intention-- it's checking that the list of available drivers no longer has the newly unavailable driver. But that's not how arrays of objects work! The drivers array will always have Driver 2, because it was built with the line drivers = dispatcher.find_available_drivers BEFORE Driver 2 got assigned a trip, so it includes Driver 2. There is no line of code that says "take out Driver 2 because Driver 2's status changed to unavailable."
If I were to refactor this line, I'd probably make the array of available drivers now, AFTER the Act step. I might do
expect(dispatcher.find_available_drivers).wont_include passenger.trips.last.driverThe test line below (directly checking the status of Driver 2) should remain, too!
| dispatch_driver[0].add_trip(trip) | ||
| dispatch_driver[0].status = :UNAVAILABLE | ||
| trip.passenger.add_trip(trip) | ||
| @trips << trip | ||
| trip.connect(trip.passenger) | ||
| trip.connect_driver(dispatch_driver[0]) |
There was a problem hiding this comment.
On line 65, you're calling the add_trip method on the driver.
But in line 70, you're also calling the connect_driver method on the trip... which calls the add_trip method on the driver! You're doing it twice!
Could you refactor the logic so that you're only adding the trip to the driver once?
| dispatch_driver[0].add_trip(trip) | ||
| dispatch_driver[0].status = :UNAVAILABLE | ||
| trip.passenger.add_trip(trip) | ||
| @trips << trip | ||
| trip.connect(trip.passenger) | ||
| trip.connect_driver(dispatch_driver[0]) |
There was a problem hiding this comment.
Similarly, on line 67, you're calling the add_trip method on the passenger,
but in line 69, you call connect on trip, which also calls the add_trip methd on passenger.
How do you need to refactor this logic so that we're only adding the trip to the passenger once? Where does it make the most sense to put this logic-- on TripDispatcher, Trip, or Passenger? What information do you need?
Lastly, what tests would you all have needed to write in order to catch this bug?
| dispatch_driver[0].add_trip(trip) | ||
| dispatch_driver[0].status = :UNAVAILABLE | ||
| trip.passenger.add_trip(trip) | ||
| @trips << trip | ||
| trip.connect(trip.passenger) | ||
| trip.connect_driver(dispatch_driver[0]) |
There was a problem hiding this comment.
One last thing to think about:
A line that sticks out of this logic is setting the driver's status to unavailable. But this should ALWAYS happen every time we connect a trip and a driver. Can the logic for changing a driver's status to unavilable live in the same spot as when a trip and driver get connected, or at least get moved out of this TripDispatcher method?
Assignment Submission: OO Ride Share
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection