From d19c9219c8301e8fa5d22fff5cf602ee7fcea777 Mon Sep 17 00:00:00 2001 From: ontruster74 Date: Wed, 18 Dec 2024 09:30:08 -0700 Subject: [PATCH 1/6] complete iteration 1 --- lib/passenger.rb | 23 ++++++++++++++++++++ spec/passenger_spec.rb | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 spec/passenger_spec.rb diff --git a/lib/passenger.rb b/lib/passenger.rb index e69de29..d8ace30 100644 --- a/lib/passenger.rb +++ b/lib/passenger.rb @@ -0,0 +1,23 @@ +class Passenger + attr_reader :name, :age + + + def initialize(passenger_details) + @name = passenger_details["name"] + @age = passenger_details["age"] + @drives = false + end + + def adult? + age >= 18 ? true : false + end + + def driver? + return @drives + end + + def drive + @drives = true + end + +end \ No newline at end of file diff --git a/spec/passenger_spec.rb b/spec/passenger_spec.rb new file mode 100644 index 0000000..f5d1586 --- /dev/null +++ b/spec/passenger_spec.rb @@ -0,0 +1,49 @@ +require './lib/passenger' +require 'rspec' + +describe Passenger do + before do + @charlie = Passenger.new({"name" => "Charlie", "age" => 18}) + @taylor = Passenger.new({"name" => "Taylor", "age" => 12}) + end + + describe '#initialize' 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 'can check whether a passenger is an adult' do + expect(@charlie.adult?).to eq(true) + expect(@taylor.adult?).to eq(false) + end + end + + describe '#driver?' do + it 'can check whether a passenger is the driver' do + expect(@charlie.driver?).to eq(false) + expect(@taylor.driver?).to eq(false) + end + end + + describe '#drive' do + it 'can make a passenger the driver' do + expect(@charlie.driver?).to eq(false) + @charlie.drive + expect(@charlie.driver?).to eq(true) + end + end + +end \ No newline at end of file From 9cc503710706006d4110b503d3acab019010942c Mon Sep 17 00:00:00 2001 From: ontruster74 Date: Wed, 18 Dec 2024 09:59:53 -0700 Subject: [PATCH 2/6] complete iteration 2 --- lib/passenger.rb | 6 ++-- lib/vehicle.rb | 28 ++++++++++++++++ spec/vehicle_spec.rb | 76 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 spec/vehicle_spec.rb diff --git a/lib/passenger.rb b/lib/passenger.rb index d8ace30..d339f10 100644 --- a/lib/passenger.rb +++ b/lib/passenger.rb @@ -5,7 +5,7 @@ class Passenger def initialize(passenger_details) @name = passenger_details["name"] @age = passenger_details["age"] - @drives = false + @driver = false end def adult? @@ -13,11 +13,11 @@ def adult? end def driver? - return @drives + return @driver end def drive - @drives = true + @driver = true end end \ No newline at end of file diff --git a/lib/vehicle.rb b/lib/vehicle.rb index e69de29..f6bc3b8 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -0,0 +1,28 @@ +class Vehicle + attr_reader :year, :make, :model, :passengers + + def initialize(year, make, model) + @year = year + @make = make + @model = model + @passengers = [] + @speeding = false + end + + def speeding? + return @speeding + end + + def speed + @speeding = true + end + + def add_passenger(passenger) + @passengers << passenger + end + + def num_adults + return passengers.select{|passenger| passenger.adult?}.length + 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..584ac5c --- /dev/null +++ b/spec/vehicle_spec.rb @@ -0,0 +1,76 @@ +require './lib/passenger' +require './lib/vehicle' +require 'rspec' + +describe Vehicle do + before 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_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 + + it 'starts with no passengers' do + expect(@vehicle.passengers).to eq([]) + end + end + + describe '#speeding?' do + it 'can check whether a vehicle is speeding' do + expect(@vehicle.speeding?).to eq(false) + end + end + + describe '#speed' do + it 'can make a vehicle start speeding' do + expect(@vehicle.speeding?).to eq(false) + + @vehicle.speed + + expect(@vehicle.speeding?).to eq(true) + end + end + + describe '#add_passenger' do + it 'can add passengers to a vehicle' 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 'can track number of adults in a vehicle' do + @vehicle.add_passenger(@charlie) + @vehicle.add_passenger(@jude) + @vehicle.add_passenger(@taylor) + + expect(@charlie.adult?).to eq(true) + expect(@jude.adult?).to eq(true) + expect(@taylor.adult?).to eq(false) + + expect(@vehicle.num_adults).to eq(2) + end + end + +end \ No newline at end of file From 3f2511956f20f64acb96f9130404bdd54f95d7b0 Mon Sep 17 00:00:00 2001 From: ontruster74 Date: Wed, 18 Dec 2024 10:26:13 -0700 Subject: [PATCH 3/6] add park class file --- lib/park.rb | 35 +++++++++++++++++++++++++++++++++++ spec/park_spec.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 spec/park_spec.rb diff --git a/lib/park.rb b/lib/park.rb index e69de29..950a4b6 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -0,0 +1,35 @@ +class Park +attr_reader :name, :price, :vehicles, :passengers + + def initialize(name, price) + @name = name + @price = price + @vehicles = [] + @passengers = [] + end + + def add_vehicle(course) + @vehicles << course + @passengers << course.passengers.flatten + return @vehicles + end + + def revenue + return (price * (@passengers.select{|passenger| passenger.adult?})) + end + + def patron_names + return @passengers.map{|passenger| passenger.name}.sort + end + + def minors + minors = @passengers.select{|passenger| passenger.adult?} + return minors.map{|minor| minor.name}.sort + end + + def adults + adults = @passengers.select{|passenger| passenger.adult? == false} + return adults.map{|adult| adult.name}.sort + 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..adf7ff3 --- /dev/null +++ b/spec/park_spec.rb @@ -0,0 +1,31 @@ +require './lib/passenger' +require './lib/vehicle' +require './lib/park' +require 'rspec' + +describe Park do + describe '#initialize' do + + end + + describe '#add_vehicle' do + + end + + describe '#revenue' do + + end + + describe '#patron_names' do + + end + + describe '#minors' do + + end + + describe '#adults' do + + end + +end \ No newline at end of file From c9b20483b5e74b49789c562b8beabf9fd7ff9c27 Mon Sep 17 00:00:00 2001 From: ontruster74 Date: Wed, 18 Dec 2024 10:47:34 -0700 Subject: [PATCH 4/6] add park class tests --- spec/park_spec.rb | 84 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/spec/park_spec.rb b/spec/park_spec.rb index adf7ff3..52d34d9 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -4,28 +4,100 @@ require 'rspec' describe Park do - describe '#initialize' do + before do + @charlie = Passenger.new({"name" => "Charlie", "age" => 18}) + @jude = Passenger.new({"name" => "Jude", "age" => 20}) + @taylor = Passenger.new({"name" => "Taylor", "age" => 12}) + @honda = Vehicle.new("2001", "Honda", "Civic") + @honda.add_passenger(@charlie) + @honda.add_passenger(@jude) + @honda.add_passenger(@taylor) + + @wilson = Passenger.new({"name" => "Wilson", "age" => 38}) + @debbie = Passenger.new({"name" => "Debbie", "age" => 36}) + + @toyota = Vehicle.new("2015", "Toyota", "4Runner") + @toyota.add_passenger(@wilson) + @toyota.add_passenger(@debbie) + + @rick = Passenger.new({"name" => "Rick", "age" => 45}) + + @hyundai = Vehicle.new("2008", "Hyundai", "Sonata") + @hyundai.add_passenger(@rick) + + @fester = Passenger.new({"name" => "Charlie", "age" => 63}) + @wednesday = Passenger.new({"name" => "Wednesday", "age" => 14}) + @pugsley = Passenger.new({"name" => "Pugsley", "age" => 13}) + + @ford = Vehicle.new("1951", "Ford", "Model T") + @ford.add_passenger(@fester) + @ford.add_passenger(@wednesday) + @ford.add_passenger(@pugsley) + + @yellowstone = Park.new("Yellowstone", 30) + @sequoia = Park.new("Sequoia", 20) + end + + describe '#initialize' do + it 'exists' do + expect(@yellowstone).to be_a(Park) + end + + it 'has a name' do + + end + + it 'has a price' do + + end + + it 'starts with an empty list of vehicles' do + + end + + it 'starts with an empty list of passengers' do + + end + end describe '#add_vehicle' do - + it 'can add a vehicle to the park' do + + end + + it 'can list all the vehicles that entered the park' do + + end + + it 'can list all the passengers that entered the park' do + + end end describe '#revenue' do - + it 'can calculate revenue generated' do + + end end describe '#patron_names' do - + it 'can provide an alphabetical list of patron names' do + + end end describe '#minors' do - + it 'can provide an alphabetical list of all minors' do + + end end describe '#adults' do - + it 'can provide an alphabetical list of all adults' do + + end end end \ No newline at end of file From 0f8ac762a74e10f427c2b7dbe4461c62c5bfb0cd Mon Sep 17 00:00:00 2001 From: ontruster74 Date: Wed, 18 Dec 2024 11:07:53 -0700 Subject: [PATCH 5/6] complete iterations 3 and 4 --- lib/park.rb | 10 +++++---- spec/park_spec.rb | 53 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/lib/park.rb b/lib/park.rb index 950a4b6..3b5782f 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -10,12 +10,14 @@ def initialize(name, price) def add_vehicle(course) @vehicles << course - @passengers << course.passengers.flatten + course.passengers.each {|passenger| + @passengers << passenger + } return @vehicles end def revenue - return (price * (@passengers.select{|passenger| passenger.adult?})) + return (price * (@passengers.select{|passenger| passenger.adult?}.length)) end def patron_names @@ -23,12 +25,12 @@ def patron_names end def minors - minors = @passengers.select{|passenger| passenger.adult?} + minors = @passengers.select{|passenger| passenger.adult? == false} return minors.map{|minor| minor.name}.sort end def adults - adults = @passengers.select{|passenger| passenger.adult? == false} + adults = @passengers.select{|passenger| passenger.adult?} return adults.map{|adult| adult.name}.sort end diff --git a/spec/park_spec.rb b/spec/park_spec.rb index 52d34d9..ac173b8 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -14,11 +14,11 @@ @honda.add_passenger(@jude) @honda.add_passenger(@taylor) - @wilson = Passenger.new({"name" => "Wilson", "age" => 38}) + @lamar = Passenger.new({"name" => "Lamar", "age" => 38}) @debbie = Passenger.new({"name" => "Debbie", "age" => 36}) @toyota = Vehicle.new("2015", "Toyota", "4Runner") - @toyota.add_passenger(@wilson) + @toyota.add_passenger(@lamar) @toyota.add_passenger(@debbie) @rick = Passenger.new({"name" => "Rick", "age" => 45}) @@ -26,7 +26,7 @@ @hyundai = Vehicle.new("2008", "Hyundai", "Sonata") @hyundai.add_passenger(@rick) - @fester = Passenger.new({"name" => "Charlie", "age" => 63}) + @fester = Passenger.new({"name" => "Fester", "age" => 63}) @wednesday = Passenger.new({"name" => "Wednesday", "age" => 14}) @pugsley = Passenger.new({"name" => "Pugsley", "age" => 13}) @@ -36,7 +36,6 @@ @ford.add_passenger(@pugsley) @yellowstone = Park.new("Yellowstone", 30) - @sequoia = Park.new("Sequoia", 20) end describe '#initialize' do @@ -45,58 +44,82 @@ end it 'has a name' do - + expect(@yellowstone.name).to eq("Yellowstone") end it 'has a price' do - + expect(@yellowstone.price).to eq(30) end it 'starts with an empty list of vehicles' do - + expect(@yellowstone.vehicles).to eq([]) end it 'starts with an empty list of passengers' do - + expect(@yellowstone.passengers).to eq([]) end end describe '#add_vehicle' do it 'can add a vehicle to the park' do - + expect(@yellowstone.add_vehicle(@honda)).to eq([@honda]) end it 'can list all the vehicles that entered the park' do - + @yellowstone.add_vehicle(@honda) + @yellowstone.add_vehicle(@toyota) + @yellowstone.add_vehicle(@hyundai) + @yellowstone.add_vehicle(@ford) + expect(@yellowstone.vehicles).to eq([@honda, @toyota, @hyundai, @ford]) end it 'can list all the passengers that entered the park' do - + @yellowstone.add_vehicle(@honda) + @yellowstone.add_vehicle(@toyota) + expect(@yellowstone.passengers).to eq([@charlie, @jude, @taylor, @lamar, @debbie]) end end describe '#revenue' do it 'can calculate revenue generated' do - + @yellowstone.add_vehicle(@honda) + @yellowstone.add_vehicle(@toyota) + @yellowstone.add_vehicle(@hyundai) + @yellowstone.add_vehicle(@ford) + expect(@yellowstone.price).to eq(30) + expect(@yellowstone.adults.length).to eq(6) + expect(@yellowstone.revenue).to eq(180) end end describe '#patron_names' do it 'can provide an alphabetical list of patron names' do - + @yellowstone.add_vehicle(@honda) + @yellowstone.add_vehicle(@toyota) + @yellowstone.add_vehicle(@hyundai) + @yellowstone.add_vehicle(@ford) + expect(@yellowstone.patron_names).to eq(["Charlie", "Debbie", "Fester", "Jude", "Lamar", "Pugsley", "Rick", "Taylor", "Wednesday"]) end end describe '#minors' do it 'can provide an alphabetical list of all minors' do - + @yellowstone.add_vehicle(@honda) + @yellowstone.add_vehicle(@toyota) + @yellowstone.add_vehicle(@hyundai) + @yellowstone.add_vehicle(@ford) + expect(@yellowstone.minors).to eq(["Pugsley", "Taylor", "Wednesday"]) end end describe '#adults' do it 'can provide an alphabetical list of all adults' do - + @yellowstone.add_vehicle(@honda) + @yellowstone.add_vehicle(@toyota) + @yellowstone.add_vehicle(@hyundai) + @yellowstone.add_vehicle(@ford) + expect(@yellowstone.adults).to eq(["Charlie", "Debbie", "Fester", "Jude", "Lamar", "Rick"]) end end From 0769da2573efb8a85aa4c8e7380504b70d65e00a Mon Sep 17 00:00:00 2001 From: ontruster74 Date: Wed, 18 Dec 2024 11:11:00 -0700 Subject: [PATCH 6/6] add line breaks for readability --- spec/park_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/park_spec.rb b/spec/park_spec.rb index ac173b8..6c04e47 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -87,8 +87,10 @@ @yellowstone.add_vehicle(@toyota) @yellowstone.add_vehicle(@hyundai) @yellowstone.add_vehicle(@ford) + expect(@yellowstone.price).to eq(30) expect(@yellowstone.adults.length).to eq(6) + expect(@yellowstone.revenue).to eq(180) end end @@ -99,6 +101,7 @@ @yellowstone.add_vehicle(@toyota) @yellowstone.add_vehicle(@hyundai) @yellowstone.add_vehicle(@ford) + expect(@yellowstone.patron_names).to eq(["Charlie", "Debbie", "Fester", "Jude", "Lamar", "Pugsley", "Rick", "Taylor", "Wednesday"]) end end @@ -109,6 +112,7 @@ @yellowstone.add_vehicle(@toyota) @yellowstone.add_vehicle(@hyundai) @yellowstone.add_vehicle(@ford) + expect(@yellowstone.minors).to eq(["Pugsley", "Taylor", "Wednesday"]) end end @@ -119,6 +123,7 @@ @yellowstone.add_vehicle(@toyota) @yellowstone.add_vehicle(@hyundai) @yellowstone.add_vehicle(@ford) + expect(@yellowstone.adults).to eq(["Charlie", "Debbie", "Fester", "Jude", "Lamar", "Rick"]) end end