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

Jackson Bickler #6

Open
wants to merge 1 commit 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
38 changes: 38 additions & 0 deletions lib/biker.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
require 'spec_helper'

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

def log_ride(ride, distance) #i cant do it. no matter what i do the tests fail. if i add the last condtion (if they know the terrain but cant do the distance) it breaks the whole thing
#i understand that the condition right above it is overiding it but no matter what order i put it in it doesnt work. i dont know how to have all three conditions and make it work
if !@acceptable_terrain.include?(ride.terrain)
return "#{@name} dosent know this terrain"
elsif ride.total_distance > @max_distance
return "#{@name} can't bike this distance"
elsif @acceptable_terrain.include?(ride.terrain) && ride.total_distance <= @max_distance
return "#{@name} knows the terrain but cannot bike the distance"
else
if @rides.key?(ride)
@rides[ride] << distance
else
@rides[ride] = [distance]
end
end
end

def personal_record(ride)
if @rides.key?(ride)
@rides[ride].min
else
false
end
end
end
20 changes: 20 additions & 0 deletions lib/ride.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
class Ride
attr_reader :name, :distance, :loop, :terrain, :total_distance

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

def loop?
@loop
end

def total_distance
if @loop == false
@distance * 2
else
@distance
end
end

end
65 changes: 65 additions & 0 deletions spec/biker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'spec_helper'

RSpec.describe Biker do
before(:each) do
@biker = Biker.new("Kenny", 30)
@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})
end

describe 'intiailize' do
it "exists and has attributes" do
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 "learn_terrain!" do
it "adds a terrain to the acceptable terrain array" do
@biker.learn_terrain!(:gravel)
@biker.learn_terrain!(:hills)
@biker2.learn_terrain!(:gravel)
@biker2.learn_terrain!(:hills)
expect(@biker.acceptable_terrain).to eq([:gravel, :hills])

end
end

describe "log_ride" do
it "logs rides into the rides hash" do
@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(@biker2.log_ride(@ride1, 97.0)).to eq("Athena dosent know this terrain")
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 the terrain but cannot bike the distance")
expect(@biker.rides).to include(@ride1)
expect(@biker.rides[@ride1]).to eq([92.5, 91.1])
end
end

describe "personal_record" do
it "displays the bikers personal record dpedning on the specific ride" do
@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.personal_record(@ride1)).to eq(91.1)
expect(@biker.personal_record(@ride2)).to eq(60.9)
end
end

describe

end
20 changes: 20 additions & 0 deletions spec/ride_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'

RSpec.describe Ride do
before(:each) do
@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})
end

describe 'initialize' do
it "exsits with attributes" do
expect(@ride1.name).to eq("Walnut Creek Trail")
expect(@ride1.distance).to eq(10.7)
expect(@ride1.loop?).to eq(false)
expect(@ride1.terrain).to eq(:hills)
expect(@ride1.total_distance).to eq(21.4)
expect(@ride2.loop?).to eq(true)
expect(@ride2.total_distance).to eq(14.9)
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require './lib/ride'
require './lib/biker'