From f1f6b586e98dba2f0af2b22772d2e6d1ea573453 Mon Sep 17 00:00:00 2001 From: Jono Sommers Date: Wed, 23 Oct 2024 12:52:30 -0500 Subject: [PATCH 1/3] Fixed type --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b5749d8..a3c1740 100644 --- a/README.md +++ b/README.md @@ -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! From f436e0b2fab8c50399f243f59e1f7497d8b3f25f Mon Sep 17 00:00:00 2001 From: Jono Sommers Date: Wed, 23 Oct 2024 12:52:57 -0500 Subject: [PATCH 2/3] Added tests, all tests passing --- spec/passenger_spec.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/spec/passenger_spec.rb b/spec/passenger_spec.rb index 26a4006..6fce11e 100644 --- a/spec/passenger_spec.rb +++ b/spec/passenger_spec.rb @@ -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 \ No newline at end of file From 1e222dc84950875df175b178ac7ee4a9ac2f0b01 Mon Sep 17 00:00:00 2001 From: Jono Sommers Date: Wed, 23 Oct 2024 12:53:16 -0500 Subject: [PATCH 3/3] Made methods to make tests pass --- lib/park.rb | 22 ++++++++++ lib/passenger.rb | 19 +++++++++ lib/vehicle.rb | 34 ++++++++++++++++ spec/park_spec.rb | 97 ++++++++++++++++++++++++++++++++++++++++++++ spec/vehicle_spec.rb | 85 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 257 insertions(+) create mode 100644 lib/park.rb create mode 100644 lib/passenger.rb create mode 100644 lib/vehicle.rb create mode 100644 spec/park_spec.rb create mode 100644 spec/vehicle_spec.rb diff --git a/lib/park.rb b/lib/park.rb new file mode 100644 index 0000000..93cca98 --- /dev/null +++ b/lib/park.rb @@ -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 \ No newline at end of file diff --git a/lib/passenger.rb b/lib/passenger.rb new file mode 100644 index 0000000..dd99038 --- /dev/null +++ b/lib/passenger.rb @@ -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 \ No newline at end of file diff --git a/lib/vehicle.rb b/lib/vehicle.rb new file mode 100644 index 0000000..19b93a6 --- /dev/null +++ b/lib/vehicle.rb @@ -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 \ No newline at end of file diff --git a/spec/park_spec.rb b/spec/park_spec.rb new file mode 100644 index 0000000..f0a21fd --- /dev/null +++ b/spec/park_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb new file mode 100644 index 0000000..246b4c8 --- /dev/null +++ b/spec/vehicle_spec.rb @@ -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 + \ No newline at end of file