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

Coral Ruschak #15

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
33 changes: 33 additions & 0 deletions lib/park.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Park
attr_reader :name, :price, :vehicles

def initialize(name, price)
@name = name
@price = price
@vehicles = []
end

def add_vehicle(vehicle)
@vehicles << vehicle
end

def passengers
passengers_array = []
@vehicles.each do |vehicle|
vehicle.passengers.each do |passenger|
passengers_array << passenger
end
end
return passengers_array
end

def revenue
total_revenue = 0
passengers.each do |passenger|
if passenger.adult? == true
total_revenue += @price
end
end
return total_revenue
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(info)
@name = info[:name]
@age = info[:age]
@driver = false
end

def adult?
if @age >= 18
return true
else
return false
end
end

def driver?
@driver
end

def drive
@driver = true
end
end
30 changes: 30 additions & 0 deletions lib/vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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
@passengers.count do |passenger|
passenger.adult?
end
end
end
80 changes: 80 additions & 0 deletions spec/park_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require './lib/passenger'
require './lib/vehicle'
require './lib/park'


RSpec.describe Park do
before(:each)do
@kennywood = Park.new("Kennywood", 10)
@vehicle_1 = Vehicle.new("2001", "Honda", "Civic")
@vehicle_2 = Vehicle.new("2015", "Subaru", "Forrester")
@coral = Passenger.new({name: 'Coral', age: 29})
@jonah = Passenger.new({name: 'Jonah', age: 6})
@charlie = Passenger.new({name: 'Charlie', age: 18})
@jude = Passenger.new({name: 'Jude', age: 20})
@taylor = Passenger.new({name: 'Taylor', age: 12})
end

describe "#initialization" do
it "exists" do
expect(@kennywood).to be_a Park
end
it "has a name" do
expect(@kennywood.name).to eq('Kennywood')
end

it "has a price" do
expect(@kennywood.price).to eq(10)
end
end

describe "#vehicles" do
it "defaults an empty array" do
expect(@kennywood.vehicles).to eq([])
end

it "can add a vehicle to array" do
@kennywood.add_vehicle(@vehicle_1)

expect(@kennywood.vehicles).to eq([@vehicle_1])
end

it "can add multiple vehicles to array" do
@kennywood.add_vehicle(@vehicle_1)
@kennywood.add_vehicle(@vehicle_2)

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

describe "#passengers" do
it "can create array of passengers from multiple vehicles" do
@vehicle_1.add_passenger(@charlie)
@vehicle_1.add_passenger(@jude)
@vehicle_1.add_passenger(@taylor)
@vehicle_2.add_passenger(@coral)
@vehicle_2.add_passenger(@jonah)

@kennywood.add_vehicle(@vehicle_1)
@kennywood.add_vehicle(@vehicle_2)

expect(@kennywood.passengers).to eq([@charlie, @jude, @taylor, @coral, @jonah])
end
end

describe "#revenue" do
it "can accurately calculate revenue collected from all adults" do
@vehicle_1.add_passenger(@charlie)
@vehicle_1.add_passenger(@jude)
@vehicle_1.add_passenger(@taylor)
@vehicle_2.add_passenger(@coral)
@vehicle_2.add_passenger(@jonah)

@kennywood.add_vehicle(@vehicle_1)
@kennywood.add_vehicle(@vehicle_2)

expect(@kennywood.revenue).to eq(30)
end
end

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

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

describe "#initialization" do
it "exists" do
expect(@charlie).to be_a Passenger
expect(@taylor).to be_a Passenger
end

it "has a name" do
expect(@charlie.name).to eq('Charlie')
expect(@taylor.name).to eq('Taylor')
end

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

describe "#adult?" do
it "accurately determines adulthood" do
expect(@charlie.adult?).to eq(true)
expect(@taylor.adult?).to eq(false)
end
end

describe "driver?" do
it "verifies driver default is false" do
expect(@charlie.driver?).to eq(false)
expect(@taylor.driver?).to eq(false)
end
end

describe "drive" do
it "changes driver status" do
expect(@charlie.driver?).to eq(false)
@charlie.drive
expect(@charlie.driver?).to eq(true)
end
end
end
64 changes: 64 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require './lib/passenger'
require './lib/vehicle'


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 "#initialization" do
it "exists" do
expect(@vehicle).to be_a Vehicle
end

it "has a year" 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 "speeding?" do
it "verifies speeding default is false" do
expect(@vehicle.speeding?).to eq(false)
end

it "changes speeding status" do
expect(@vehicle.speeding?).to eq(false)
@vehicle.speed
expect(@vehicle.speeding?).to eq(true)
end
end

describe "#passengers" do
it "defaults to empty array" do
expect(@vehicle.passengers).to eq([])
end
it "add_passengers adds passengers to array" do
@vehicle.add_passenger(@charlie)
@vehicle.add_passenger(@jude)
@vehicle.add_passenger(@taylor)
expect(@vehicle.passengers).to eq([@charlie, @jude, @taylor])
end
end

describe "#num_adults" do
it "counts number of adult passengers" do
@vehicle.add_passenger(@charlie)
@vehicle.add_passenger(@jude)
@vehicle.add_passenger(@taylor)

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