From 16a699b9e7c987b927c224b833db31fda149a1cc Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 09:04:17 -0700 Subject: [PATCH 01/20] add the spec files for testing to the repo. --- park_spec.rb | 0 passenger_spec.rb | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 park_spec.rb create mode 100644 passenger_spec.rb diff --git a/park_spec.rb b/park_spec.rb new file mode 100644 index 0000000..e69de29 diff --git a/passenger_spec.rb b/passenger_spec.rb new file mode 100644 index 0000000..e69de29 From 57ca9fea2ea006ce4f261148c5cbf72c39a542f3 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 09:11:34 -0700 Subject: [PATCH 02/20] add the test files for the classes. Initialize test on passengers started. --- passenger_spec.rb | 0 spec/park_spec.rb | 2 ++ spec/passenger_spec.rb | 13 +++++++++++++ spec/spec_helper.rb | 3 +++ park_spec.rb => spec/vehicle_spec.rb | 0 5 files changed, 18 insertions(+) delete mode 100644 passenger_spec.rb create mode 100644 spec/park_spec.rb create mode 100644 spec/passenger_spec.rb create mode 100644 spec/spec_helper.rb rename park_spec.rb => spec/vehicle_spec.rb (100%) diff --git a/passenger_spec.rb b/passenger_spec.rb deleted file mode 100644 index e69de29..0000000 diff --git a/spec/park_spec.rb b/spec/park_spec.rb new file mode 100644 index 0000000..e743d22 --- /dev/null +++ b/spec/park_spec.rb @@ -0,0 +1,2 @@ +require './spec/spec_helper.rb' + diff --git a/spec/passenger_spec.rb b/spec/passenger_spec.rb new file mode 100644 index 0000000..90b105c --- /dev/null +++ b/spec/passenger_spec.rb @@ -0,0 +1,13 @@ +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 +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..af653cf --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,3 @@ +require './lib/park.rb' +require './lib/passenger.rb' +require './lib/vehicle.rb' diff --git a/park_spec.rb b/spec/vehicle_spec.rb similarity index 100% rename from park_spec.rb rename to spec/vehicle_spec.rb From e5b7eab78a11440951cf6f1c60e487976f22664d Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 09:15:58 -0700 Subject: [PATCH 03/20] passenger has a name test passes --- lib/passenger.rb | 9 +++++++++ spec/passenger_spec.rb | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/lib/passenger.rb b/lib/passenger.rb index e69de29..7e2f158 100644 --- a/lib/passenger.rb +++ b/lib/passenger.rb @@ -0,0 +1,9 @@ + + +class Passenger + attr_reader :name + + def initialize(passenger_info) + @name = passenger_info['name'] + end +end \ No newline at end of file diff --git a/spec/passenger_spec.rb b/spec/passenger_spec.rb index 90b105c..1a3542b 100644 --- a/spec/passenger_spec.rb +++ b/spec/passenger_spec.rb @@ -10,4 +10,9 @@ 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 + end \ No newline at end of file From 222e994f2f0da66d7026f96bb5fc4028d4d97a71 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 09:18:22 -0700 Subject: [PATCH 04/20] create test for age on passesnger --- lib/passenger.rb | 4 +++- spec/passenger_spec.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/passenger.rb b/lib/passenger.rb index 7e2f158..7aefc98 100644 --- a/lib/passenger.rb +++ b/lib/passenger.rb @@ -1,9 +1,11 @@ class Passenger - attr_reader :name + attr_reader :name, + :age def initialize(passenger_info) @name = passenger_info['name'] + @age = passenger_info['age'] end end \ No newline at end of file diff --git a/spec/passenger_spec.rb b/spec/passenger_spec.rb index 1a3542b..5eed220 100644 --- a/spec/passenger_spec.rb +++ b/spec/passenger_spec.rb @@ -15,4 +15,8 @@ expect(@taylor.name).to eq('Taylor') end + it 'has age' do + expect(@charlie.age).to eq(18) + expect(@taylor.age).to eq(12) + end end \ No newline at end of file From a604c773c2566fd549716f3ae241862ba917e557 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 09:22:30 -0700 Subject: [PATCH 05/20] passenger class passes adult? test --- lib/passenger.rb | 4 ++++ spec/passenger_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/passenger.rb b/lib/passenger.rb index 7aefc98..02ee3a5 100644 --- a/lib/passenger.rb +++ b/lib/passenger.rb @@ -8,4 +8,8 @@ def initialize(passenger_info) @name = passenger_info['name'] @age = passenger_info['age'] end + + def adult? + @age >= 18 ? true : false + end end \ No newline at end of file diff --git a/spec/passenger_spec.rb b/spec/passenger_spec.rb index 5eed220..a102354 100644 --- a/spec/passenger_spec.rb +++ b/spec/passenger_spec.rb @@ -19,4 +19,10 @@ 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 + end \ No newline at end of file From 2303f1bad7325312da521cc27285ba99ba1c1e93 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 09:29:03 -0700 Subject: [PATCH 06/20] passenger class passes respec tests. --- lib/passenger.rb | 12 +++++++++++- spec/passenger_spec.rb | 13 ++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/passenger.rb b/lib/passenger.rb index 02ee3a5..def003a 100644 --- a/lib/passenger.rb +++ b/lib/passenger.rb @@ -2,14 +2,24 @@ class Passenger attr_reader :name, - :age + :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 \ No newline at end of file diff --git a/spec/passenger_spec.rb b/spec/passenger_spec.rb index a102354..f91ae04 100644 --- a/spec/passenger_spec.rb +++ b/spec/passenger_spec.rb @@ -24,5 +24,16 @@ 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 \ No newline at end of file From fa6dc239c479b58cfb961d2a0651846ba33dc7dc Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 09:34:24 -0700 Subject: [PATCH 07/20] initialize test written --- spec/vehicle_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index e69de29..97c8ea9 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -0,0 +1,14 @@ +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 + + it 'initializes' do + expect(@vehicle).to be_an_instance_of(Vehicle) + end +end \ No newline at end of file From eaa7c441fa89916cb3e8d8d27b3bf671c112b034 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 09:46:54 -0700 Subject: [PATCH 08/20] write tests for class methods in vehicle --- lib/vehicle.rb | 23 +++++++++++++++++++++++ spec/vehicle_spec.rb | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/lib/vehicle.rb b/lib/vehicle.rb index e69de29..b0fd335 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -0,0 +1,23 @@ + + +class Vehicle + attr_reader :year, + :make, + :model, + :speeding + + def initialize(year, make, model) + @year = year + @make = make + @model = model + @speeding = false + end + + def speeding? + @speeding + end + + def speed + @speeding = true + end +end \ No newline at end of file diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index 97c8ea9..f7175ba 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -8,7 +8,41 @@ @taylor = Passenger.new({"name" => "Taylor", "age" => 12}) end - it 'initializes' do - expect(@vehicle).to be_an_instance_of(Vehicle) + 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 end end \ No newline at end of file From 4bcd1c6f99a7f381292a3050f7979a44cb021203 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 09:49:04 -0700 Subject: [PATCH 09/20] class passes tests for speed and adding passengers --- lib/vehicle.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/vehicle.rb b/lib/vehicle.rb index b0fd335..22e5d2f 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -4,13 +4,15 @@ class Vehicle attr_reader :year, :make, :model, - :speeding + :speeding, + :passengers def initialize(year, make, model) @year = year @make = make @model = model @speeding = false + @passengers = [] end def speeding? @@ -20,4 +22,10 @@ def speeding? def speed @speeding = true end + + def add_passenger(passenger) + @passengers << passenger + end + + end \ No newline at end of file From 10722a2b17437b90bf7bff7fb0e6030cf8c54a39 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 10:00:02 -0700 Subject: [PATCH 10/20] iteration 2 passes tests!!!!! --- lib/vehicle.rb | 5 ++++- spec/spec_helper.rb | 1 + spec/vehicle_spec.rb | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/vehicle.rb b/lib/vehicle.rb index 22e5d2f..cda1e1b 100644 --- a/lib/vehicle.rb +++ b/lib/vehicle.rb @@ -27,5 +27,8 @@ def add_passenger(passenger) @passengers << passenger end - + def num_adults + adults = @passengers.find_all {|x| x.adult?} + return adults.count + end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index af653cf..da8bcb2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ +require 'pry' require './lib/park.rb' require './lib/passenger.rb' require './lib/vehicle.rb' diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index f7175ba..fe436cb 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -44,5 +44,13 @@ 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 \ No newline at end of file From b1048b9d84e9539ec4c4e96442d7263849e7064b Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 10:13:09 -0700 Subject: [PATCH 11/20] started park_spec tests. The before command methods are laid out --- spec/park_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/park_spec.rb b/spec/park_spec.rb index e743d22..656d48d 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -1,2 +1,27 @@ require './spec/spec_helper.rb' +# attr_reader and initialize park name and ticket price +# + + +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 + +end From 6dd91b8bbccba41b2c3104a40ac4abcc3bd1c2c2 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 10:18:12 -0700 Subject: [PATCH 12/20] rspec tests and class are initialized for name and price --- lib/park.rb | 10 ++++++++++ spec/park_spec.rb | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/park.rb b/lib/park.rb index e69de29..2c8a38e 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -0,0 +1,10 @@ + + +class Park + attr_reader :name, :price + + def initialize(name, price) + @name = name + @price = price + end +end \ No newline at end of file diff --git a/spec/park_spec.rb b/spec/park_spec.rb index 656d48d..79b8974 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -24,4 +24,17 @@ @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 end From 18efd7d774112a4aadc5cbae3904227300330cc8 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 10:28:14 -0700 Subject: [PATCH 13/20] vehicles can be added to park, class passes test. --- lib/park.rb | 9 ++++++++- spec/park_spec.rb | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/park.rb b/lib/park.rb index 2c8a38e..3507ebd 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -1,10 +1,17 @@ class Park - attr_reader :name, :price + attr_reader :name, + :price, + :vehicles def initialize(name, price) @name = name @price = price + @vehicles = [] + end + + def add_vehicle(vehicle) + @vehicles << vehicle end end \ No newline at end of file diff --git a/spec/park_spec.rb b/spec/park_spec.rb index 79b8974..c49e656 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -1,7 +1,9 @@ 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 @@ -37,4 +39,18 @@ 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 end From 2627dc8aeea085ba80843b644d2e1fae61adbaf2 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 11:07:46 -0700 Subject: [PATCH 14/20] the park can add passengers --- lib/park.rb | 13 ++++++++++++- spec/park_spec.rb | 14 +++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/park.rb b/lib/park.rb index 3507ebd..954c819 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -3,15 +3,26 @@ class Park attr_reader :name, :price, - :vehicles + :vehicles, + :passengers, + def initialize(name, price) @name = name @price = price @vehicles = [] + @passengers = [] end def add_vehicle(vehicle) @vehicles << vehicle + list_class = @vehicles.each {|x| x.passengers} + passenger_list = list_class.flat_map {|y| y.passengers} + passenger_list.each {|passenger| @passengers << passenger} end + + def revenue + + end + end \ No newline at end of file diff --git a/spec/park_spec.rb b/spec/park_spec.rb index c49e656..7bc9386 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -48,9 +48,21 @@ @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 + end From 8c9e95451af72624c1b7cd7dc99af30a7d80a8c0 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 11:14:51 -0700 Subject: [PATCH 15/20] added tests for revenue --- lib/park.rb | 1 + spec/park_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/park.rb b/lib/park.rb index 954c819..e80710b 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -23,6 +23,7 @@ def add_vehicle(vehicle) def revenue + end end \ No newline at end of file diff --git a/spec/park_spec.rb b/spec/park_spec.rb index 7bc9386..529e57c 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -64,5 +64,18 @@ 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 From bf9c552056d6af1008297e7e305a434f500b8be5 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 11:16:58 -0700 Subject: [PATCH 16/20] renenue passed test on first try!!!!!!! --- lib/park.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/park.rb b/lib/park.rb index e80710b..f4dc9c4 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -5,6 +5,7 @@ class Park :price, :vehicles, :passengers, + :revenue def initialize(name, price) @@ -12,6 +13,7 @@ def initialize(name, price) @price = price @vehicles = [] @passengers = [] + @revenue = 0 end def add_vehicle(vehicle) @@ -22,8 +24,7 @@ def add_vehicle(vehicle) end def revenue - - + @revenue += @passenger.count * @price end end \ No newline at end of file From fe528c80e9052ce45b7354a5518f61cacbbd1491 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 11:20:36 -0700 Subject: [PATCH 17/20] forgot to switch branches rspec tests for park iteration for started --- spec/park_spec.rb | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/spec/park_spec.rb b/spec/park_spec.rb index 529e57c..825ac95 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -77,5 +77,33 @@ 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 + end From 76f65154b121c38a441580b3e417c55f87a4dee3 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 11:41:14 -0700 Subject: [PATCH 18/20] fixed add vehicle, I was overcomplicating it --- lib/park.rb | 6 ++---- spec/park_spec.rb | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/park.rb b/lib/park.rb index f4dc9c4..f196482 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -18,13 +18,11 @@ def initialize(name, price) def add_vehicle(vehicle) @vehicles << vehicle - list_class = @vehicles.each {|x| x.passengers} - passenger_list = list_class.flat_map {|y| y.passengers} - passenger_list.each {|passenger| @passengers << passenger} + vehicle.passengers.each { |passenger| @passengers << passenger } end def revenue - @revenue += @passenger.count * @price + @revenue = @passengers.count * @price end end \ No newline at end of file diff --git a/spec/park_spec.rb b/spec/park_spec.rb index 825ac95..a7d5f07 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -83,27 +83,27 @@ ### iteration 4 -RSpec.describe Park do - before(:each) do - @park_1 = Park.new('Jackson Hole', 10) +# 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_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_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_1.add_passenger(@charlie) +# @vehicle_1.add_passenger(@jude) +# @vehicle_1.add_passenger(@taylor) - @vehicle_2.add_passenger(@patrick) +# @vehicle_2.add_passenger(@patrick) - @park_1.add_vehicle(@vehicle_1) - # @park_1.add_vehicle(@vehicle_2) - end +# @park_1.add_vehicle(@vehicle_1) +# # @park_1.add_vehicle(@vehicle_2) +# end -end +# end From e7b014c3fa045f573842f105f6448b1298340829 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 11:45:45 -0700 Subject: [PATCH 19/20] patron name test written --- lib/park.rb | 2 ++ spec/park_spec.rb | 40 +++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lib/park.rb b/lib/park.rb index f196482..232dd9c 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -25,4 +25,6 @@ def revenue @revenue = @passengers.count * @price end + + end \ No newline at end of file diff --git a/spec/park_spec.rb b/spec/park_spec.rb index a7d5f07..95e66de 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -83,27 +83,33 @@ ### iteration 4 -# RSpec.describe Park do -# before(:each) do -# @park_1 = Park.new('Jackson Hole', 10) +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_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_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_1.add_passenger(@charlie) + @vehicle_1.add_passenger(@jude) + @vehicle_1.add_passenger(@taylor) -# @vehicle_2.add_passenger(@patrick) + @vehicle_2.add_passenger(@patrick) -# @park_1.add_vehicle(@vehicle_1) -# # @park_1.add_vehicle(@vehicle_2) -# end + @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 -# end +end From 974a87ab1dc67f0a640d5afb42dd44b97e006887 Mon Sep 17 00:00:00 2001 From: Patrick Little Date: Wed, 18 Dec 2024 11:57:46 -0700 Subject: [PATCH 20/20] iteration 4 done --- lib/park.rb | 18 ++++++++++++++++-- spec/park_spec.rb | 9 +++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/park.rb b/lib/park.rb index 232dd9c..950ba9d 100644 --- a/lib/park.rb +++ b/lib/park.rb @@ -5,7 +5,8 @@ class Park :price, :vehicles, :passengers, - :revenue + :revenue, + :patron_name def initialize(name, price) @@ -13,6 +14,7 @@ def initialize(name, price) @price = price @vehicles = [] @passengers = [] + @patron_name = [] @revenue = 0 end @@ -25,6 +27,18 @@ 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 \ No newline at end of file diff --git a/spec/park_spec.rb b/spec/park_spec.rb index 95e66de..d4b66c8 100644 --- a/spec/park_spec.rb +++ b/spec/park_spec.rb @@ -112,4 +112,13 @@ 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