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

Queues - Tamiko Terada - ride-share-two #45

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
345fed9
updated Rakefile and created lib and spec files
TamikoT Mar 6, 2017
899ec59
require added to specs files
TamikoT Mar 6, 2017
0a5bb04
pseudocode structure added to each .rb file
TamikoT Mar 6, 2017
639dc3f
pseudocode edited for trip.rb
TamikoT Mar 6, 2017
582fc93
specs statements for trip
TamikoT Mar 7, 2017
052b1ed
specs created: trip#initialize
TamikoT Mar 7, 2017
bb94985
method added: trip.initialize to pass specs
TamikoT Mar 7, 2017
d08865a
method added: trip.initialize to pass specs
TamikoT Mar 7, 2017
7ce1c70
method added: trips.all created and passes specs
TamikoT Mar 7, 2017
f9a2296
specs added: driver#initialize specs created
TamikoT Mar 7, 2017
22bfa6d
specs passed: minor changes to pass tests
TamikoT Mar 7, 2017
1fcb11e
specs added: rider#initialize specs created
TamikoT Mar 7, 2017
fe3e924
method added: rider#initialize created and passed specs
TamikoT Mar 7, 2017
9cef625
specs edited: driver_spec.rb wording edited
TamikoT Mar 7, 2017
37fa1d9
specs created: driver#all specs created
TamikoT Mar 7, 2017
9e55409
method added: driver#all method created to read CSV
TamikoT Mar 7, 2017
00af1a6
specs added: rider#all specs created
TamikoT Mar 7, 2017
2c48100
specs pass with rake for each .all
TamikoT Mar 7, 2017
c3a4fc4
spec added: specs created for driver#find method
TamikoT Mar 7, 2017
1bf80b0
spec helper created and added
TamikoT Mar 7, 2017
9c2338a
specs require-relative edited to match spec_helper
TamikoT Mar 7, 2017
445daf2
method added: driver#find created and tested
TamikoT Mar 7, 2017
bedc350
specs added: rider#find to mirror driver#find specs
TamikoT Mar 7, 2017
fc250a4
method added: rider#find created and passed tests
TamikoT Mar 7, 2017
31bb8b4
specs added: trip#find_driver and trip#find_rider
TamikoT Mar 7, 2017
57ee0b3
created unfinished.md to track project progress
TamikoT Mar 7, 2017
bd6a947
method added: trip#find_driver/rider created and passed tests
TamikoT Mar 7, 2017
c9066e6
method added: trip#by_rider, trip#by_driver created to pass tests
TamikoT Mar 7, 2017
fddd7fb
specs added: rider#past_driver, rider#past_rides specs created
TamikoT Mar 7, 2017
3a68a02
method added: rider#past_driver, rider#past_rides and passes tests
TamikoT Mar 7, 2017
5ec88f8
specs added: driver#trips specs created
TamikoT Mar 7, 2017
1793d50
method added: driver#trips method created
TamikoT Mar 7, 2017
618a8c2
specs added: driver#avg_rating specs created
TamikoT Mar 7, 2017
495cb6f
to do list updated and rake run
TamikoT Mar 8, 2017
ff6c052
specs edited: driver specs DRY with let/before
TamikoT Mar 8, 2017
ff23a56
.gitignore file added and include coverage
TamikoT Mar 8, 2017
19e41bd
specs edited: require_relative changes for spec_helper
TamikoT Mar 8, 2017
67f822a
specs edited: specs refactored with let and before
TamikoT Mar 8, 2017
2172caa
class edit: refactored comments in trip, driver, rider
TamikoT Mar 8, 2017
4ed0d3a
specs added: driver#initialize check for vin validation
TamikoT Mar 8, 2017
755a912
test to .gitignore coverage file
TamikoT Mar 8, 2017
eccc54e
formatting cleaned up and comments reduced
TamikoT Mar 9, 2017
4ab1496
.gitignore file updated
TamikoT Mar 9, 2017
adc0392
change path of CSV files
TamikoT Mar 9, 2017
1741fde
error classes created for no_driver, no_rider
TamikoT Mar 10, 2017
4434e60
id and rating changed to numerical at intake
TamikoT Mar 10, 2017
10a1b85
exceptions: custom created for missing account and duplicate account
TamikoT Mar 13, 2017
8172050
exceptions: custom one for rider and driver removed
TamikoT Mar 13, 2017
7925747
exceptions: custom exception created for invalid vin
TamikoT Mar 13, 2017
8a0b8f9
specs edited: match styles of before, let, and variable naming
TamikoT Mar 13, 2017
6f56ef0
refactor comments in the class files
TamikoT Mar 13, 2017
386d7d7
edit comments in lib files
TamikoT Mar 13, 2017
8693b18
specs edit: add expectations to .new specs
TamikoT Mar 13, 2017
2e666ad
edits for submissions
TamikoT Mar 13, 2017
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
Prev Previous commit
edits for submissions
TamikoT committed Mar 13, 2017
commit 2e666adf5a7b66f9adf7f0b0b34c32f1b839bde7
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"covered_percent": 99.56
"covered_percent": 97.63
}
}
157 changes: 106 additions & 51 deletions coverage/.resultset.json
Original file line number Diff line number Diff line change
@@ -14,53 +14,53 @@
1,
null,
1,
6209,
6209,
6209,
6209,
6911,
6911,
6911,
6911,
null,
null,
null,
1,
62,
69,
null,
62,
69,
null,
null,
null,
null,
6200,
6900,
null,
62,
69,
null,
null,
null,
1,
5,
6,
null,
null,
null,
null,
1,
null,
14,
2,
2,
26,
3,
3,
null,
null,
null,
1,
null,
13,
1313,
13,
11,
1111,
11,
10,
1,
1,
2,
2,
null,
0,
null,
10,
11,
null,
null,
null,
@@ -69,13 +69,13 @@
null,
1,
null,
6209,
6209,
6203,
6911,
6911,
6909,
1,
null,
7,
6,
3,
2,
null,
1,
null,
@@ -116,35 +116,44 @@
1,
null,
1,
17409,
17409,
17409,
18909,
18909,
18909,
null,
null,
null,
1,
58,
63,
null,
58,
63,
null,
null,
null,
null,
17400,
18900,
null,
58,
63,
null,
null,
null,
1,
null,
7,
2107,
7,
7,
0,
0,
null,
0,
null,
7,
null,
null,
null,
null,
1,
3,
5,
null,
null,
null,
@@ -159,41 +168,42 @@
null
],
"/Users/tamikulon/ada/classwork/week5/ride-share-two/lib/trip.rb": [
1,
1,
null,
null,
1,
1,
1,
null,
null,
1,
40807,
40807,
40807,
40807,
40807,
45608,
45608,
45608,
45608,
45608,
45608,
null,
null,
null,
1,
68,
76,
null,
68,
76,
null,
null,
null,
null,
null,
null,
40800,
45600,
null,
68,
76,
null,
null,
null,
1,
4808,
6611,
null,
null,
null,
@@ -215,6 +225,24 @@
null,
null,
null,
1,
null,
null,
1,
null,
45608,
45608,
0,
0,
null,
null,
null,
null
],
"/Users/tamikulon/ada/classwork/week5/ride-share-two/lib/invalid_rating_error.rb": [
1,
1,
null,
null
],
"/Users/tamikulon/ada/classwork/week5/ride-share-two/specs/rider_spec.rb": [
@@ -264,13 +292,15 @@
1,
null,
null,
null,
1,
null,
1,
1,
1,
null,
null,
null,
1,
null,
1,
@@ -300,10 +330,22 @@
null,
1,
1,
1,
null,
null,
1,
1,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
@@ -326,19 +368,26 @@
1,
null,
1,
20,
20,
20,
8,
null,
1,
19,
19,
19,
null,
null,
1,
1,
1,
18,
18,
18,
null,
null,
1,
3,
null,
1,
1,
1,
1,
1,
null,
@@ -351,6 +400,7 @@
1,
null,
null,
null,
1,
1,
1,
@@ -372,6 +422,7 @@
1,
null,
null,
null,
1,
null,
1,
@@ -381,6 +432,7 @@
1,
null,
null,
null,
1,
null,
1,
@@ -402,21 +454,24 @@
1,
null,
null,
null,
1,
3,
null,
1,
1,
null,
null,
null,
null,
1,
3,
null,
1,
1,
null,
null,
1,
1,
1,
null,
null,
null,
1,
@@ -455,6 +510,6 @@
null
]
},
"timestamp": 1489382956
"timestamp": 1489420402
}
}
1,252 changes: 799 additions & 453 deletions coverage/index.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lib/driver.rb
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ def trips
# instance method: avg_rating (calls .trips)
def avg_rating
# average rating of all trips for this Driver instance
ratings = trips.map {|trip| trip.rating } # calls trips method above
ratings = trips.map {|trip| trip.rating.to_f } # calls trips method above
average = ratings.inject(:+)/ratings.length
return average.round(2) # a rounded float
end
@@ -49,8 +49,8 @@ def self.find(driver_id)
# finds an instance of Driver by ID (calls .all)
begin
found_driver = all.select { |instance| instance.id == driver_id }
raise MissingAccountError.new("Driver ID not found.") if found_driver.empty?
raise DuplicateAccountError.new("Duplicate accounts found.") if found_driver.length > 1
raise MissingAccountError.new("Missing Driver: Driver_#{driver_id}.") if found_driver.empty?
raise DuplicateAccountError.new("Duplicates found: Driver_#{driver_id}.") if found_driver.length > 1
rescue MissingAccountError => alert
puts alert.message
rescue DuplicateAccountError => alert
@@ -64,11 +64,11 @@ def self.find(driver_id)

# instance method: vin_verify (calls custom exceptions)
def vin_verify(vin)
# raises exceptions if vin is not 17-char. or alphanumeric
# exceptions if vin is not 17-char. or alphanumeric
begin
raise MissingVinError.new("Missing VIN, Driver_#{@id}!") if vin == nil
raise MissingVinError.new("Missing VIN: Driver_#{@id}.") if vin == nil
if (vin.length == 17 && !vin.match(/\A[a-zA-Z0-9]*\z/).nil?) == false
raise InvalidVinError.new("Invalid VIN, Driver_#{@id}!")
raise InvalidVinError.new("Invalid VIN: Driver_#{@id}.")
end
rescue MissingVinError => alert
puts alert.message
4 changes: 4 additions & 0 deletions lib/invalid_rating_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module RideShare
class InvalidRatingError < StandardError
end
end
13 changes: 11 additions & 2 deletions lib/rider.rb
Original file line number Diff line number Diff line change
@@ -28,8 +28,17 @@ def self.all
# class method: .find (calls .all)
def self.find(rider_id)
# finds an instance of Rider by ID
found_rider = all.select { |instance| instance.id == rider_id }
return found_rider[0] # a Rider instance
begin
found_rider = all.select { |instance| instance.id == rider_id }
raise MissingAccountError.new("Missing rider: Rider_#{rider_id}.") if found_rider.empty?
raise DuplicateAccountError.new("Duplicates found: Rider_#{rider_id}.") if found_rider.length > 1
rescue MissingAccountError => alert
puts alert.message
rescue DuplicateAccountError => alert
puts alert.message
else
return found_rider[0] # a Rider instance
end
end

# instance method: .past_trips (calls Trip class)
18 changes: 16 additions & 2 deletions lib/trip.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
require 'csv'
require_relative 'invalid_rating_error'

# Trip class, subclass of RideShare
module RideShare
class Trip
attr_reader :id, :driver_id, :rider_id, :date, :rating, :all

# creates new trip with id, driver_id, rider_id, date, and rating
def initialize(trip_info={})
@id = trip_info[:id].to_i
@driver_id = trip_info[:driver_id].to_i
@rider_id = trip_info[:rider_id].to_i
@date = trip_info[:date]
@rating = trip_info[:rating].to_f
@rating = trip_info[:rating].to_i
rating_verification(@rating)
end

# class method: .all (calls .new)
@@ -32,6 +33,7 @@ def self.all

# class method: .by_rider (calls .all)
def self.by_rider(rider_id)

all.select { |trip| trip.rider_id == rider_id }
# returns all Trip instances for specified rider_id
end
@@ -53,5 +55,17 @@ def find_rider
RideShare::Rider.find(@rider_id)
# returns Rider instance associated with this Trip instance
end

private

# instance method: rating_verification (calls custom exception)
def rating_verification(rating)
# exception if rating is not 1,2,3,4,5
begin
raise InvalidRatingError.new("Invalid rating: Trip_#{@id}.") if (1..5).include?(rating) == false || rating == nil
rescue InvalidRatingError => alert
puts alert.message
end
end
end
end
98 changes: 67 additions & 31 deletions specs/driver_spec.rb
Original file line number Diff line number Diff line change
@@ -13,30 +13,44 @@
end

describe "Driver#initialize" do
it "creates a new instance of trip" do
it "creates a Driver instance" do
example_driver.must_be_instance_of RideShare::Driver
end

it "passes in driver data correctly" do
it "passes in Driver data with keys" do
#9,Simone Hackett,4RA34A5K3YPN8H5P4
example_driver.must_respond_to :id
example_driver.must_respond_to :name
example_driver.must_respond_to :vin

example_driver.id.must_equal 9
example_driver.name.must_equal "Simone Hackett"
example_driver.vin.must_equal "4RA34A5K3YPN8H5P4"
end

it "throws an ArgumentError if the vin is invalid" do
# EDGE CASE
it "prints message when passed invalid vin" do
proc {
RideShare::Driver.new(id: "9", name: "Simone Hackett", vin: "4RA34A5K3YPN8H5P40000000")
}.must_raise ArgumentError
}.must_output("Invalid VIN: Driver_9.\n")
end

# EDGE CASE
it "prints message when passed no vin" do
proc {
RideShare::Driver.new(id: "9", name: "Simone Hackett")
}.must_output("Missing VIN: Driver_9.\n")
end

it "is silent when passed good vin" do
proc {
example_driver
}.must_be_silent
end

it "can create a new driver with a missing vin" do
it "can initialize with missing data" do
no_vin_driver = RideShare::Driver.new(id: "87", name: "Tamiko Terada")
no_vin_driver.vin.must_equal nil
no_vin_driver.must_be_instance_of RideShare::Driver
no_vin_driver.vin.must_be_nil
end
end

@@ -45,7 +59,7 @@
all_drivers.must_be_kind_of Array
end

it "each returned element is a Driver instances" do
it "each returned element is a Driver instance" do
all_drivers.each do |each_driver|
each_driver.must_be_instance_of RideShare::Driver
end
@@ -55,13 +69,15 @@
all_drivers.length.must_equal 100 # rows in CSV file
end

# EDGE CASE
it "correctly reads in the first row of the CSV file" do
# last row of data: 1,Bernardo Prosacco,WBWSS52P9NEYLVDE9
all_drivers[0].id.must_equal 1
all_drivers[0].name.must_equal "Bernardo Prosacco"
all_drivers[0].vin.must_equal "WBWSS52P9NEYLVDE9"
end

# EDGE CASE
it "correctly reads in the last row of the CSV file" do
# last row of data: 100,Minnie Dach,XF9Z0ST7X18WD41HT
all_drivers[-1].id.must_equal 100
@@ -70,48 +86,68 @@
end
end

describe "Driver#find" do
let(:driver_found) { RideShare::Driver.find(31) }

it "return value is a Driver instance" do
driver_found.must_be_instance_of RideShare::Driver
end

it "finds the correct instance of Driver" do
driver_found.id.must_equal 31
driver_found.name.must_equal "Sheila VonRueden"
driver_found.vin.must_equal "KPH9RLSZ9YKNVMGH2"
end

it "will not find a nonexistent Driver" do
RideShare::Driver.find(999)
end
end

describe "Driver#Trips" do
let (:example_driver_trips) { RideShare::Driver.new({id: "9"}).trips }
let (:example_driver_trips) { example_driver.trips }

it "returns value as an Array" do
example_driver_trips.must_be_kind_of Array
end

it "first element is an instance of Trip" do
it "first Trip is associated with the expected driver" do
example_driver_trips[0].must_be_instance_of RideShare::Trip
example_driver_trips[0].driver_id.must_equal 9
end

it "last element is a Trip associated with the expected driver" do
it "last Trip is associated with the expected driver" do
example_driver_trips[0].must_be_instance_of RideShare::Trip
example_driver_trips[-1].driver_id.must_equal 9
end
end

describe "Driver#avg_rating" do
let (:example_driver_avg) { RideShare::Driver.new(id: "9").avg_rating }
let (:example_driver_avg) { example_driver.avg_rating }

it "returns value as a Float" do
example_driver_avg.must_be_kind_of Float
end

it "return value is min 0, max 5" do
it "return value is between 0 and 5" do
example_driver_avg.must_be :<=, 5
example_driver_avg.must_be :>=, 0
end

# EDGE CASE
it "rounds to two decimal points correctly" do
driver_21 = RideShare::Driver.find(21)
driver_21.avg_rating.must_equal 2.73
# manually calculated as 30/11 = 2.73 rounded
end
end

describe "Driver#find" do
let(:driver_found) { RideShare::Driver.find(31) }

it "return value is a Driver instance" do
driver_found.must_be_instance_of RideShare::Driver
end

it "finds the correct instance of Driver" do
driver_found.id.must_equal 31
driver_found.name.must_equal "Sheila VonRueden"
driver_found.vin.must_equal "KPH9RLSZ9YKNVMGH2"
end

# EDGE CASE
it "returns nil for a nonexistent Driver" do
nonexistent = RideShare::Driver.find(999)
nonexistent.must_be_nil
end

# EDGE CASE
it "prints message with a failed search" do
proc {
RideShare::Driver.find(999)
}.must_output puts "Driver_999 not found."
end
end
end
22 changes: 18 additions & 4 deletions specs/rider_spec.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
let(:all_riders) { RideShare::Rider.all }
let(:all_drivers) { RideShare::Driver.all }
let(:rider) { RideShare::Rider.new({ id: "13", name: "Dr. Leilani Mertz", phone_number: "777.380.7540" }) }

# initialize .all for each class--as default dataset
before do
all_trips
all_riders
@@ -25,7 +25,7 @@

it "can create a new rider with a missing phone" do
no_phone = RideShare::Rider.new({id: "87", name: "Tamiko Terada"})
no_phone.phone_number.must_equal nil
no_phone.phone_number.must_be_nil
end
end

@@ -44,13 +44,15 @@
all_riders.length.must_equal 300 # rows in CSV file
end

# EDGE CASE
it "correctly reads in the first row of the CSV file" do
# last row of data: 1,Nina Hintz Sr.,560.815.3059
all_riders[0].id.must_equal 1
all_riders[0].name.must_equal "Nina Hintz Sr."
all_riders[0].phone_number.must_equal "560.815.3059"
end

# EDGE CASE
it "correctly reads in the last row of the CSV file" do
# last row of data: 300,Miss Isom Gleason,791-114-8423 x70188
all_riders[-1].id.must_equal 300
@@ -78,13 +80,25 @@
rider.past_trips.must_be_kind_of Array
end

it "first element is an instance of Trip" do
it "first element is a Trip with expected rider" do
rider.past_trips[0].must_be_instance_of RideShare::Trip
rider.past_trips[0].rider_id.must_equal 13
end

it "last element is a Trip associated with the expected rider" do
it "last element is a Trip with expected rider" do
rider.past_trips[-1].must_be_instance_of RideShare::Trip
rider.past_trips[-1].rider_id.must_equal 13
end

# # EDGE CASE
# it "returns empty array for rider with no trips" do
# # expects no error message because rider exists
# proc {
# RideShare::Rider.find(116)
# }.must_be_silent
# rider116 = RideShare::Rider.find(116)
# rider116.past_trips.must_be_empty
# end
end

describe "Rider#past_drivers" do
43 changes: 28 additions & 15 deletions specs/trip_spec.rb
Original file line number Diff line number Diff line change
@@ -4,20 +4,27 @@
let(:all_trips) { RideShare::Trip.all }
let(:all_riders) { RideShare::Rider.all }
let(:all_drivers) { RideShare::Driver.all }

let(:example_trip) { RideShare::Trip.new({ id: "13", driver_id: "83",rider_id: "298", date: "2015-05-27", rating: "5" }) }
# initialize .all for each class--as default dataset
before do
all_trips
all_riders
all_drivers
end

describe "Trip#initialize" do
let(:example_trip) { RideShare::Trip.new({ id: "13", driver_id: "83",rider_id: "298", date: "2015-05-27", rating: "5" }) }

it "creates a new instance of trip" do
example_trip.must_be_instance_of RideShare::Trip
end

it "responds to being called" do
example_trip.must_respond_to :id
example_trip.must_respond_to :driver_id
example_trip.must_respond_to :rider_id
example_trip.must_respond_to :date
example_trip.must_respond_to :rating
end

it "passes in values correctly" do
example_trip.id.must_equal 13
example_trip.driver_id.must_equal 83
@@ -26,9 +33,10 @@
example_trip.rating.must_equal 5
end

it "can create a new trip with a missing date" do
# EDGE CASE
it "can create a new trip with missing date" do
no_date_trip = RideShare::Trip.new({ id: "13", driver_id: "83",rider_id: "298", rating: "5" })
no_date_trip.date.must_equal nil
no_date_trip.date.must_be_nil
end
end

@@ -47,6 +55,7 @@
all_trips.length.must_equal 600 # rows in CSV file
end

# EDGE CASE
it "correctly reads in the first row of the CSV file" do
# last row of data: 1,1,54,2016-04-05,3
all_trips[0].id.must_equal 1
@@ -56,6 +65,7 @@
all_trips[0].rating.must_equal 3
end

# EDGE CASE
it "correctly reads in the last row of the CSV file" do
# last row of data: (600,61,168,2016-04-25,3)
all_trips[-1].id.must_equal 600
@@ -73,9 +83,16 @@
example_by_rider.must_be_kind_of Array
end

it "each returned element is a trip instances" do
it "each returned element is a Trip instance" do
example_by_rider.each { |element| element.must_be_instance_of RideShare::Trip }
end

it "prints message if rider_id doesn't exist" do
proc {
RideShare::Trip.by_rider("999")
}.must_output("")
end

end

describe "Trip#by_driver(driver_id)" do
@@ -85,23 +102,19 @@
example_by_driver.must_be_kind_of Array
end

it "each returned element is a trip instances" do
it "each returned element is a Trip instance" do
example_by_driver.each { |element| element.must_be_instance_of RideShare::Trip }
end

it "returns empty array if no trips are found for driver" do
# EDGE CASE
it "returns empty array if no trips are found" do
by_driver_no_trips= RideShare::Trip.by_driver("100") # has no trips recorded
by_driver_no_trips.must_equal []
end

it "returns nil if the driver_id is not a valid one" do
by_driver_missing = RideShare::Trip.by_driver("999") # nonexistent driver_id lookup
by_driver_missing.must_equal []
end
end

describe "Trip#find_driver" do
let(:example_find_driver) { RideShare::Trip.new({driver_id: "83"}).find_driver }
let(:example_find_driver) { example_trip.find_driver }

it "returns the instance of Driver" do
example_find_driver.must_be_instance_of RideShare::Driver
@@ -115,7 +128,7 @@
end

describe "Trip#find_rider" do
let(:example_find_rider) { RideShare::Trip.new({rider_id: "298"}).find_rider }
let(:example_find_rider) { example_trip.find_rider }

it "returns the instance of Rider" do
example_find_rider.must_be_instance_of RideShare::Rider