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

Jono Sommers - Week 3 IC/Mid Module Diagnostic (Mod1 - 2410) #7

Open
wants to merge 3 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

* Fork this Repository
* Clone YOUR fork
* Compete the activity below
* Complete the activity below
* Push your solution to your fork
* Submit a pull request from your repository to the turingschool-examples repository
* Make sure to put your name in your PR!
Expand Down
22 changes: 22 additions & 0 deletions lib/park.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Park
attr_reader :name, :price, :parking_lot, :visitors

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

def vehicles_in_park(vehicle)
if vehicle.enter_park == true
@parking_lot << vehicle
end
end

def passengers_in_park(vehicle)
if vehicle.enter_park == true
@visitors << vehicle.passengers
end
end
end
19 changes: 19 additions & 0 deletions lib/passenger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Passenger
attr_reader :name, :age, :drive

def initialize(passenger_info)
@name = passenger_info["name"]
@age = passenger_info["age"]
@drive = true
end

def adult?
@age >= 18
end

def driver?
@drive = !@drive
@drive
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, :speed, :passengers, :enter_park

def initialize(year, make, model)
@year = year
@make = make
@model = model
@speed = true
@passengers = []
@enter_park = true

end

def speeding?
@speed = !@speed
@speed
end

def add_passenger(passenger)
@passengers << passenger
end

def num_adults
@adults = 0

@passengers.each do |passenger|
if passenger.adult?
@adults += 1
end
end
@adults
end

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

RSpec.configure do |config|
config.formatter = :documentation
end

RSpec.describe Park do
describe "#initialize" do
it "exists" do
park1 = Park.new("Underwood", 10)
park2 = Park.new("Washburn", 5)
park3 = Park.new("Wheeler", 15)

expect(park1).to be_a (Park)
expect(park2).to be_a (Park)
expect(park3).to be_a (Park)
end

it "has attributes" do
park1 = Park.new("Underwood", 10)
park2 = Park.new("Washburn", 5)
park3 = Park.new("Wheeler", 15)

expect(park1.name).to eq("Underwood")
expect(park1.price).to eq(10)
expect(park2.name).to eq("Washburn")
expect(park2.price).to eq(5)
expect(park3.name).to eq("Wheeler")
expect(park3.price).to eq(15)
end
end

describe "#vehicles_in_park" do
it "starts with an emptry parking_lot array" do
park1 = Park.new("Underwood", 10)
park2 = Park.new("Washburn", 5)
park3 = Park.new("Wheeler", 15)
vehicle = Vehicle.new("2001", "Honda", "Civic")

expect(park1.parking_lot).to eq([])
expect(park2.parking_lot).to eq([])
expect(park3.parking_lot).to eq([])
end

it "lists the vehicles that have entered the park" do
park1 = Park.new("Underwood", 10)
park2 = Park.new("Washburn", 5)
park3 = Park.new("Wheeler", 15)
vehicle1 = Vehicle.new("2001", "Honda", "Civic")
vehicle2 = Vehicle.new("2001", "Honda", "Civic")
vehicle3 = Vehicle.new("2001", "Honda", "Civic")

vehicle1.enter_park
park1.vehicles_in_park(vehicle1)
vehicle2.enter_park
park1.vehicles_in_park(vehicle2)
vehicle3.enter_park
park3.vehicles_in_park(vehicle3)

expect(park1.parking_lot).to eq([vehicle1, vehicle2])
expect(park2.parking_lot).to eq([])
expect(park3.parking_lot).to eq([vehicle3])
end
end

describe "#passengers_in_park" do
it "listes the passengers that entered the park" do
park1 = Park.new("Underwood", 10)
park2 = Park.new("Washburn", 5)
park3 = Park.new("Wheeler", 15)
vehicle1 = Vehicle.new("2001", "Honda", "Civic")
vehicle2 = Vehicle.new("2001", "Honda", "Civic")
vehicle3 = 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})

vehicle1.add_passenger(charlie)
vehicle1.add_passenger(jude)
vehicle3.add_passenger(taylor)

expect(vehicle1.passengers).to eq([charlie, jude])
expect(vehicle2.passengers).to eq([])
expect(vehicle3.passengers).to eq([taylor])

vehicle1.enter_park
vehicle2.enter_park
vehicle3.enter_park

expect(park1.visitors).to eq([charlie, jude])
# expect(park2.visitors).to eq([])
# expect(park3.visitors).to eq([taylor])
end
end
end
40 changes: 40 additions & 0 deletions spec/passenger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,45 @@
charlie = Passenger.new({"name" => "Charlie", "age" => 18})
expect(charlie).to be_a Passenger
end

it "has attributes" do
charlie = Passenger.new({"name" => "Charlie", "age" => 18})
taylor = Passenger.new({"name" => "Taylor", "age" => 12})

expect(charlie.name).to eq("Charlie")
expect(charlie.age).to eq(18)
expect(taylor.name).to eq("Taylor")
expect(taylor.age).to eq(12)
end
end

describe "#adult?" do
it "determines if a Passenger is an adult" do
charlie = Passenger.new({"name" => "Charlie", "age" => 18})
taylor = Passenger.new({"name" => "Taylor", "age" => 12})

charlie.adult?
taylor.adult?
expect(charlie.adult?).to be(true)
expect(taylor.adult?).to be (false)
end
end

describe "#driver?" do
it "can have a a passenger drive" do
charlie = Passenger.new({"name" => "Charlie", "age" => 18})
taylor = Passenger.new({"name" => "Taylor", "age" => 12})

expect(charlie.drive).to be(true)
end

it "determines if a Passenger is a driver or not" do
charlie = Passenger.new({"name" => "Charlie", "age" => 18})
taylor = Passenger.new({"name" => "Taylor", "age" => 12})

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

RSpec.configure do |config|
config.formatter = :documentation
end

RSpec.describe Vehicle do
describe "#initialize" do
it "exists" do
vehicle = Vehicle.new("2001", "Honda", "Civic")

expect(vehicle).to be_a (Vehicle)
end

it "has attributes" do
vehicle = Vehicle.new("2001", "Honda", "Civic")

expect(vehicle.year).to eq("2001")
expect(vehicle.make).to eq("Honda")
expect(vehicle.model).to eq("Civic")
end
end

describe "#speeding?" do
it "can have a speeding vehicle" do
vehicle = Vehicle.new("2001", "Honda", "Civic")

expect(vehicle.speed).to be(true)
end

it "determines if the vehicle is speeding" do
vehicle = Vehicle.new("2001", "Honda", "Civic")

expect(vehicle.speeding?).to be (false)
vehicle.speed
expect(vehicle.speeding?).to be (true)
end
end

describe "#passengers" do
it "starts a vehicle with an empty array of passengers" do
vehicle = Vehicle.new("2001", "Honda", "Civic")

expect(vehicle.passengers).to eq([])
end

it "can add passengers to the passengers array" 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})

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 "determines the number of adult passengers in a vehicle" 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})

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

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

describe "#enter_park" do
it "cant enter a park" do
vehicle = Vehicle.new("2001", "Honda", "Civic")

expect(vehicle.enter_park).to be(true)
end
end
end