forked from AdaGold/oo-ride-share
-
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
oo-ride-share-maryam-kay #22
Open
kayxn23
wants to merge
53
commits into
Ada-C10:master
Choose a base branch
from
kayxn23:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
4bf1915
copy pasted the correct csv data, there was a bug in initial version
kayxn23 d65c41b
added Time.parse method to loadtrips method of TripDispatcher
kayxn23 a90385f
Trip#initialize trying to add check in intialize for date
marshi23 095f0c3
matching up any changes with pair
kayxn23 c57adc0
preparing for merge with pair's code
kayxn23 978b78c
Merge branch 'master' of https://github.com/kayxn23/oo-ride-share
kayxn23 85216bb
comments added
marshi23 1a14dbc
tests if start date is after end date
marshi23 98fa0d1
not sure why this code isn't working, try to pull from pair's code again
kayxn23 78f34a7
defined the duration method (to find duration of trip in seconds), ad…
kayxn23 149c0b0
defining User#net_expenditures tests not passing yet
marshi23 7966ef3
didn't make many changes, preparing this version to pull from my pair…
kayxn23 fff085d
user#net_expenditure method defined tests created and passing
marshi23 e110108
added net_expenditures method to my version
kayxn23 90614f3
defined method total_time_spent to User class
kayxn23 cea7f98
copy/pasted fix to bug in trips_test.csv
kayxn23 6432068
added DRIVER_TEST_FILE param to trip_dispatch_spec, it was a bug
kayxn23 bfcf7ac
fixed bugs in driver_spec.rb
kayxn23 c12b427
Clean up and matching two versions
marshi23 75b3dc4
matching versions
marshi23 e339f5f
fixing driver errors
marshi23 49f3687
added vehicle_id, driven_trips, status to Driver class, and passed te…
kayxn23 2d748bd
added .driver method to Trip class
kayxn23 6a79172
matching versisons
marshi23 e9ea7f3
load driver method defined
kayxn23 14587e7
Merge branch 'master' of https://github.com/kayxn23/oo-ride-share
kayxn23 95fb656
all test passing
marshi23 a20df14
Matching versions
marshi23 1d270f7
added find_driver method to TripDispatcher Class, successfuly passed …
kayxn23 d8892a8
TripDispatcher#load_trips method modified
marshi23 eba9dee
adding Driver#add_trip
marshi23 cf7b2c9
Driver#add_driven_trip method added
marshi23 e0c2611
created add_average_rating method for Driver class, passes all tests
kayxn23 f86b5d9
Driver#total_revenue method defined, test created and passed
marshi23 439a32f
created net_expenditures method for Driver Class, and tests which are…
kayxn23 6fa040e
Driver#net_expenditure added with one test
marshi23 6a71e68
driver test bug fix
marshi23 18e0747
added request_trip(user_id) method to Trip_Dispatcher, still need to …
kayxn23 bd72b5c
Trip#request_trip() two tests created and passing helper method for d…
marshi23 d4a931f
passenger trips modified using helper method add_trip
marshi23 bab24d3
odified request_trip()
marshi23 6ff76cd
syncing up
kayxn23 edf7a34
resolving merge conflict
kayxn23 b5a96c7
added new test to test if driver returned is available, and included …
kayxn23 2047598
just adding this change but will rever to b5a96c7 soon
marshi23 cdf15cd
commiting so that pair can be updated
marshi23 f8f496e
making two more tests left
marshi23 5e95afc
added tests for find_driver_by_availability, and edited test for requ…
kayxn23 591ee9f
uncommendted test in Trips to test if Trip stores an instance of driv…
kayxn23 3d0c936
making tests for driven trips and user trips
marshi23 adc1d60
created test to make sure the trips list for driver and user are upda…
marshi23 65c59ca
minor clean up and bug fix 1 test failing
marshi23 a2c2d36
comments made
marshi23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
require_relative 'spec_helper' | ||
require 'pry' | ||
|
||
USER_TEST_FILE = 'specs/test_data/users_test.csv' | ||
TRIP_TEST_FILE = 'specs/test_data/trips_test.csv' | ||
DRIVER_TEST_FILE = 'specs/test_data/drivers_test.csv' | ||
UNAVAILBLE_DRIVERS_TEST_FILE = 'specs/test_data/unavailable_drivers.csv' | ||
|
||
|
||
describe "TripDispatcher class" do | ||
describe "Initializer" do | ||
it "is an instance of TripDispatcher" do | ||
dispatcher = RideShare::TripDispatcher.new(USER_TEST_FILE, | ||
TRIP_TEST_FILE, DRIVER_TEST_FILE) | ||
expect(dispatcher).must_be_kind_of RideShare::TripDispatcher | ||
end | ||
|
||
it "establishes the base data structures when instantiated" do | ||
dispatcher = RideShare::TripDispatcher.new | ||
[:trips, :passengers].each do |prop| | ||
expect(dispatcher).must_respond_to prop | ||
end | ||
|
||
expect(dispatcher.trips).must_be_kind_of Array | ||
expect(dispatcher.passengers).must_be_kind_of Array | ||
expect(dispatcher.drivers).must_be_kind_of Array | ||
end | ||
end | ||
|
||
describe "find_user method" do | ||
before do | ||
@dispatcher = RideShare::TripDispatcher.new | ||
end | ||
|
||
it "throws an argument error for a bad ID" do | ||
expect{ @dispatcher.find_passenger(0) }.must_raise ArgumentError | ||
end | ||
|
||
it "finds a user instance" do | ||
passenger = @dispatcher.find_passenger(2) | ||
expect(passenger).must_be_kind_of RideShare::User | ||
end | ||
end | ||
|
||
|
||
# Uncomment for Wave 2 | ||
describe "find_driver method" do | ||
before do | ||
@dispatcher = RideShare::TripDispatcher.new(USER_TEST_FILE, TRIP_TEST_FILE, DRIVER_TEST_FILE) | ||
end | ||
|
||
it "throws an argument error for a bad ID" do | ||
expect { @dispatcher.find_driver(0) }.must_raise ArgumentError | ||
end | ||
|
||
it "finds a driver instance" do | ||
driver = @dispatcher.find_driver(2) | ||
expect(driver).must_be_kind_of RideShare::Driver | ||
end | ||
end | ||
|
||
describe "Driver & Trip loader methods" do | ||
before do | ||
@dispatcher = RideShare::TripDispatcher.new(USER_TEST_FILE, | ||
TRIP_TEST_FILE, DRIVER_TEST_FILE) | ||
end | ||
|
||
it "accurately loads driver information into drivers array" do | ||
# Unskip After Wave 2 | ||
first_driver = @dispatcher.drivers.first | ||
last_driver = @dispatcher.drivers.last | ||
|
||
|
||
expect(first_driver.name).must_equal "Driver2" | ||
expect(first_driver.id).must_equal 2 | ||
expect(first_driver.status).must_equal :UNAVAILABLE | ||
expect(last_driver.name).must_equal "Driver8" | ||
expect(last_driver.id).must_equal 8 | ||
expect(last_driver.status).must_equal :AVAILABLE | ||
end | ||
|
||
it "Connects drivers with trips" do | ||
skip # Unskip after wave 2 | ||
trips = @dispatcher.trips | ||
|
||
[trips.first, trips.last].each do |trip| | ||
driver = trip.driver | ||
expect(driver).must_be_instance_of RideShare::Driver | ||
expect(driver.trips).must_include trip | ||
end | ||
end | ||
end | ||
|
||
describe "User & Trip loader methods" do | ||
before do | ||
@dispatcher = RideShare::TripDispatcher.new(USER_TEST_FILE, | ||
TRIP_TEST_FILE, DRIVER_TEST_FILE) | ||
end | ||
|
||
|
||
it "accurately loads passenger information into passengers array" do | ||
first_passenger = @dispatcher.passengers.first | ||
last_passenger = @dispatcher.passengers.last | ||
|
||
|
||
expect(first_passenger.name).must_equal "User1" | ||
expect(first_passenger.id).must_equal 1 | ||
expect(last_passenger.name).must_equal "Driver8" | ||
expect(last_passenger.id).must_equal 8 | ||
end | ||
|
||
it "accurately loads trip info and associates trips with passengers" do | ||
trip = @dispatcher.trips.first | ||
passenger = trip.passenger | ||
|
||
expect(passenger).must_be_instance_of RideShare::User | ||
expect(passenger.trips).must_include trip | ||
end | ||
end | ||
|
||
describe "#request_trip(user_id)" do | ||
before do | ||
@dispatcher = RideShare::TripDispatcher.new(USER_TEST_FILE, | ||
TRIP_TEST_FILE, DRIVER_TEST_FILE) | ||
end | ||
# let (:new_dispatcher) { | ||
# dispatcher = RideShare::TripDispatcher.new(USER_TEST_FILE, | ||
# TRIP_TEST_FILE, DRIVER_TEST_FILE) | ||
# dispatcher.request_trip(5) | ||
# | ||
# } | ||
it "will return an instance of trip" do | ||
expect(@dispatcher.request_trip(4)).must_be_instance_of RideShare::Trip | ||
end | ||
|
||
it "will raise error if user does not exist" do | ||
expect {@dispatcher.request_trip(40000)}.must_raise ArgumentError | ||
end | ||
|
||
it "returns a driver who is AVAILABLE" do | ||
expect(@dispatcher.request_trip(1).driver.status).must_equal :AVAILABLE | ||
end | ||
|
||
it "returns a driver who is AVAILABLE" do | ||
expect{}(@dispatcher.request_trip(1).driver.status).must_raise ArgumentError | ||
end | ||
|
||
end | ||
|
||
describe "t"do | ||
before do | ||
|
||
@dispatcher = RideShare::TripDispatcher.new(passengers, drivers, trips) | ||
|
||
end | ||
end | ||
|
||
# it "will add trip to trips array" do | ||
# # new_dispatcher = RideShare::TripDispatcher.new(USER_TEST_FILE, | ||
# # TRIP_TEST_FILE, DRIVER_TEST_FILE) | ||
# # new_dispatcher.request_trip(5) | ||
# binding.pry | ||
# expect(@dispatcher.trips.length).must_equal 600 | ||
# # expect(new_dispatcher.trips.length).must_equal 601 | ||
# # expect{(new_dispatcher.trips.length > @dispatcher.trips.length)}.must_equal true | ||
# end | ||
#trips.length should be 1 longer than before | ||
|
||
# it "" do | ||
# end | ||
|
||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require 'pry' | ||
module RideShare | ||
|
||
class Driver < RideShare::User | ||
attr_reader :vin, :driven_trips, :status | ||
|
||
def initialize(input) | ||
super(input) | ||
|
||
if input[:vin] == nil || input[:vin] == "" || input[:vin].length > 17 | ||
raise ArgumentError.new('Invalid Vin') | ||
end | ||
@vin = input[:vin] | ||
@driven_trips = input[:driven_trips] ||= [] | ||
@status = input[:status] ||= :AVAILABLE | ||
raise ArgumentError.new("Invalid Status") unless @status == :AVAILABLE || @status == :UNAVAILABLE | ||
end | ||
|
||
|
||
# Modify this selected driver using a new helper method in Driver: | ||
# Add the new trip to the collection of trips for that Driver | ||
# Set the driver's status to :UNAVAILABLE | ||
def update_status(new_status) | ||
raise ArgumentError.new"Invalid Status" unless new_status == :AVAILABLE || new_status == :UNAVAILABLE | ||
@status = new_status | ||
end | ||
|
||
def add_driven_trip(trip) | ||
raise ArgumentError.new("Invalid Driver") unless trip.instance_of? RideShare::Trip | ||
@driven_trips << trip | ||
end | ||
|
||
|
||
def check_id(id) | ||
raise ArgumentError, "ID cannot be blank or less than zero. (got #{id})" if id.nil? || id <= 0 | ||
end | ||
|
||
def average_rating | ||
return 0 if driven_trips.empty? | ||
all_ratings = [] | ||
driven_trips.each do |trip| | ||
all_ratings << trip.rating | ||
end | ||
return average = (all_ratings.sum / all_ratings.length).to_f.round(1) | ||
end | ||
|
||
def total_revenue | ||
return 0 if driven_trips.empty? | ||
|
||
revenue = [] | ||
driven_trips.each do |trip| | ||
|
||
raise ArgumentError.new("Invalid, cost can't be negetive") if trip.cost < 0 | ||
num = trip.cost - 1.65 | ||
num = num - (num * 0.2) | ||
revenue << num | ||
end | ||
|
||
return revenue.sum | ||
end | ||
|
||
def net_expenditures | ||
return (super - total_revenue) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
end | ||
|
||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't need
average
you could simply: