Skip to content
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
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Aug 27, 2018
d65c41b
added Time.parse method to loadtrips method of TripDispatcher
kayxn23 Aug 27, 2018
a90385f
Trip#initialize trying to add check in intialize for date
marshi23 Aug 28, 2018
095f0c3
matching up any changes with pair
kayxn23 Aug 28, 2018
c57adc0
preparing for merge with pair's code
kayxn23 Aug 28, 2018
978b78c
Merge branch 'master' of https://github.com/kayxn23/oo-ride-share
kayxn23 Aug 28, 2018
85216bb
comments added
marshi23 Aug 28, 2018
1a14dbc
tests if start date is after end date
marshi23 Aug 28, 2018
98fa0d1
not sure why this code isn't working, try to pull from pair's code again
kayxn23 Aug 28, 2018
78f34a7
defined the duration method (to find duration of trip in seconds), ad…
kayxn23 Aug 28, 2018
149c0b0
defining User#net_expenditures tests not passing yet
marshi23 Aug 29, 2018
7966ef3
didn't make many changes, preparing this version to pull from my pair…
kayxn23 Aug 29, 2018
fff085d
user#net_expenditure method defined tests created and passing
marshi23 Aug 29, 2018
e110108
added net_expenditures method to my version
kayxn23 Aug 29, 2018
90614f3
defined method total_time_spent to User class
kayxn23 Aug 29, 2018
cea7f98
copy/pasted fix to bug in trips_test.csv
kayxn23 Aug 29, 2018
6432068
added DRIVER_TEST_FILE param to trip_dispatch_spec, it was a bug
kayxn23 Aug 29, 2018
bfcf7ac
fixed bugs in driver_spec.rb
kayxn23 Aug 29, 2018
c12b427
Clean up and matching two versions
marshi23 Aug 29, 2018
75b3dc4
matching versions
marshi23 Aug 29, 2018
e339f5f
fixing driver errors
marshi23 Aug 29, 2018
49f3687
added vehicle_id, driven_trips, status to Driver class, and passed te…
kayxn23 Aug 29, 2018
2d748bd
added .driver method to Trip class
kayxn23 Aug 29, 2018
6a79172
matching versisons
marshi23 Aug 30, 2018
e9ea7f3
load driver method defined
kayxn23 Aug 30, 2018
14587e7
Merge branch 'master' of https://github.com/kayxn23/oo-ride-share
kayxn23 Aug 30, 2018
95fb656
all test passing
marshi23 Aug 30, 2018
a20df14
Matching versions
marshi23 Aug 30, 2018
1d270f7
added find_driver method to TripDispatcher Class, successfuly passed …
kayxn23 Aug 30, 2018
d8892a8
TripDispatcher#load_trips method modified
marshi23 Aug 30, 2018
eba9dee
adding Driver#add_trip
marshi23 Aug 30, 2018
cf7b2c9
Driver#add_driven_trip method added
marshi23 Aug 30, 2018
e0c2611
created add_average_rating method for Driver class, passes all tests
kayxn23 Aug 30, 2018
f86b5d9
Driver#total_revenue method defined, test created and passed
marshi23 Aug 30, 2018
439a32f
created net_expenditures method for Driver Class, and tests which are…
kayxn23 Aug 31, 2018
6fa040e
Driver#net_expenditure added with one test
marshi23 Aug 31, 2018
6a71e68
driver test bug fix
marshi23 Aug 31, 2018
18e0747
added request_trip(user_id) method to Trip_Dispatcher, still need to …
kayxn23 Aug 31, 2018
bd72b5c
Trip#request_trip() two tests created and passing helper method for d…
marshi23 Aug 31, 2018
d4a931f
passenger trips modified using helper method add_trip
marshi23 Aug 31, 2018
bab24d3
odified request_trip()
marshi23 Aug 31, 2018
6ff76cd
syncing up
kayxn23 Aug 31, 2018
edf7a34
resolving merge conflict
kayxn23 Aug 31, 2018
b5a96c7
added new test to test if driver returned is available, and included …
kayxn23 Aug 31, 2018
2047598
just adding this change but will rever to b5a96c7 soon
marshi23 Aug 31, 2018
cdf15cd
commiting so that pair can be updated
marshi23 Aug 31, 2018
f8f496e
making two more tests left
marshi23 Sep 1, 2018
5e95afc
added tests for find_driver_by_availability, and edited test for requ…
kayxn23 Sep 1, 2018
591ee9f
uncommendted test in Trips to test if Trip stores an instance of driv…
kayxn23 Sep 1, 2018
3d0c936
making tests for driven trips and user trips
marshi23 Sep 1, 2018
adc1d60
created test to make sure the trips list for driver and user are upda…
marshi23 Sep 1, 2018
65c59ca
minor clean up and bug fix 1 test failing
marshi23 Sep 2, 2018
a2c2d36
comments made
marshi23 Sep 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions Untitled.rb
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
68 changes: 68 additions & 0 deletions lib/driver.rb
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)

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:

      return (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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end


end
end
26 changes: 23 additions & 3 deletions lib/trip.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require 'csv'
require 'pry'
require_relative 'user'
require 'time'

module RideShare
class Trip
attr_reader :id, :passenger, :start_time, :end_time, :cost, :rating
attr_reader :id, :passenger, :start_time, :end_time, :cost, :rating, :driver

def initialize(input)
@id = input[:id]
Expand All @@ -11,16 +14,33 @@ def initialize(input)
@end_time = input[:end_time]
@cost = input[:cost]
@rating = input[:rating]
@driver = input[:driver]

if @rating > 5 || @rating < 1
if @rating == nil
@rating = 0
elsif @rating > 5 || @rating < 1
# @rating > 5 || @rating < 1
raise ArgumentError.new("Invalid rating #{@rating}")
end

if @end_time == nil
@end_time = "some end time"
elsif @end_time < @start_time
raise ArgumentError.new("Invalid Date: End date is before or on start date!")
end

end

def inspect
def inspect #what does this first line do?
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} " +
"ID=#{id.inspect} " +
"PassengerID=#{passenger&.id.inspect}>"
end

def duration #duration of the trip in second
@duration = @end_time - @start_time

return @duration.to_i
end
end
end
Loading