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

True iteration 4 #13

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
16a699b
add the spec files for testing to the repo.
little-Patrick Dec 18, 2024
57ca9fe
add the test files for the classes. Initialize test on passengers sta…
little-Patrick Dec 18, 2024
e5b7eab
passenger has a name test passes
little-Patrick Dec 18, 2024
222e994
create test for age on passesnger
little-Patrick Dec 18, 2024
a604c77
passenger class passes adult? test
little-Patrick Dec 18, 2024
2303f1b
passenger class passes respec tests.
little-Patrick Dec 18, 2024
fa6dc23
initialize test written
little-Patrick Dec 18, 2024
eaa7c44
write tests for class methods in vehicle
little-Patrick Dec 18, 2024
4bcd1c6
class passes tests for speed and adding passengers
little-Patrick Dec 18, 2024
10722a2
iteration 2 passes tests!!!!!
little-Patrick Dec 18, 2024
bf4e016
Merge pull request #1 from little-Patrick/2_iteration
little-Patrick Dec 18, 2024
b1048b9
started park_spec tests. The before command methods are laid out
little-Patrick Dec 18, 2024
6dd91b8
rspec tests and class are initialized for name and price
little-Patrick Dec 18, 2024
18efd7d
vehicles can be added to park, class passes test.
little-Patrick Dec 18, 2024
2627dc8
the park can add passengers
little-Patrick Dec 18, 2024
8c9e954
added tests for revenue
little-Patrick Dec 18, 2024
bf9c552
renenue passed test on first try!!!!!!!
little-Patrick Dec 18, 2024
fe528c8
forgot to switch branches rspec tests for park iteration for started
little-Patrick Dec 18, 2024
76f6515
fixed add vehicle, I was overcomplicating it
little-Patrick Dec 18, 2024
e7b014c
patron name test written
little-Patrick Dec 18, 2024
974a87a
iteration 4 done
little-Patrick Dec 18, 2024
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
44 changes: 44 additions & 0 deletions lib/park.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


class Park
attr_reader :name,
:price,
:vehicles,
:passengers,
:revenue,
:patron_name


def initialize(name, price)
@name = name
@price = price
@vehicles = []
@passengers = []
@patron_name = []
@revenue = 0
end

def add_vehicle(vehicle)
@vehicles << vehicle
vehicle.passengers.each { |passenger| @passengers << passenger }
end

def revenue
@revenue = @passengers.count * @price
end

def patron_name
@patron_name = @passengers.map{|x| x.name}
end

def minors
minors = @passengers.select {|age| !age.adult?}
return minors
end

def adults
adults = @passengers.select {|age| age.adult?}
return adults
end

end
25 changes: 25 additions & 0 deletions lib/passenger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


class Passenger
attr_reader :name,
:age,
:driver

def initialize(passenger_info)
@name = passenger_info['name']
@age = passenger_info['age']
@driver = false
end

def adult?
@age >= 18 ? true : false
end

def driver?
return @driver
end

def drive
@age >= 16 ? @driver = true : @driver = false
end
end
34 changes: 34 additions & 0 deletions lib/vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@


class Vehicle
attr_reader :year,
:make,
:model,
:speeding,
:passengers

def initialize(year, make, model)
@year = year
@make = make
@model = model
@speeding = false
@passengers = []
end

def speeding?
@speeding
end

def speed
@speeding = true
end

def add_passenger(passenger)
@passengers << passenger
end

def num_adults
adults = @passengers.find_all {|x| x.adult?}
return adults.count
end
end
124 changes: 124 additions & 0 deletions spec/park_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
require './spec/spec_helper.rb'

# attr_reader and initialize park name and ticket price
# add a vehicle to ann array for the instance of that park
# -add_vehicle(course)
# -vehicles = []


RSpec.describe Park do
before(:each) do
@park_1 = Park.new('Jackson Hole', 10)


@vehicle_1 = Vehicle.new("2001", "Honda", "Civic")
@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@jude = Passenger.new({"name" => "Jude", "age" => 20})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})

@vehicle_2 = Vehicle.new("1955", "VW", 'Beetle')
@patrick = Passenger.new({'name' => 'Patrick', 'age' => 24})

@vehicle_1.add_passenger(@charlie)
@vehicle_1.add_passenger(@jude)
@vehicle_1.add_passenger(@taylor)

@vehicle_2.add_passenger(@patrick)
end

describe 'initialize' do
it 'exists' do
expect(@park_1).to be_an_instance_of(Park)
end

it 'has name' do
expect(@park_1.name).to eq('Jackson Hole')
end

it 'has ticket price' do
expect(@park_1.price).to eq(10)
end
end

describe 'vehicles entry to park' do
it 'adds vehicles to an array' do
expect(@park_1.vehicles).to eq([])

@park_1.add_vehicle(@vehicle_1)
@park_1.add_vehicle(@vehicle_2)

expect(@park_1.vehicles).to eq([@vehicle_1, @vehicle_2])
end
end

describe 'adding to the park passengers' do
before(:each) do
@park_1.add_vehicle(@vehicle_1)
end

it 'can add passengers' do
expect(@park_1.passengers).to eq([@charlie, @jude, @taylor])

@park_1.add_vehicle(@vehicle_2)

expect(@park_1.passengers).to eq([@charlie, @jude, @taylor, @patrick])
end
end

describe 'revenue' do
it 'starts with 0' do
expect(@park_1.revenue).to eq(0)
end

it 'can add revenue based on vehicle passengers' do
@park_1.add_vehicle(@vehicle_1)
@park_1.add_vehicle(@vehicle_2)

expect(@park_1.revenue).to eq(40)
end
end

end

### iteration 4


RSpec.describe Park do
before(:each) do
@park_1 = Park.new('Jackson Hole', 10)


@vehicle_1 = Vehicle.new("2001", "Honda", "Civic")
@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@jude = Passenger.new({"name" => "Jude", "age" => 20})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})

@vehicle_2 = Vehicle.new("1955", "VW", 'Beetle')
@patrick = Passenger.new({'name' => 'Patrick', 'age' => 24})

@vehicle_1.add_passenger(@charlie)
@vehicle_1.add_passenger(@jude)
@vehicle_1.add_passenger(@taylor)

@vehicle_2.add_passenger(@patrick)

@park_1.add_vehicle(@vehicle_1)
# @park_1.add_vehicle(@vehicle_2)
end

it 'has names' do
expect(@park_1.patron_name).to eq(['Charlie', 'Jude', 'Taylor'])
@park_1.add_vehicle(@vehicle_2)
expect(@park_1.patron_name).to eq(['Charlie', 'Jude', 'Taylor', 'Patrick'])
end

it 'has minors' do
expect(@park_1.minors).to eq([@taylor])
end

it 'has adults' do
expect(@park_1.adults).to eq([@charlie, @jude])
end


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

RSpec.describe Passenger do
before(:each) do
@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})
end

it 'initializes' do
expect(@charlie).to be_an_instance_of(Passenger)
expect(@taylor).to be_an_instance_of(Passenger)
end
it 'has name' do
expect(@charlie.name).to eq('Charlie')
expect(@taylor.name).to eq('Taylor')
end

it 'has age' do
expect(@charlie.age).to eq(18)
expect(@taylor.age).to eq(12)
end

it 'is an adult?' do
expect(@charlie.adult?).to eq(true)
expect(@taylor.adult?).to eq(false)
end

it 'can drive' do
expect(@charlie.driver?).to eq(false)
expect(@taylor.driver?).to eq(false)

@charlie.drive
@taylor.drive

expect(@charlie.driver?).to eq(true)
expect(@taylor.driver?).to eq(false)
end

end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'pry'
require './lib/park.rb'
require './lib/passenger.rb'
require './lib/vehicle.rb'
56 changes: 56 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require './spec/spec_helper.rb'

RSpec.describe Vehicle do
before(:each) do
@vehicle = Vehicle.new("2001", "Honda", "Civic")
@charlie = Passenger.new({"name" => "Charlie", "age" => 18})
@jude = Passenger.new({"name" => "Jude", "age" => 20})
@taylor = Passenger.new({"name" => "Taylor", "age" => 12})
end

describe 'initialize' do
it 'exists' do
expect(@vehicle).to be_an_instance_of(Vehicle)
end

it 'has vehicle info' do
expect(@vehicle.year).to eq('2001')
end

it 'has a make' do
expect(@vehicle.make).to eq('Honda')
end

it 'has a model' do
expect(@vehicle.model).to eq('Civic')
end
end

describe 'methods' do
it 'is speeding' do
expect(@vehicle.speeding?).to eq(false)

@vehicle.speed

expect(@vehicle.speeding?).to eq(true)
end

it 'adds passengers' do
expect(@vehicle.passengers).to eq([])

@vehicle.add_passenger(@charlie)
@vehicle.add_passenger(@jude)
@vehicle.add_passenger(@taylor)

expect(@vehicle.passengers).to eq([@charlie, @jude, @taylor])
end

it 'counts the number of adults' do
@vehicle.add_passenger(@charlie)
@vehicle.add_passenger(@jude)
@vehicle.add_passenger(@taylor)

expect(@vehicle.num_adults).to eq(2)
end
end
end