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

Kevin Newland #8

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 19 additions & 1 deletion lib/bike_club.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
class BikeClub
attr_reader :name, :bikers
def initialize(name)
@name = name
@bikers = []
end

end
def add_biker(biker)
@bikers << biker
end

def most_rides #almost just trying to find out how i can shovel the biker with the most rides into array then output it.
biker_most_rides = [] #also this should proabably not be an array should be a single biker

@bikers.each do |biker|
biker.rides.count

biker_most_rides << biker
end
end
end
31 changes: 31 additions & 0 deletions lib/biker.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
class Biker
attr_reader :name, :max_distance, :rides, :acceptable_terrain

def initialize(name, max_distance)
@name = name
@max_distance = max_distance
@rides = {}
@acceptable_terrain = []
end

def learn_terrain!(terrain)
@acceptable_terrain << terrain
end
#A Biker will not log a ride if the ride's terrain does not match their acceptable terrain. They also won't log a ride if the ride's total distance is greater than the Biker's max distance.
def log_ride(ride, time)
return unless @acceptable_terrain.include?(ride.terrain)
return unless ride.distance <= @max_distance

if @rides[ride] == nil #ride been logged?
@rides[ride] = []
end

@rides[ride] << time
end

def personal_record(ride)
if @rides[ride] == nil
return false
end

lowest_time = @rides[ride].min
return lowest_time
end
end
19 changes: 19 additions & 0 deletions lib/ride.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
class Ride
attr_reader :name, :distance, :loop, :terrain

def initialize(ride_details)
@name = ride_details[:name]
@distance = ride_details[:distance]
@loop = ride_details[:loop]
@terrain = ride_details[:terrain]
end

def loop?
@loop
end

def total_distance
if @loop == false
@distance * 2
else
@distance
end
end
end
50 changes: 50 additions & 0 deletions spec/bike_club_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require './lib/ride'
require './lib/biker'
require './lib/bike_club'
require 'rspec'

RSpec.describe BikeClub do
describe '#initialize' do
it 'exists' do
bike_club = BikeClub.new("Turing")
expect(bike_club).to be_an_instance_of(BikeClub)
end

it 'has attributes' do
bike_club = BikeClub.new("Turing")
expect(bike_club.name).to eq("Turing")
expect(bike_club.bikers).to be_an(Array)
end
end

describe '#add_biker(biker)' do
it 'can add a biker to the bikers array' do
bike_club = BikeClub.new("Turing")
biker = Biker.new("Kenny", 30)

bike_club.add_biker(biker)

expect(bike_club.bikers).to eq([biker])
end
end

describe '#most_rides' do
it 'can tell us which biker has logged the most rides' do
bike_club = BikeClub.new("Turing")
biker = Biker.new("Kenny", 30)
biker2 = Biker.new("Athena", 15)

bike_club.add_biker(biker)
bike_club.add_biker(biker2)

ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
ride2 = Ride.new({name: "Town Lake", distance: 14.9, loop: true, terrain: :gravel})

biker.log_ride(ride1, 92.5)
biker.log_ride(ride1, 91.1)

biker2.log_ride(ride2, 65.0)
expect(bike_club.most_rides).to eq(biker)
end
end
end
118 changes: 118 additions & 0 deletions spec/biker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
require './lib/ride'
require './lib/biker'
require 'rspec'

RSpec.describe Biker do
describe '#initialize' do
it 'exists' do
biker = Biker.new("Kenny", 30)
expect(biker).to be_an_instance_of(Biker)
end

it 'can have attributes' do
biker = Biker.new("Kenny", 30)
expect(biker.name).to eq("Kenny")
expect(biker.max_distance).to eq(30)
expect(biker.rides).to be_a(Hash)
expect(biker.acceptable_terrain).to be_a(Array)
end
end

describe '#learn_terrain!' do
it 'can learn new terrain' do
biker = Biker.new("Kenny", 30)

biker.learn_terrain!(:gravel)
biker.learn_terrain!(:hills)
expect(biker.acceptable_terrain).to eq([:gravel, :hills])
end
end

describe '#log_ride' do
it 'can log rides' do
biker = Biker.new("Kenny", 30)
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
ride2 = Ride.new({name: "Town Lake", distance: 14.9, loop: true, terrain: :gravel})

biker.learn_terrain!(:gravel)
biker.learn_terrain!(:hills)

biker.log_ride(ride1, 92.5)
biker.log_ride(ride1, 91.1)
biker.log_ride(ride2, 60.9)
biker.log_ride(ride2, 61.6)

expect(biker.rides).to include(ride1 => [92.5, 91.1], ride2 => [60.9, 61.6])
end
end
describe '#personal_record' do
it 'can set a personal record' do
biker = Biker.new("Kenny", 30)
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
ride2 = Ride.new({name: "Town Lake", distance: 14.9, loop: true, terrain: :gravel})

biker.learn_terrain!(:gravel) #stop forgetting to bring down the proper set up! (plz dont mind me yelling at myself)(wasted a lot of time)
biker.learn_terrain!(:hills)

biker.log_ride(ride1, 92.5)
biker.log_ride(ride1, 91.1)
biker.log_ride(ride2, 60.9)
biker.log_ride(ride2, 61.6)

biker.personal_record(ride1)
biker.personal_record(ride2)

expect(biker.personal_record(ride1)).to eq(91.1)
expect(biker.personal_record(ride2)).to eq(60.9)
end
end

describe '#biker2' do
it 'can have another biker' do
biker2 = Biker.new("Athena", 15)
expect(biker2).to be_an_instance_of(Biker)
end

it 'cannot log rides due to unlearned terrain' do
biker2 = Biker.new("Athena", 15)
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
ride2 = Ride.new({name: "Town Lake", distance: 14.9, loop: true, terrain: :gravel})

biker2.log_ride(ride1, 97.0) #biker2 doesn't know this terrain yet
biker2.log_ride(ride2, 67.0) #biker2 doesn't know this terrain yet

expect(biker2.rides).to eq({})
end

context 'must be acceptable terrain and total distance cannot be greater than bikers max distance' do
it 'can learn terrain if conditions are met' do
biker2 = Biker.new("Athena", 15)
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
ride2 = Ride.new({name: "Town Lake", distance: 14.9, loop: true, terrain: :gravel})

biker2.learn_terrain!(:gravel)

biker2.log_ride(ride1, 95.0) # biker2 can't bike this distance
biker2.log_ride(ride2, 65.0) # biker2 knows this terrain and can bike this distance
expect(biker2.rides).to eq({ride2 => [65.0]})
end
end
it 'can have personal record' do
biker2 = Biker.new("Athena", 15)
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
ride2 = Ride.new({name: "Town Lake", distance: 14.9, loop: true, terrain: :gravel})

biker2.learn_terrain!(:gravel)
biker2.learn_terrain!(:hills)


biker2.log_ride(ride2, 65.0) # biker2 knows this terrain and can bike this distance

biker2.personal_record(ride2)
biker2.personal_record(ride1)

expect(biker2.personal_record(ride2)).to eq(65.0)
expect(biker2.personal_record(ride1)).to be(false)
end
end
end
37 changes: 37 additions & 0 deletions spec/ride_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require './lib/ride'
require 'rspec'

RSpec.describe Ride do
describe '#initilaize' do
it 'exists' do
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
expect(ride1).to be_an_instance_of(Ride)
end

it 'has attributes' do
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
expect(ride1.name).to eq("Walnut Creek Trail")
expect(ride1.distance).to eq(10.7)
expect(ride1.loop).to be(false)
expect(ride1.terrain).to eq(:hills)
end
end

describe '#total_distance' do
it 'can report total distance if the ride is not a loop' do
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
expect(ride1.loop).to be(false)

ride1.total_distance
expect(ride1.total_distance).to eq(21.4)
end
end

describe 'ride 2' do
it 'can have another ride' do
ride2 = Ride.new({name: "Town Lake", distance: 14.9, loop: true, terrain: :gravel})
expect(ride2.loop).to be(true)
expect(ride2.total_distance).to eq(14.9)
end
end
end