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

Kristin IC Week #5 #10

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
21 changes: 21 additions & 0 deletions lib/bike_club.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
class BikeClub

attr_reader :name,
:bikers

def initialize(name, bikers = [])
@name = name
@bikers = bikers
end

def add_bikers(biker)
bikers << biker
end

def biker_most_rides
bikers.each do |biker|
if biker.ride.keys.count
#need to compare the different counts and determin the hights
#do an each cons?
end
end
end

end
60 changes: 60 additions & 0 deletions lib/biker.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
class Biker

attr_reader :name,
:max_distance,
:rides,
:acceptable_terrain

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

def accepted_terrain?(terrain)
if acceptable_terrain.include?(terrain)
true
else
false
end
end

def accepted_distance?(distance)
if max_distance >= distance
true
else
false
end
end

def learn_terrain!(terrain)
acceptable_terrain << terrain
end

def log_ride(ride, time)
if accepted_terrain?(ride.terrain) && accepted_distance?(ride.total_distance)
if rides[ride]
rides[ride] << time
else
rides[ride] = [time]
end
return "#{self.name} knows this terrain and can bike this distance"
elsif accepted_terrain?(ride.terrain) && !accepted_distance?(ride.total_distance)
return "#{self.name} can't bike this distance"
elsif accepted_distance?(ride.total_distance) && !accepted_terrain?(ride.terrain)
return "#{self.name} doesn't know this terrain yet"
else
return "#{self.name} can't bike this distance and doesn't know this terrain yet"
end
rides
end

def personal_record(ride)
if rides[ride]
ordered_times = rides[ride].sort
ordered_times.first
else
false
end
end


end
26 changes: 26 additions & 0 deletions lib/ride.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
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
62 changes: 62 additions & 0 deletions spec/bike_club_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'pry'
require 'rspec'
require './lib/ride'
require './lib/biker'
require './lib/bike_club'

RSpec.describe BikeClub do
describe '#initialize' do
it 'exists' do
bikeclub_1 = BikeClub.new("Cruz")

expect(bikeclub_1).to be_an_instance_of(BikeClub)
end

it 'has attributes' do
bikeclub_1 = BikeClub.new("Cruz")

expect(bikeclub_1.name).to eq("Cruz")
expect(bikeclub_1.bikers).to eq([])
end
end

describe '#bikers' do
it 'can add bikers' do
bikeclub_1 = BikeClub.new("Cruz")

biker = Biker.new("Kenny", 30)

bikeclub_1.add_bikers(biker)

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

describe '#compare bikers' do
it 'can find bikers with most rides' do
bikeclub_1 = BikeClub.new("Cruz")
biker = Biker.new("Kenny", 30)
biker.learn_terrain!(:gravel)
biker.learn_terrain!(:hills)
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)
biker.log_ride(ride2, 60.9)
biker.log_ride(ride2, 61.6)

biker2 = Biker.new("Athena", 15)
biker2.learn_terrain!(:gravel)
biker2.learn_terrain!(:hills)
biker2.log_ride(ride1, 97.0)
biker2.log_ride(ride2, 67.0)

bikeclub_1.add_bikers(biker)
bikeclub_1.add_bikers(biker2)

binding.pry

expect(bikeclub_1.biker_most_rides).to eq(biker)
end
end
end
99 changes: 99 additions & 0 deletions spec/biker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
require 'pry'
require 'rspec'
require './lib/ride'
require './lib/biker'

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 'has attributes' do
biker = Biker.new("Kenny", 30)
binding.pry

expect(biker.name).to eq("Kenny")
expect(biker.max_distance).to eq(30)
expect(biker.rides).to eq({})
expect(biker.acceptable_terrain).to eq([])
end
end

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

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

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

describe '#rides' do
it 'can log rides' do
biker = Biker.new("Kenny", 30)
biker.learn_terrain!(:gravel)
biker.learn_terrain!(:hills)

ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})
expect(ride1).to be_an_instance_of(Ride)

ride2 = Ride.new({name: "Town Lake", distance: 14.9, loop: true, terrain: :gravel})
expect(ride2).to be_an_instance_of(Ride)

biker.log_ride(ride1, 92.5)
expect(biker.rides).to eq({ride1 => [92.5]})
biker.log_ride(ride1, 91.1)
expect(biker.rides).to eq({ride1 => [92.5, 91.1]})
biker.log_ride(ride2, 60.9)
expect(biker.rides).to eq({ride1 => [92.5, 91.1], ride2 => [60.9]})
biker.log_ride(ride2, 61.6)
expect(biker.rides).to eq({ride1 => [92.5, 91.1], ride2 => [60.9, 61.6]})
end
end

describe '#records' do
it 'can detect personal records' do
biker = Biker.new("Kenny", 30)
biker.learn_terrain!(:gravel)
biker.learn_terrain!(:hills)

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)
biker.log_ride(ride2, 60.9)
biker.log_ride(ride2, 61.6)

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

biker2 = Biker.new("Athena", 15)
expect(biker2).to be_an_instance_of(Biker)

biker2.log_ride(ride1, 97.0)
biker2.log_ride(ride2, 67.0)
expect(biker2.log_ride(ride1, 97.0)).to eq( "Athena can't bike this distance and doesn't know this terrain yet")
expect(biker2.log_ride(ride2, 67.0)).to eq( "Athena doesn't know this terrain yet")

expect(biker2.rides).to eq({})
biker2.learn_terrain!(:gravel)
biker2.learn_terrain!(:hills)

expect(biker2.log_ride(ride1, 95.0)).to eq("Athena can't bike this distance")
expect(biker2.log_ride(ride2, 65.0)).to eq("Athena knows this terrain and can bike this distance")

expect(biker2.personal_record(ride2)).to eq(65.0)
expect(biker2.personal_record(ride1)).to eq(false)

end
end


end
42 changes: 42 additions & 0 deletions spec/ride_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'pry'
require 'rspec'
require './lib/ride'

RSpec.describe Ride do
describe '#initialize' 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 eq(false)
end
end

describe '#distance' do
it 'tests for a loop' do
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})

expect(ride1.loop?).to eq(false)
end

it 'calculates total distance' do
ride1 = Ride.new({name: "Walnut Creek Trail", distance: 10.7, loop: false, terrain: :hills})

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

ride2 = Ride.new({name: "Town Lake", distance: 14.9, loop: true, terrain: :gravel})

expect(ride2).to be_an_instance_of(Ride)
expect(ride2.loop?).to eq(true)
expect(ride2.total_distance).to eq(14.9)
end
end

end