From 355958ebde7ebe155599674b11b5c1f9b06afc45 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Wed, 6 Sep 2017 13:37:33 -0700 Subject: [PATCH 01/43] forgot to commit when files were created --- Rakefile | 9 +++++++++ lib/date_range.rb | 12 ++++++++++++ lib/reservation.rb | 16 ++++++++++++++++ specs/date_range_spec.rb | 18 ++++++++++++++++++ specs/reservation_spec.rb | 19 +++++++++++++++++++ specs/spec_helper.rb | 10 ++++++++++ 6 files changed, 84 insertions(+) create mode 100644 Rakefile create mode 100644 lib/date_range.rb create mode 100644 lib/reservation.rb create mode 100644 specs/date_range_spec.rb create mode 100644 specs/reservation_spec.rb create mode 100644 specs/spec_helper.rb diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..43287f15d --- /dev/null +++ b/Rakefile @@ -0,0 +1,9 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs = [] + t.warning = true + t.test_files = FileList['./specs/*_spec.rb'] +end + +task default: :test diff --git a/lib/date_range.rb b/lib/date_range.rb new file mode 100644 index 000000000..2de6b0ac1 --- /dev/null +++ b/lib/date_range.rb @@ -0,0 +1,12 @@ +require 'date' + +module Hotel + class DateRange + attr_reader :check_in, :check_out + + def initialize(check_in, check_out) + @check_in = Date.new(check_in) + @check_out = check_out + end # end initialize + end # end of class +end # end of module diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..fae7491a5 --- /dev/null +++ b/lib/reservation.rb @@ -0,0 +1,16 @@ +require 'date' +require_relative 'date_range' + +module Hotel + class Reservation + ROOMS = %w(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) + + attr_reader :name, :dates, :room_number + + def initialize(name, check_in, check_out, room_number) + @name = name + @dates = Hotel::DateRange.new(check_in, check_out) + @room_number = ROOMS[room_number.to_i - 1] + end # end initialize + end # end of Reservation +end # end of Hotel module diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb new file mode 100644 index 000000000..d5309470b --- /dev/null +++ b/specs/date_range_spec.rb @@ -0,0 +1,18 @@ +require_relative 'spec_helper' + +describe 'DateRange' do + before do + @puppy_dates = Hotel::DateRange.new("10/13/2017", "10/31/2017") + end # end before + + xdescribe 'initialize' do + it 'takes a check in date and a check out date' do + @puppy_dates.check_in.must_equal "10/13/2017" + @puppy_dates.check_out.must_equal "10/31/2017" + end # end test 1 + + it 'converts check_in and check_out into dates that can be worked on' do + @puppy_dates.check_in.class.must_equal Date + end # end test 2 + end # end #initialize +end # end of all tests diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb new file mode 100644 index 000000000..c5be48913 --- /dev/null +++ b/specs/reservation_spec.rb @@ -0,0 +1,19 @@ +require_relative 'spec_helper' + +describe 'Reservation' do + before do + @puppy_expo = Hotel::Reservation.new('Finn', '10/13/2017', '10/31/2017', 13) + end # end before + + describe 'initialize' do + it 'initializes with guest name, date range from DateRange, and room number' do + @puppy_expo.name.must_equal 'Finn' + @puppy_expo.dates.check_in.must_equal '10/13/2017' + @puppy_expo.dates.check_out.must_equal '10/31/2017' + end # end test 1 + + it 'room_number = its matching index (minus 1) in ROOMS array' do + @puppy_expo.room_number.must_equal Hotel::Reservation::ROOMS[13-1] + end # end test 2 + end # end #initialize +end # end of all tests diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 000000000..9b29d767a --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,10 @@ +require 'simplecov' +SimpleCov.start + +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/skip_dsl' +require_relative '../lib/reservation' +require_relative '../lib/date_range' + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 3290eb5407ea058469a8a89b96fea8f346b1821f Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Wed, 6 Sep 2017 19:08:37 -0700 Subject: [PATCH 02/43] forgot to commit again, created tests for Reservation, Room, DateRange --- lib/date_range.rb | 6 +++++- lib/reservation.rb | 15 ++++++++++----- lib/room.rb | 16 ++++++++++++++++ specs/date_range_spec.rb | 33 +++++++++++++++++++++++++-------- specs/reservation_spec.rb | 22 +++++++++++++--------- specs/room_spec.rb | 23 +++++++++++++++++++++++ 6 files changed, 92 insertions(+), 23 deletions(-) create mode 100644 lib/room.rb create mode 100644 specs/room_spec.rb diff --git a/lib/date_range.rb b/lib/date_range.rb index 2de6b0ac1..f976bfcd8 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -5,8 +5,12 @@ class DateRange attr_reader :check_in, :check_out def initialize(check_in, check_out) - @check_in = Date.new(check_in) + @check_in = check_in @check_out = check_out end # end initialize + + def find_range + @check_out - @check_in + end # end date_range end # end of class end # end of module diff --git a/lib/reservation.rb b/lib/reservation.rb index fae7491a5..bbf5feb15 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,16 +1,21 @@ require 'date' require_relative 'date_range' +require_relative 'room' module Hotel class Reservation - ROOMS = %w(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) - attr_reader :name, :dates, :room_number + attr_reader :guest_name, :dates, :room_number - def initialize(name, check_in, check_out, room_number) - @name = name + def initialize(guest_name, check_in, check_out, room_number) + @guest_name = guest_name @dates = Hotel::DateRange.new(check_in, check_out) - @room_number = ROOMS[room_number.to_i - 1] + @room_number = Hotel::Room.new(room_number) end # end initialize + + def reserve_dates + @dates.find_range + + end end # end of Reservation end # end of Hotel module diff --git a/lib/room.rb b/lib/room.rb new file mode 100644 index 000000000..6cac220a1 --- /dev/null +++ b/lib/room.rb @@ -0,0 +1,16 @@ +require 'date' + +module Hotel + class Room + ROOMS = (1..20).to_a + attr_reader :room_number + + def initialize(room_number) + @room_number = ROOMS[room_number-1] + end # end #initialize + + def assign_room + + end # end #assign_room + end # end Room class +end # Hotel module diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index d5309470b..de3225b09 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -2,17 +2,34 @@ describe 'DateRange' do before do - @puppy_dates = Hotel::DateRange.new("10/13/2017", "10/31/2017") + @puppy_dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) end # end before - xdescribe 'initialize' do + describe 'initialize' do it 'takes a check in date and a check out date' do - @puppy_dates.check_in.must_equal "10/13/2017" - @puppy_dates.check_out.must_equal "10/31/2017" - end # end test 1 + @puppy_dates.check_in.to_s.must_equal "2017-10-13" + @puppy_dates.check_out.to_s.must_equal "2017-10-31" + end # end test - it 'converts check_in and check_out into dates that can be worked on' do + it 'passes check_in and check_out in as Date objects' do @puppy_dates.check_in.class.must_equal Date - end # end test 2 + @puppy_dates.check_out.class.must_equal Date + end # end test end # end #initialize -end # end of all tests + + describe 'find_range' do + it 'finds the number of days needed for the reservation based on given dates' do + @puppy_dates.find_range.must_equal 18 + end # end test + + xit 'checks if a room is available on given dates' do + + end # end test + end # end #date_range + + describe 'reserve_room' do + xit 'reserves room if given dates are available' do + + end # end test + end # end #reserve_room +end # end of all DateRange tests diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index c5be48913..be1afeda1 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -2,18 +2,22 @@ describe 'Reservation' do before do - @puppy_expo = Hotel::Reservation.new('Finn', '10/13/2017', '10/31/2017', 13) + @puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31), 13) end # end before describe 'initialize' do it 'initializes with guest name, date range from DateRange, and room number' do - @puppy_expo.name.must_equal 'Finn' - @puppy_expo.dates.check_in.must_equal '10/13/2017' - @puppy_expo.dates.check_out.must_equal '10/31/2017' - end # end test 1 + @puppy_expo.guest_name.must_equal 'Finn' + @puppy_expo.dates.check_in.to_s.must_equal "2017-10-13" + @puppy_expo.dates.check_out.to_s.must_equal "2017-10-31" + @puppy_expo.room_number.must_equal 13 + end # end test - it 'room_number = its matching index (minus 1) in ROOMS array' do - @puppy_expo.room_number.must_equal Hotel::Reservation::ROOMS[13-1] - end # end test 2 end # end #initialize -end # end of all tests + + describe 'reserve_dates' do + it 'returns the number of days to reserve' do + @puppy_expo.reserve_dates.must_equal 18 + end # end test + end # end #reserve_dates +end # end of all Reservation tests diff --git a/specs/room_spec.rb b/specs/room_spec.rb new file mode 100644 index 000000000..a679a26ac --- /dev/null +++ b/specs/room_spec.rb @@ -0,0 +1,23 @@ +require_relative 'spec_helper' + +describe 'Room' do + before do + @puppy_room = Hotel::Room.new(13) + end # end before + + describe 'initialize' do + it 'creates a class called Room' do + @puppy_room.class.must_equal Class + end # end test + end # end #initialize + + describe 'assign_room' do + xit 'assigns a room number from the ROOMS ARRAY' do + @puppy_room.assign_room.must_equal ROOMS[0] + end # end test + + xit 'room_number = its matching index (room_number minus 1) in ROOMS array' do + @puppy_room.assign_room.must_equal Hotel::Room::ROOMS[13-1] + end # end test + end # end assign_room +end # end all Room tests From 096475f5b0b0c8a431f1c0f8565733ed6a04b549 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Thu, 7 Sep 2017 09:47:51 -0700 Subject: [PATCH 03/43] changed ROOMS to rooms_available --- lib/reservation.rb | 4 ++-- lib/room.rb | 7 ++++--- specs/reservation_spec.rb | 2 +- specs/room_spec.rb | 12 ++++++------ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index bbf5feb15..1464cac92 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -5,12 +5,12 @@ module Hotel class Reservation - attr_reader :guest_name, :dates, :room_number + attr_reader :guest_name, :dates, :room def initialize(guest_name, check_in, check_out, room_number) @guest_name = guest_name @dates = Hotel::DateRange.new(check_in, check_out) - @room_number = Hotel::Room.new(room_number) + @room = Hotel::Room.new(room_number) end # end initialize def reserve_dates diff --git a/lib/room.rb b/lib/room.rb index 6cac220a1..6e6159f08 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -2,15 +2,16 @@ module Hotel class Room - ROOMS = (1..20).to_a + rooms_available = (1..20).to_a attr_reader :room_number def initialize(room_number) - @room_number = ROOMS[room_number-1] + @room_number = rooms_available[room_number-1] end # end #initialize def assign_room - + rooms_available.each do |i| + # go through array and remove the first room available, going from lowest number to highest, return when guest checks out, continue booking the smallest numbered room end # end #assign_room end # end Room class end # Hotel module diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index be1afeda1..f6f7227e6 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -10,7 +10,7 @@ @puppy_expo.guest_name.must_equal 'Finn' @puppy_expo.dates.check_in.to_s.must_equal "2017-10-13" @puppy_expo.dates.check_out.to_s.must_equal "2017-10-31" - @puppy_expo.room_number.must_equal 13 + @puppy_expo.room.room_number.must_equal 13 end # end test end # end #initialize diff --git a/specs/room_spec.rb b/specs/room_spec.rb index a679a26ac..a9d015212 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -6,18 +6,18 @@ end # end before describe 'initialize' do - it 'creates a class called Room' do - @puppy_room.class.must_equal Class + it 'creates an instance of Room' do + @puppy_room.class.must_equal Hotel::Room end # end test end # end #initialize describe 'assign_room' do - xit 'assigns a room number from the ROOMS ARRAY' do - @puppy_room.assign_room.must_equal ROOMS[0] + xit 'assigns a room number from the rooms_available ARRAY' do + @puppy_room.assign_room.must_equal rooms_available[0] end # end test - xit 'room_number = its matching index (room_number minus 1) in ROOMS array' do - @puppy_room.assign_room.must_equal Hotel::Room::ROOMS[13-1] + xit 'room_number = its matching index (room_number minus 1) in rooms_available array' do + @puppy_room.assign_room.must_equal Hotel::Room::rooms_available[13-1] end # end test end # end assign_room end # end all Room tests From 0506643f6ba4dec7427933a593451b7d8192bff9 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Thu, 7 Sep 2017 10:04:23 -0700 Subject: [PATCH 04/43] create test 'removes unavailable rooms' --- lib/reservation.rb | 6 +++--- lib/room.rb | 12 ++++++------ specs/reservation_spec.rb | 2 +- specs/room_spec.rb | 8 +++++++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 1464cac92..c9f13f2cf 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -7,15 +7,15 @@ class Reservation attr_reader :guest_name, :dates, :room - def initialize(guest_name, check_in, check_out, room_number) + def initialize(guest_name, check_in, check_out) @guest_name = guest_name @dates = Hotel::DateRange.new(check_in, check_out) - @room = Hotel::Room.new(room_number) + @room = Hotel::Room.new end # end initialize def reserve_dates @dates.find_range - end + end # end #reserve_dates end # end of Reservation end # end of Hotel module diff --git a/lib/room.rb b/lib/room.rb index 6e6159f08..44bd4303b 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -2,15 +2,15 @@ module Hotel class Room - rooms_available = (1..20).to_a - attr_reader :room_number - - def initialize(room_number) - @room_number = rooms_available[room_number-1] + attr_reader :room_number, :rooms_available + def initialize + @rooms_available = (1..20).to_a + @room_number end # end #initialize def assign_room - rooms_available.each do |i| + @room_number = @rooms_available.pop + # go through array and remove the first room available, going from lowest number to highest, return when guest checks out, continue booking the smallest numbered room end # end #assign_room end # end Room class diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index f6f7227e6..44374ae0a 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -2,7 +2,7 @@ describe 'Reservation' do before do - @puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31), 13) + @puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31)) end # end before describe 'initialize' do diff --git a/specs/room_spec.rb b/specs/room_spec.rb index a9d015212..b8c3c291f 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -2,7 +2,7 @@ describe 'Room' do before do - @puppy_room = Hotel::Room.new(13) + @puppy_room = Hotel::Room.new end # end before describe 'initialize' do @@ -12,6 +12,12 @@ end # end #initialize describe 'assign_room' do + it 'removes unavailable rooms from the rooms_available array' do + all_rooms = @rooms_available + @puppy_room.assign_room + all_rooms.length.must_equal 19 + end # end test + xit 'assigns a room number from the rooms_available ARRAY' do @puppy_room.assign_room.must_equal rooms_available[0] end # end test From 737ea0db549e070b797f98497285de2074d61a77 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Thu, 7 Sep 2017 10:25:24 -0700 Subject: [PATCH 05/43] pass test 'remove checked in room from array' --- lib/reservation.rb | 2 +- lib/room.rb | 6 +++--- specs/date_range_spec.rb | 4 ++-- specs/reservation_spec.rb | 8 +++----- specs/room_spec.rb | 10 +++------- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index c9f13f2cf..bd3930a0a 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -4,7 +4,7 @@ module Hotel class Reservation - + COST = 200 # per night attr_reader :guest_name, :dates, :room def initialize(guest_name, check_in, check_out) diff --git a/lib/room.rb b/lib/room.rb index 44bd4303b..3633ca0b9 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -5,13 +5,13 @@ class Room attr_reader :room_number, :rooms_available def initialize @rooms_available = (1..20).to_a - @room_number + @room_number = room_number end # end #initialize def assign_room - @room_number = @rooms_available.pop + @room_number = @rooms_available.shift # removes first element of array - # go through array and remove the first room available, going from lowest number to highest, return when guest checks out, continue booking the smallest numbered room + # go through array and remove the first room available, (shorten the number of rooms available by shortening the array) then shovel back in as guests check out end # end #assign_room end # end Room class end # Hotel module diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index de3225b09..7fc073c01 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -7,8 +7,8 @@ describe 'initialize' do it 'takes a check in date and a check out date' do - @puppy_dates.check_in.to_s.must_equal "2017-10-13" - @puppy_dates.check_out.to_s.must_equal "2017-10-31" + @puppy_dates.check_in.to_s.must_equal '2017-10-13' + @puppy_dates.check_out.to_s.must_equal '2017-10-31' end # end test it 'passes check_in and check_out in as Date objects' do diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 44374ae0a..bb0877a43 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -8,11 +8,9 @@ describe 'initialize' do it 'initializes with guest name, date range from DateRange, and room number' do @puppy_expo.guest_name.must_equal 'Finn' - @puppy_expo.dates.check_in.to_s.must_equal "2017-10-13" - @puppy_expo.dates.check_out.to_s.must_equal "2017-10-31" - @puppy_expo.room.room_number.must_equal 13 - end # end test - + @puppy_expo.dates.check_in.to_s.must_equal '2017-10-13' + @puppy_expo.dates.check_out.to_s.must_equal '2017-10-31' + end # end testr end # end #initialize describe 'reserve_dates' do diff --git a/specs/room_spec.rb b/specs/room_spec.rb index b8c3c291f..3554d89f4 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -12,18 +12,14 @@ end # end #initialize describe 'assign_room' do - it 'removes unavailable rooms from the rooms_available array' do - all_rooms = @rooms_available + it 'removes unavailable rooms from the rooms_available array each time a room is booked' do + @puppy_room.rooms_available.length @puppy_room.assign_room - all_rooms.length.must_equal 19 + @puppy_room.rooms_available.length.must_equal 19 end # end test xit 'assigns a room number from the rooms_available ARRAY' do @puppy_room.assign_room.must_equal rooms_available[0] end # end test - - xit 'room_number = its matching index (room_number minus 1) in rooms_available array' do - @puppy_room.assign_room.must_equal Hotel::Room::rooms_available[13-1] - end # end test end # end assign_room end # end all Room tests From fbc86ef0741d1055cb8c7bd8f6693b6d542986ac Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 11:16:57 -0700 Subject: [PATCH 06/43] prep for room assign --- lib/reservation.rb | 1 - lib/room.rb | 7 +++++++ specs/room_spec.rb | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index bd3930a0a..0a14d5c57 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -15,7 +15,6 @@ def initialize(guest_name, check_in, check_out) def reserve_dates @dates.find_range - end # end #reserve_dates end # end of Reservation end # end of Hotel module diff --git a/lib/room.rb b/lib/room.rb index 3633ca0b9..eb71d1003 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -13,5 +13,12 @@ def assign_room # go through array and remove the first room available, (shorten the number of rooms available by shortening the array) then shovel back in as guests check out end # end #assign_room + + def check_out_of_room + @rooms_available << @room_number + end # end #check_out_of_room + + def is_available?(checkin, check_out) + end # end #is_available? end # end Room class end # Hotel module diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 3554d89f4..7784d3930 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -18,8 +18,8 @@ @puppy_room.rooms_available.length.must_equal 19 end # end test - xit 'assigns a room number from the rooms_available ARRAY' do - @puppy_room.assign_room.must_equal rooms_available[0] + it 'assigns room number and not index number' do + @puppy_room.assign_room.must_equal 1 end # end test end # end assign_room end # end all Room tests From 7a3cc133f99a4a01af7db4447e4a69af8cde26da Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 11:23:36 -0700 Subject: [PATCH 07/43] commenting a big question because i am confused --- specs/room_spec.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 7784d3930..ffba4f1e1 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -19,7 +19,14 @@ end # end test it 'assigns room number and not index number' do - @puppy_room.assign_room.must_equal 1 + @puppy_room.assign_room + @puppy_room.assign_room + @puppy_room.assign_room.must_equal 3 + + #################################### + # okay so in this test, i want it to change the room number as they are booked. so #assign_room is called 3 times, room number should be 3. BUT, what is happening, is it's the SAME GUEST booking 3 rooms. if i make a new instance of Hotel::Room, obv it'll just reset the array and the room assigned would be 1. how do????) + ##################################### + end # end test end # end assign_room end # end all Room tests From 4b73c4014485a80cb3bc661a00b297d776d17431 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 11:47:32 -0700 Subject: [PATCH 08/43] @@rooms_available, diff room for diff guests --- lib/room.rb | 9 ++++++--- specs/room_spec.rb | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index eb71d1003..3bd0b6500 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -2,20 +2,23 @@ module Hotel class Room + @@rooms_available = (1..20).to_a + end + attr_reader :room_number, :rooms_available + def self.rooms_available def initialize - @rooms_available = (1..20).to_a @room_number = room_number end # end #initialize def assign_room - @room_number = @rooms_available.shift # removes first element of array + @room_number = @@rooms_available.shift # removes first element of array # go through array and remove the first room available, (shorten the number of rooms available by shortening the array) then shovel back in as guests check out end # end #assign_room def check_out_of_room - @rooms_available << @room_number + @@rooms_available << @room_number end # end #check_out_of_room def is_available?(checkin, check_out) diff --git a/specs/room_spec.rb b/specs/room_spec.rb index ffba4f1e1..6058d7a6a 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -13,20 +13,22 @@ describe 'assign_room' do it 'removes unavailable rooms from the rooms_available array each time a room is booked' do - @puppy_room.rooms_available.length - @puppy_room.assign_room - @puppy_room.rooms_available.length.must_equal 19 + Hotel::Room.rooms_available.length # 20 + @puppy_room.assign_room # 1 + Hotel::Room.rooms_available.length.must_equal 19 end # end test - it 'assigns room number and not index number' do - @puppy_room.assign_room - @puppy_room.assign_room - @puppy_room.assign_room.must_equal 3 + it 'assigns a different room number as they are assigned and made unavailable' do + @puppy_room.assign_room # 1 + @kitten_room = Hotel::Room.new + @kitten_room.assign_room # 2 + @bat_room = Hotel::Room.new + @bat_room.assign_room.must_equal 3 #################################### # okay so in this test, i want it to change the room number as they are booked. so #assign_room is called 3 times, room number should be 3. BUT, what is happening, is it's the SAME GUEST booking 3 rooms. if i make a new instance of Hotel::Room, obv it'll just reset the array and the room assigned would be 1. how do????) ##################################### - + end # end test end # end assign_room end # end all Room tests From 2b1b0c327ddb7cbd48fd68dd6de3ae880eb1755f Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 11:51:48 -0700 Subject: [PATCH 09/43] remove room as booked/fail assign diff room --- lib/room.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 3bd0b6500..bb75f66ff 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -3,14 +3,17 @@ module Hotel class Room @@rooms_available = (1..20).to_a - end attr_reader :room_number, :rooms_available - def self.rooms_available + def initialize @room_number = room_number end # end #initialize + def self.rooms_available + @@rooms_available + end # end #rooms_available + def assign_room @room_number = @@rooms_available.shift # removes first element of array From 7110fa2e84463f759d2be8c0abf47652f002d271 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 12:02:50 -0700 Subject: [PATCH 10/43] change rooms_available to ROOMS --- lib/room.rb | 6 ++++-- specs/room_spec.rb | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index bb75f66ff..f7222bd4c 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -2,12 +2,13 @@ module Hotel class Room - @@rooms_available = (1..20).to_a + ROOMS = (1..20).to_a attr_reader :room_number, :rooms_available def initialize @room_number = room_number + @@rooms_available = ROOMS end # end #initialize def self.rooms_available @@ -15,7 +16,8 @@ def self.rooms_available end # end #rooms_available def assign_room - @room_number = @@rooms_available.shift # removes first element of array + @room_number = @@rooms_available[0] + @@rooms_available.shift # removes first element of array # go through array and remove the first room available, (shorten the number of rooms available by shortening the array) then shovel back in as guests check out end # end #assign_room diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 6058d7a6a..222e26096 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -25,10 +25,6 @@ @bat_room = Hotel::Room.new @bat_room.assign_room.must_equal 3 - #################################### - # okay so in this test, i want it to change the room number as they are booked. so #assign_room is called 3 times, room number should be 3. BUT, what is happening, is it's the SAME GUEST booking 3 rooms. if i make a new instance of Hotel::Room, obv it'll just reset the array and the room assigned would be 1. how do????) - ##################################### - end # end test end # end assign_room end # end all Room tests From c0fbf2e71e7ee7ec465494908c943034fa73c4bf Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 12:16:02 -0700 Subject: [PATCH 11/43] @puppy_room @kitten_room @bat_room --- lib/room.rb | 5 ++--- specs/room_spec.rb | 8 +++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index f7222bd4c..07ca38dad 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -3,12 +3,12 @@ module Hotel class Room ROOMS = (1..20).to_a + @@rooms_available = ROOMS attr_reader :room_number, :rooms_available def initialize @room_number = room_number - @@rooms_available = ROOMS end # end #initialize def self.rooms_available @@ -16,8 +16,7 @@ def self.rooms_available end # end #rooms_available def assign_room - @room_number = @@rooms_available[0] - @@rooms_available.shift # removes first element of array + @room_number = @@rooms_available.shift # removes first element of array # go through array and remove the first room available, (shorten the number of rooms available by shortening the array) then shovel back in as guests check out end # end #assign_room diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 222e26096..c930d16a2 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -3,6 +3,8 @@ describe 'Room' do before do @puppy_room = Hotel::Room.new + @kitten_room = Hotel::Room.new + @bat_room = Hotel::Room.new end # end before describe 'initialize' do @@ -15,14 +17,14 @@ it 'removes unavailable rooms from the rooms_available array each time a room is booked' do Hotel::Room.rooms_available.length # 20 @puppy_room.assign_room # 1 - Hotel::Room.rooms_available.length.must_equal 19 + @kitten_room.assign_room + @bat_room.assign_room + Hotel::Room.rooms_available.length.must_equal 17 end # end test it 'assigns a different room number as they are assigned and made unavailable' do @puppy_room.assign_room # 1 - @kitten_room = Hotel::Room.new @kitten_room.assign_room # 2 - @bat_room = Hotel::Room.new @bat_room.assign_room.must_equal 3 end # end test From f3b4d4f287f24eca292d589ab4072f0eb3b4af51 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 13:33:50 -0700 Subject: [PATCH 12/43] rooms are returned to the array at checkout --- lib/room.rb | 8 ++++++++ specs/room_spec.rb | 35 +++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 07ca38dad..56ef7a3c7 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -11,18 +11,26 @@ def initialize @room_number = room_number end # end #initialize + ######################### + def self.initialize_rooms + @@rooms_available = (1..20).to_a + end + ######################### + def self.rooms_available @@rooms_available end # end #rooms_available def assign_room @room_number = @@rooms_available.shift # removes first element of array + return @room_number # go through array and remove the first room available, (shorten the number of rooms available by shortening the array) then shovel back in as guests check out end # end #assign_room def check_out_of_room @@rooms_available << @room_number + return @@rooms_available end # end #check_out_of_room def is_available?(checkin, check_out) diff --git a/specs/room_spec.rb b/specs/room_spec.rb index c930d16a2..f5ecfdd9f 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -2,6 +2,9 @@ describe 'Room' do before do + ############################ + Hotel::Room.initialize_rooms + ############################ @puppy_room = Hotel::Room.new @kitten_room = Hotel::Room.new @bat_room = Hotel::Room.new @@ -16,17 +19,33 @@ describe 'assign_room' do it 'removes unavailable rooms from the rooms_available array each time a room is booked' do Hotel::Room.rooms_available.length # 20 - @puppy_room.assign_room # 1 - @kitten_room.assign_room - @bat_room.assign_room - Hotel::Room.rooms_available.length.must_equal 17 + @puppy_room.assign_room # -1 + @kitten_room.assign_room # -1 + Hotel::Room.rooms_available.length.must_equal 18 end # end test it 'assigns a different room number as they are assigned and made unavailable' do - @puppy_room.assign_room # 1 - @kitten_room.assign_room # 2 - @bat_room.assign_room.must_equal 3 - + @puppy_room.assign_room # room 1 + @kitten_room.assign_room # room 2 + @bat_room.assign_room # room 3 + @bat_room.room_number.must_equal 3 end # end test end # end assign_room + + describe 'check_out_of_room' do + it 'returns the room number to the rooms_available array when a guest checks out' do + @puppy_room.assign_room # room 1 + @kitten_room.assign_room # room 2 + @bat_room.assign_room # room 3 + + @puppy_room.check_out_of_room + @kitten_room.check_out_of_room + @bat_room.check_out_of_room + Hotel::Room.rooms_available.must_equal [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3] + end # end test + + # it 'will sort the rooms_available array each time a room is assigned so the remaining rooms are in order (this will help when consecutive rooms need to be booked together)' do + + # end # end test + end # end #check_out_of_room end # end all Room tests From 8c8d24eb070b59c3cc2dc3709284865265994bb4 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 13:44:53 -0700 Subject: [PATCH 13/43] returns rooms to array in numerical order --- lib/room.rb | 2 +- specs/room_spec.rb | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 56ef7a3c7..a8df9bf29 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -30,7 +30,7 @@ def assign_room def check_out_of_room @@rooms_available << @room_number - return @@rooms_available + return @@rooms_available.sort! # sort the rooms back into numerical order as they are returned to the array end # end #check_out_of_room def is_available?(checkin, check_out) diff --git a/specs/room_spec.rb b/specs/room_spec.rb index f5ecfdd9f..b257b31bf 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -36,16 +36,20 @@ it 'returns the room number to the rooms_available array when a guest checks out' do @puppy_room.assign_room # room 1 @kitten_room.assign_room # room 2 - @bat_room.assign_room # room 3 + @puppy_room.check_out_of_room # return 1 to array - @puppy_room.check_out_of_room - @kitten_room.check_out_of_room - @bat_room.check_out_of_room - Hotel::Room.rooms_available.must_equal [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3] + Hotel::Room.rooms_available.must_include 1 end # end test - # it 'will sort the rooms_available array each time a room is assigned so the remaining rooms are in order (this will help when consecutive rooms need to be booked together)' do + it 'will sort the rooms_available array each time a room is assigned so the remaining rooms are in order (this will help when consecutive rooms need to be booked together)' do + @puppy_room.assign_room # room 1 + @kitten_room.assign_room # room 2 + @bat_room.assign_room # room 3 + @puppy_room.check_out_of_room # room 1 + @kitten_room.check_out_of_room # room 2 + @bat_room.check_out_of_room # room 3 - # end # end test + Hotel::Room.rooms_available.must_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + end # end test end # end #check_out_of_room end # end all Room tests From bf1b1aa93786f09756dab3adbcebbfbdcb236110 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 13:48:39 -0700 Subject: [PATCH 14/43] begin working on dates --- lib/date_range.rb | 2 +- lib/reservation.rb | 2 +- lib/room.rb | 2 -- specs/date_range_spec.rb | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index f976bfcd8..1bcd26b7f 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -9,7 +9,7 @@ def initialize(check_in, check_out) @check_out = check_out end # end initialize - def find_range + def length_of_stay @check_out - @check_in end # end date_range end # end of class diff --git a/lib/reservation.rb b/lib/reservation.rb index 0a14d5c57..4417ec2b3 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -14,7 +14,7 @@ def initialize(guest_name, check_in, check_out) end # end initialize def reserve_dates - @dates.find_range + @dates.length_of_stay end # end #reserve_dates end # end of Reservation end # end of Hotel module diff --git a/lib/room.rb b/lib/room.rb index a8df9bf29..166dad842 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -24,8 +24,6 @@ def self.rooms_available def assign_room @room_number = @@rooms_available.shift # removes first element of array return @room_number - - # go through array and remove the first room available, (shorten the number of rooms available by shortening the array) then shovel back in as guests check out end # end #assign_room def check_out_of_room diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index 7fc073c01..d8830abc6 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -17,9 +17,9 @@ end # end test end # end #initialize - describe 'find_range' do + describe 'length_of_stay' do it 'finds the number of days needed for the reservation based on given dates' do - @puppy_dates.find_range.must_equal 18 + @puppy_dates.length_of_stay.must_equal 18 end # end test xit 'checks if a room is available on given dates' do From 4b442a858af60a1f051b98dc849ea43cd1a9ded1 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 14:11:07 -0700 Subject: [PATCH 15/43] try making reservation hash --- lib/date_range.rb | 7 +++++++ lib/reservation.rb | 14 +++++++++++++- specs/date_range_spec.rb | 6 ++++-- specs/reservation_spec.rb | 4 ++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 1bcd26b7f..48f6ad2b6 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -12,5 +12,12 @@ def initialize(check_in, check_out) def length_of_stay @check_out - @check_in end # end date_range + + def is_available? + + end # end #is_available? + + def reserve_room + end # end #reserve_room end # end of class end # end of module diff --git a/lib/reservation.rb b/lib/reservation.rb index 4417ec2b3..b27d1f094 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -5,16 +5,28 @@ module Hotel class Reservation COST = 200 # per night - attr_reader :guest_name, :dates, :room + attr_reader :guest_name, :dates, :room, :reservation def initialize(guest_name, check_in, check_out) @guest_name = guest_name @dates = Hotel::DateRange.new(check_in, check_out) @room = Hotel::Room.new + + @reservation = {} + #reservation: [name: date_range, room, cost] + #sort_by{|k,v|v} end # end initialize def reserve_dates @dates.length_of_stay end # end #reserve_dates + + def final_reservation + + end # end #final_reservation + + def list_by_date + + end # end #list_by_date end # end of Reservation end # end of Hotel module diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index d8830abc6..b3b26917c 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -21,12 +21,14 @@ it 'finds the number of days needed for the reservation based on given dates' do @puppy_dates.length_of_stay.must_equal 18 end # end test + end # end #length_of_stay + describe 'is_available?' do xit 'checks if a room is available on given dates' do end # end test - end # end #date_range - + end # end #is_available? + describe 'reserve_room' do xit 'reserves room if given dates are available' do diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index bb0877a43..2f756c50e 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -17,5 +17,9 @@ it 'returns the number of days to reserve' do @puppy_expo.reserve_dates.must_equal 18 end # end test + + it 'returns the array of dates needed to be reserved' do + + end # end test end # end #reserve_dates end # end of all Reservation tests From ca5e5822a66da6b72e3f5956be4a5d523c354079 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 15:05:09 -0700 Subject: [PATCH 16/43] create mad hash for reservation --- lib/date_range.rb | 7 ------- lib/reservation.rb | 12 +++++++++--- specs/date_range_spec.rb | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 48f6ad2b6..1bcd26b7f 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -12,12 +12,5 @@ def initialize(check_in, check_out) def length_of_stay @check_out - @check_in end # end date_range - - def is_available? - - end # end #is_available? - - def reserve_room - end # end #reserve_room end # end of class end # end of module diff --git a/lib/reservation.rb b/lib/reservation.rb index b27d1f094..90e157beb 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -11,8 +11,8 @@ def initialize(guest_name, check_in, check_out) @guest_name = guest_name @dates = Hotel::DateRange.new(check_in, check_out) @room = Hotel::Room.new + @reservation = reservation - @reservation = {} #reservation: [name: date_range, room, cost] #sort_by{|k,v|v} end # end initialize @@ -22,11 +22,17 @@ def reserve_dates end # end #reserve_dates def final_reservation - + @reservation = { + name: @guest_name, + check_in: @check_in, + check_out: @check_out, + room: @room, + cost: COST * Hotel::DateRange.length_of_stay, + } end # end #final_reservation def list_by_date - + end # end #list_by_date end # end of Reservation end # end of Hotel module diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index b3b26917c..0e9dd4c3d 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -28,7 +28,7 @@ end # end test end # end #is_available? - + describe 'reserve_room' do xit 'reserves room if given dates are available' do From a2224f9dff9e669fa41600c087ea997c781b1a0b Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 15:07:35 -0700 Subject: [PATCH 17/43] grammar --- lib/reservation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 90e157beb..79880a505 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -27,7 +27,7 @@ def final_reservation check_in: @check_in, check_out: @check_out, room: @room, - cost: COST * Hotel::DateRange.length_of_stay, + cost: COST * Hotel::DateRange.length_of_stay } end # end #final_reservation From 544b2270ec9ecbf9c015a8fa5ccba533b0ec69c5 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 15:35:24 -0700 Subject: [PATCH 18/43] reservation info output - fails --- lib/reservation.rb | 16 +++++++--------- specs/reservation_spec.rb | 6 ++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 79880a505..c66f444d3 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -9,6 +9,8 @@ class Reservation def initialize(guest_name, check_in, check_out) @guest_name = guest_name + @check_in = check_in + @check_out = check_out @dates = Hotel::DateRange.new(check_in, check_out) @room = Hotel::Room.new @reservation = reservation @@ -21,15 +23,11 @@ def reserve_dates @dates.length_of_stay end # end #reserve_dates - def final_reservation - @reservation = { - name: @guest_name, - check_in: @check_in, - check_out: @check_out, - room: @room, - cost: COST * Hotel::DateRange.length_of_stay - } - end # end #final_reservation + def finalize_reservation + booking = "Name: #{@guest_name}\nCheck In: #{@check_in}\nCheck Out: #{@check_out}\nRoom Number: #{@room}\nTotal Cost: $#{COST * @dates.length_of_stay}" + + return puts booking + end # end #finalize_reservation def list_by_date diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 2f756c50e..f60619a45 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -22,4 +22,10 @@ end # end test end # end #reserve_dates + + describe 'finalize_reservation' do + it 'displays complete reservation info' do + @puppy_expo.finalize_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" + end # end test + end # end #final_reservation end # end of all Reservation tests From 68cb68d70b48841581fa094a847898f38d7ee94f Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 8 Sep 2017 15:53:28 -0700 Subject: [PATCH 19/43] pass print reservation info --- lib/reservation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index c66f444d3..be2217b03 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -24,9 +24,9 @@ def reserve_dates end # end #reserve_dates def finalize_reservation - booking = "Name: #{@guest_name}\nCheck In: #{@check_in}\nCheck Out: #{@check_out}\nRoom Number: #{@room}\nTotal Cost: $#{COST * @dates.length_of_stay}" + booking = "Name: #{@guest_name}\nCheck In: #{@check_in}\nCheck Out: #{@check_out}\nRoom Number: #{@room.assign_room}\nTotal Cost: $#{(COST * @dates.length_of_stay).to_i}" - return puts booking + return booking end # end #finalize_reservation def list_by_date From 205a157051ba41e3f622c5d6f08a4a218d9fcfd3 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sat, 9 Sep 2017 22:40:33 -0700 Subject: [PATCH 20/43] start hash --- lib/reservation.rb | 9 ++++----- specs/reservation_spec.rb | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index be2217b03..d4caa8378 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -5,7 +5,7 @@ module Hotel class Reservation COST = 200 # per night - attr_reader :guest_name, :dates, :room, :reservation + attr_reader :guest_name, :dates, :room, :reservation :list def initialize(guest_name, check_in, check_out) @guest_name = guest_name @@ -14,15 +14,12 @@ def initialize(guest_name, check_in, check_out) @dates = Hotel::DateRange.new(check_in, check_out) @room = Hotel::Room.new @reservation = reservation + @list = list #reservation: [name: date_range, room, cost] #sort_by{|k,v|v} end # end initialize - def reserve_dates - @dates.length_of_stay - end # end #reserve_dates - def finalize_reservation booking = "Name: #{@guest_name}\nCheck In: #{@check_in}\nCheck Out: #{@check_out}\nRoom Number: #{@room.assign_room}\nTotal Cost: $#{(COST * @dates.length_of_stay).to_i}" @@ -30,7 +27,9 @@ def finalize_reservation end # end #finalize_reservation def list_by_date + @list = { + } end # end #list_by_date end # end of Reservation end # end of Hotel module diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index f60619a45..621ea09b8 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -2,7 +2,11 @@ describe 'Reservation' do before do + ############################ + Hotel::Room.initialize_rooms + ############################ @puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31)) + @kitten_expo = Hotel::Reservation.new('Girlie', Date.new(2018, 1, 17), Date.new(2018, 1, 31)) end # end before describe 'initialize' do @@ -10,22 +14,16 @@ @puppy_expo.guest_name.must_equal 'Finn' @puppy_expo.dates.check_in.to_s.must_equal '2017-10-13' @puppy_expo.dates.check_out.to_s.must_equal '2017-10-31' - end # end testr - end # end #initialize - - describe 'reserve_dates' do - it 'returns the number of days to reserve' do - @puppy_expo.reserve_dates.must_equal 18 - end # end test - - it 'returns the array of dates needed to be reserved' do - end # end test - end # end #reserve_dates - + end # end #initialize describe 'finalize_reservation' do it 'displays complete reservation info' do @puppy_expo.finalize_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" end # end test + + it 'displays different info for each new reservation w/o overwrite' do + @puppy_expo.finalize_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" + @kitten_expo.finalize_reservation.must_equal "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 2\nTotal Cost: $2800" + end end # end #final_reservation end # end of all Reservation tests From efee7b2221cbf271e96273bf2d922c37f82697c3 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 10 Sep 2017 00:09:03 -0700 Subject: [PATCH 21/43] create hash of booking info --- lib/reservation.rb | 27 ++++++++++++++++----------- specs/reservation_spec.rb | 20 ++++++++++++++------ specs/spec_helper.rb | 1 + 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index d4caa8378..ad710ff2a 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -5,7 +5,7 @@ module Hotel class Reservation COST = 200 # per night - attr_reader :guest_name, :dates, :room, :reservation :list + attr_reader :guest_name, :dates, :room, :reservation, :cost, :list def initialize(guest_name, check_in, check_out) @guest_name = guest_name @@ -13,23 +13,28 @@ def initialize(guest_name, check_in, check_out) @check_out = check_out @dates = Hotel::DateRange.new(check_in, check_out) @room = Hotel::Room.new - @reservation = reservation - @list = list + @cost = (COST * @dates.length_of_stay).to_i + @list = { + :guest_name => @guest_name, + :check_in => @check_in.to_s, + :check_out => @check_out.to_s, + :cost => @cost + } #reservation: [name: date_range, room, cost] #sort_by{|k,v|v} end # end initialize - def finalize_reservation - booking = "Name: #{@guest_name}\nCheck In: #{@check_in}\nCheck Out: #{@check_out}\nRoom Number: #{@room.assign_room}\nTotal Cost: $#{(COST * @dates.length_of_stay).to_i}" + def self.list_all + end #end #list_all - return booking - end # end #finalize_reservation + def self.list_by_date + end # end #list_by_date - def list_by_date - @list = { + def display_reservation + booking = "Name: #{@guest_name}\nCheck In: #{@check_in}\nCheck Out: #{@check_out}\nRoom Number: #{@room.assign_room}\nTotal Cost: $#{@cost}" - } - end # end #list_by_date + return booking + end # end #display_reservation end # end of Reservation end # end of Hotel module diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 621ea09b8..9332cd7df 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -10,20 +10,28 @@ end # end before describe 'initialize' do - it 'initializes with guest name, date range from DateRange, and room number' do + it 'initializes with guest name, date range from DateRange, and room number from Room' do @puppy_expo.guest_name.must_equal 'Finn' @puppy_expo.dates.check_in.to_s.must_equal '2017-10-13' @puppy_expo.dates.check_out.to_s.must_equal '2017-10-31' end # end test + + it 'creates a hash containing all information, including cost' do + @puppy_expo.list[:guest_name].must_equal 'Finn' + @puppy_expo.list[:check_in].must_equal '2017-10-13' + @puppy_expo.list[:check_out].must_equal '2017-10-31' + @puppy_expo.list[:cost].must_equal 3600 + end end # end #initialize - describe 'finalize_reservation' do + + describe 'display_reservation' do it 'displays complete reservation info' do - @puppy_expo.finalize_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" + @puppy_expo.display_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" end # end test it 'displays different info for each new reservation w/o overwrite' do - @puppy_expo.finalize_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" - @kitten_expo.finalize_reservation.must_equal "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 2\nTotal Cost: $2800" + @puppy_expo.display_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" + @kitten_expo.display_reservation.must_equal "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 2\nTotal Cost: $2800" end - end # end #final_reservation + end # end #display_reservation end # end of all Reservation tests diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 9b29d767a..ec45fa495 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -6,5 +6,6 @@ require 'minitest/skip_dsl' require_relative '../lib/reservation' require_relative '../lib/date_range' +require_relative '../lib/room' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 19270bed5efbd6b409fbff229710e5c4a8c9a824 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 10 Sep 2017 01:08:50 -0700 Subject: [PATCH 22/43] self.list_all mess --- lib/reservation.rb | 40 ++++++++++++++++++++++----------------- lib/room.rb | 4 ---- specs/reservation_spec.rb | 11 ++++++----- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index ad710ff2a..769701be4 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,3 +1,5 @@ +require 'pry' + require 'date' require_relative 'date_range' require_relative 'room' @@ -5,36 +7,40 @@ module Hotel class Reservation COST = 200 # per night - attr_reader :guest_name, :dates, :room, :reservation, :cost, :list + @@reservations = [] + attr_reader :guest_name, :dates, :room, :cost, :list def initialize(guest_name, check_in, check_out) + @guest_name = guest_name @check_in = check_in @check_out = check_out @dates = Hotel::DateRange.new(check_in, check_out) @room = Hotel::Room.new @cost = (COST * @dates.length_of_stay).to_i - @list = { - :guest_name => @guest_name, - :check_in => @check_in.to_s, - :check_out => @check_out.to_s, - :cost => @cost - } - + @@reservations << self + # @list = { + # :guest_name => @guest_name, + # :check_in => @check_in.to_s, + # :check_out => @check_out.to_s, + # :cost => @cost + # } + # #reservation: [name: date_range, room, cost] - #sort_by{|k,v|v} + #sort_by{|k,v|v} date end # end initialize - def self.list_all - end #end #list_all + def self.reservation + @@reservations + end - def self.list_by_date - end # end #list_by_date + def self.print_list + @@reservations.each do | booking | + puts "Name: #{booking.guest_name}" - def display_reservation - booking = "Name: #{@guest_name}\nCheck In: #{@check_in}\nCheck Out: #{@check_out}\nRoom Number: #{@room.assign_room}\nTotal Cost: $#{@cost}" - return booking - end # end #display_reservation + # puts "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.assign_room}\nTotal Cost: $#{booking.cost}" + end + end # end #self.print_list end # end of Reservation end # end of Hotel module diff --git a/lib/room.rb b/lib/room.rb index 166dad842..7e358910f 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -7,10 +7,6 @@ class Room attr_reader :room_number, :rooms_available - def initialize - @room_number = room_number - end # end #initialize - ######################### def self.initialize_rooms @@rooms_available = (1..20).to_a diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 9332cd7df..ee70beb79 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -16,7 +16,7 @@ @puppy_expo.dates.check_out.to_s.must_equal '2017-10-31' end # end test - it 'creates a hash containing all information, including cost' do + xit 'creates a hash containing all information, including cost' do @puppy_expo.list[:guest_name].must_equal 'Finn' @puppy_expo.list[:check_in].must_equal '2017-10-13' @puppy_expo.list[:check_out].must_equal '2017-10-31' @@ -24,14 +24,15 @@ end end # end #initialize - describe 'display_reservation' do + describe 'self.print_list' do it 'displays complete reservation info' do - @puppy_expo.display_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" + @puppy_expo + Hotel::Reservation.print_list.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" end # end test - it 'displays different info for each new reservation w/o overwrite' do + xit 'displays different info for each new reservation w/o overwrite' do @puppy_expo.display_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" @kitten_expo.display_reservation.must_equal "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 2\nTotal Cost: $2800" end - end # end #display_reservation + end # end #self.print_list end # end of all Reservation tests From f5e776a5ad83c7d33c4e70223217927f73cff333 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 10 Sep 2017 01:55:13 -0700 Subject: [PATCH 23/43] pass print_list --- lib/reservation.rb | 21 +++++---------------- lib/room.rb | 6 +++--- specs/reservation_spec.rb | 33 +++++++++++++-------------------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 769701be4..b14d7cb05 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,4 +1,3 @@ -require 'pry' require 'date' require_relative 'date_range' @@ -8,7 +7,7 @@ module Hotel class Reservation COST = 200 # per night @@reservations = [] - attr_reader :guest_name, :dates, :room, :cost, :list + attr_reader :guest_name, :check_in, :check_out, :dates, :room, :cost, :list def initialize(guest_name, check_in, check_out) @@ -19,28 +18,18 @@ def initialize(guest_name, check_in, check_out) @room = Hotel::Room.new @cost = (COST * @dates.length_of_stay).to_i @@reservations << self - # @list = { - # :guest_name => @guest_name, - # :check_in => @check_in.to_s, - # :check_out => @check_out.to_s, - # :cost => @cost - # } - # - #reservation: [name: date_range, room, cost] - #sort_by{|k,v|v} date end # end initialize def self.reservation @@reservations - end + end # end self.reservations def self.print_list + bookings = [] @@reservations.each do | booking | - puts "Name: #{booking.guest_name}" - - - # puts "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.assign_room}\nTotal Cost: $#{booking.cost}" + bookings << "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.assign_room}\nTotal Cost: $#{booking.cost}" end + return bookings end # end #self.print_list end # end of Reservation end # end of Hotel module diff --git a/lib/room.rb b/lib/room.rb index 7e358910f..547dba322 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -2,8 +2,8 @@ module Hotel class Room - ROOMS = (1..20).to_a - @@rooms_available = ROOMS + ROOMS = (1..20).to_a + @@rooms_available = ROOMS attr_reader :room_number, :rooms_available @@ -27,7 +27,7 @@ def check_out_of_room return @@rooms_available.sort! # sort the rooms back into numerical order as they are returned to the array end # end #check_out_of_room - def is_available?(checkin, check_out) + def available?(checkin, check_out) end # end #is_available? end # end Room class end # Hotel module diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index ee70beb79..ed2575ae7 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1,38 +1,31 @@ require_relative 'spec_helper' +puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31)) +kitten_expo = Hotel::Reservation.new('Girlie', Date.new(2018, 1, 17), Date.new(2018, 1, 31)) describe 'Reservation' do before do ############################ Hotel::Room.initialize_rooms ############################ - @puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31)) - @kitten_expo = Hotel::Reservation.new('Girlie', Date.new(2018, 1, 17), Date.new(2018, 1, 31)) end # end before describe 'initialize' do it 'initializes with guest name, date range from DateRange, and room number from Room' do - @puppy_expo.guest_name.must_equal 'Finn' - @puppy_expo.dates.check_in.to_s.must_equal '2017-10-13' - @puppy_expo.dates.check_out.to_s.must_equal '2017-10-31' + puppy_expo.guest_name.must_equal 'Finn' + puppy_expo.dates.check_in.to_s.must_equal '2017-10-13' + puppy_expo.dates.check_out.to_s.must_equal '2017-10-31' end # end test - - xit 'creates a hash containing all information, including cost' do - @puppy_expo.list[:guest_name].must_equal 'Finn' - @puppy_expo.list[:check_in].must_equal '2017-10-13' - @puppy_expo.list[:check_out].must_equal '2017-10-31' - @puppy_expo.list[:cost].must_equal 3600 - end end # end #initialize describe 'self.print_list' do - it 'displays complete reservation info' do - @puppy_expo - Hotel::Reservation.print_list.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" + it 'returns list of all reservations' do + Hotel::Reservation.print_list.must_equal ["Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600", "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 2\nTotal Cost: $2800"] end # end test - - xit 'displays different info for each new reservation w/o overwrite' do - @puppy_expo.display_reservation.must_equal "Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600" - @kitten_expo.display_reservation.must_equal "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 2\nTotal Cost: $2800" - end end # end #self.print_list + + describe 'self.list_by_date' do + it 'returns a list of reservations for a specific date' do + + end # end test + end # end #self.list_by_date end # end of all Reservation tests From 0e6a2a42df7e9a590756f6336d0898c65418d77d Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 10 Sep 2017 02:05:40 -0700 Subject: [PATCH 24/43] list reservations on a given date --- lib/reservation.rb | 6 ++++++ specs/reservation_spec.rb | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index b14d7cb05..9a40cb021 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -31,5 +31,11 @@ def self.print_list end return bookings end # end #self.print_list + + def self.on_date(date) + @@reservations.select do | reservation | + reservation.check_in == date + end + end # end #self.on_date end # end of Reservation end # end of Hotel module diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index ed2575ae7..a4371c3c2 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -23,9 +23,9 @@ end # end test end # end #self.print_list - describe 'self.list_by_date' do + describe 'self.on_date' do it 'returns a list of reservations for a specific date' do - + Hotel::Reservation.on_date(Date.new(2018, 1, 17)).must_equal [kitten_expo] end # end test - end # end #self.list_by_date + end # end #self.on_date end # end of all Reservation tests From 5397ce167730c8bac11541b286693cfa468c3ebf Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 10 Sep 2017 21:26:26 -0700 Subject: [PATCH 25/43] test self.reservations --- lib/reservation.rb | 10 +++++----- lib/room.rb | 2 +- specs/reservation_spec.rb | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 9a40cb021..d18208810 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -6,7 +6,7 @@ module Hotel class Reservation COST = 200 # per night - @@reservations = [] + @@reservations = [] # list of all reservations made attr_reader :guest_name, :check_in, :check_out, :dates, :room, :cost, :list def initialize(guest_name, check_in, check_out) @@ -17,23 +17,23 @@ def initialize(guest_name, check_in, check_out) @dates = Hotel::DateRange.new(check_in, check_out) @room = Hotel::Room.new @cost = (COST * @dates.length_of_stay).to_i - @@reservations << self + @@reservations << self # each new instance put into the list of total reservations end # end initialize - def self.reservation + def self.reservations @@reservations end # end self.reservations def self.print_list bookings = [] @@reservations.each do | booking | - bookings << "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.assign_room}\nTotal Cost: $#{booking.cost}" + bookings << "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.assign_room}\nTotal Cost: $#{booking.cost}" # turns out you can't use instance variables within a class method end return bookings end # end #self.print_list def self.on_date(date) - @@reservations.select do | reservation | + @@reservations.select do | reservation | # filter reservation.check_in == date end end # end #self.on_date diff --git a/lib/room.rb b/lib/room.rb index 547dba322..8bc990924 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -27,7 +27,7 @@ def check_out_of_room return @@rooms_available.sort! # sort the rooms back into numerical order as they are returned to the array end # end #check_out_of_room - def available?(checkin, check_out) + def available?(check_in, check_out) end # end #is_available? end # end Room class end # Hotel module diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index a4371c3c2..0499973be 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -17,6 +17,12 @@ end # end test end # end #initialize + describe 'self.reservations' do + it 'calls the class variable @@reservations, which holds all instances of Reservation in an array' do + Hotel::Reservation.reservations.must_equal [puppy_expo, kitten_expo] + end # end test + end # end #self.reservations + describe 'self.print_list' do it 'returns list of all reservations' do Hotel::Reservation.print_list.must_equal ["Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600", "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 2\nTotal Cost: $2800"] From acc4c641296bf3ed1a5f19cad40634664ad59a43 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 10 Sep 2017 21:30:33 -0700 Subject: [PATCH 26/43] begin #available? tests --- lib/room.rb | 2 ++ specs/room_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/room.rb b/lib/room.rb index 8bc990924..a19745fe9 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -28,6 +28,8 @@ def check_out_of_room end # end #check_out_of_room def available?(check_in, check_out) + Hotel::Reservation.reservations.each do | room | + if end # end #is_available? end # end Room class end # Hotel module diff --git a/specs/room_spec.rb b/specs/room_spec.rb index b257b31bf..d77bdc713 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -52,4 +52,18 @@ Hotel::Room.rooms_available.must_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] end # end test end # end #check_out_of_room + + def 'available?' do + it 'compares list of reservation with list of rooms' do + + end # end test + + it 'returns false if a room is already on the list of reservations for a given date' do + + end # end test + + it 'returns true if a room is not on the list of reservations for a given date' do + + end # end test + end # end #available? end # end all Room tests From 4819f44a82cad215f057e76e6e9aa905d21ad187 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 10 Sep 2017 23:49:16 -0700 Subject: [PATCH 27/43] self.available_rooms and rooms.csv --- lib/reservation.rb | 29 +++++++++++++++++++++-------- lib/room.rb | 38 ++++++++++++-------------------------- specs/reservation_spec.rb | 18 +++++++++--------- specs/room_spec.rb | 9 +++------ support/rooms.csv | 20 ++++++++++++++++++++ 5 files changed, 65 insertions(+), 49 deletions(-) create mode 100644 support/rooms.csv diff --git a/lib/reservation.rb b/lib/reservation.rb index d18208810..7a79d3fa7 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -4,18 +4,17 @@ require_relative 'room' module Hotel - class Reservation + class Reservation # various ways to list reservations COST = 200 # per night @@reservations = [] # list of all reservations made attr_reader :guest_name, :check_in, :check_out, :dates, :room, :cost, :list - def initialize(guest_name, check_in, check_out) - + def initialize(guest_name, check_in, check_out, room) @guest_name = guest_name @check_in = check_in @check_out = check_out @dates = Hotel::DateRange.new(check_in, check_out) - @room = Hotel::Room.new + @room = room @cost = (COST * @dates.length_of_stay).to_i @@reservations << self # each new instance put into the list of total reservations end # end initialize @@ -26,16 +25,30 @@ def self.reservations def self.print_list bookings = [] - @@reservations.each do | booking | - bookings << "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.assign_room}\nTotal Cost: $#{booking.cost}" # turns out you can't use instance variables within a class method + @@reservations.each do |booking| + bookings << "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room}\nTotal Cost: $#{booking.cost}" # turns out you can't use instance variables within a class method end return bookings end # end #self.print_list - def self.on_date(date) - @@reservations.select do | reservation | # filter + def self.on_date(date) # list reservations on a given date + @@reservations.select do |reservation| reservation.check_in == date end end # end #self.on_date + + def self.available_rooms(date_range) # list reservations on given date range + reservations_in_range = @@reservations.reject do |reservation| # excludes reservastions outside date range + reservation.check_out < date_range.check_in && reservation.check_in > date_range.check_out + end + + rooms_in_range = reservations_in_range.map do |reservation| # iterates over reservations_in_range and converts each reservation into its room number (instead of list of obj, becomes list of int) + reservation.room.room_number + end + + return Hotel::Room.all.reject do |room| # remove from list of rooms without reservations in date range + rooms_in_range.include?(room.room_number) + end + end # end #self.available_rooms end # end of Reservation end # end of Hotel module diff --git a/lib/room.rb b/lib/room.rb index a19745fe9..9304d6c91 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,35 +1,21 @@ require 'date' +require 'csv' module Hotel class Room - ROOMS = (1..20).to_a - @@rooms_available = ROOMS - attr_reader :room_number, :rooms_available - ######################### - def self.initialize_rooms - @@rooms_available = (1..20).to_a - end - ######################### - - def self.rooms_available - @@rooms_available - end # end #rooms_available - - def assign_room - @room_number = @@rooms_available.shift # removes first element of array - return @room_number - end # end #assign_room - - def check_out_of_room - @@rooms_available << @room_number - return @@rooms_available.sort! # sort the rooms back into numerical order as they are returned to the array - end # end #check_out_of_room + def initialize(room_number) + @room_number = room_number + end # end #initialize - def available?(check_in, check_out) - Hotel::Reservation.reservations.each do | room | - if - end # end #is_available? + def self.all + all_rooms = [] + CSV.open("support/rooms.csv", 'r').each do |line| + room_number = line[0].to_i + all_rooms << self.new(room_number) + end + return all_rooms + end # end #self.all end # end Room class end # Hotel module diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 0499973be..352fb02b1 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1,14 +1,8 @@ require_relative 'spec_helper' -puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31)) -kitten_expo = Hotel::Reservation.new('Girlie', Date.new(2018, 1, 17), Date.new(2018, 1, 31)) +puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31), 13) +kitten_expo = Hotel::Reservation.new('Girlie', Date.new(2018, 1, 17), Date.new(2018, 1, 31), 11) describe 'Reservation' do - before do - ############################ - Hotel::Room.initialize_rooms - ############################ - end # end before - describe 'initialize' do it 'initializes with guest name, date range from DateRange, and room number from Room' do puppy_expo.guest_name.must_equal 'Finn' @@ -25,7 +19,7 @@ describe 'self.print_list' do it 'returns list of all reservations' do - Hotel::Reservation.print_list.must_equal ["Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 1\nTotal Cost: $3600", "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 2\nTotal Cost: $2800"] + Hotel::Reservation.print_list.must_equal ["Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 13\nTotal Cost: $3600", "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 11\nTotal Cost: $2800"] end # end test end # end #self.print_list @@ -34,4 +28,10 @@ Hotel::Reservation.on_date(Date.new(2018, 1, 17)).must_equal [kitten_expo] end # end test end # end #self.on_date + + describe 'self.available_rooms' do + it 'excludes reservations outside a given date range' do + + end # end test + end # end #self.available_rooms end # end of all Reservation tests diff --git a/specs/room_spec.rb b/specs/room_spec.rb index d77bdc713..23cf2322f 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1,10 +1,7 @@ require_relative 'spec_helper' -describe 'Room' do +xdescribe 'Room' do before do - ############################ - Hotel::Room.initialize_rooms - ############################ @puppy_room = Hotel::Room.new @kitten_room = Hotel::Room.new @bat_room = Hotel::Room.new @@ -53,9 +50,9 @@ end # end test end # end #check_out_of_room - def 'available?' do + describe 'available?' do it 'compares list of reservation with list of rooms' do - + Hotel::Reservation.reservations.room.wont_equal Hotel::Reservation.rooms_available end # end test it 'returns false if a room is already on the list of reservations for a given date' do diff --git a/support/rooms.csv b/support/rooms.csv new file mode 100644 index 000000000..0ff3bbb9c --- /dev/null +++ b/support/rooms.csv @@ -0,0 +1,20 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 From a6eb6b32c6f015e8f8cfdcb139a9b353e563d350 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Mon, 11 Sep 2017 00:43:08 -0700 Subject: [PATCH 28/43] self.all self.find spec pass --- lib/invalid_room_error.rb | 4 +++ lib/reservation.rb | 4 +-- lib/room.rb | 10 ++++++ specs/date_range_spec.rb | 12 ------- specs/reservation_spec.rb | 10 ++++-- specs/room_spec.rb | 73 ++++++++++++++------------------------- specs/spec_helper.rb | 1 + 7 files changed, 49 insertions(+), 65 deletions(-) create mode 100644 lib/invalid_room_error.rb diff --git a/lib/invalid_room_error.rb b/lib/invalid_room_error.rb new file mode 100644 index 000000000..e7f185165 --- /dev/null +++ b/lib/invalid_room_error.rb @@ -0,0 +1,4 @@ +module Hotel + class InvalidRoomError < StandardError + end +end diff --git a/lib/reservation.rb b/lib/reservation.rb index 7a79d3fa7..98b7dceda 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -26,7 +26,7 @@ def self.reservations def self.print_list bookings = [] @@reservations.each do |booking| - bookings << "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room}\nTotal Cost: $#{booking.cost}" # turns out you can't use instance variables within a class method + bookings << "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.room_number}\nTotal Cost: $#{booking.cost}" # turns out you can't use instance variables within a class method end return bookings end # end #self.print_list @@ -39,7 +39,7 @@ def self.on_date(date) # list reservations on a given date def self.available_rooms(date_range) # list reservations on given date range reservations_in_range = @@reservations.reject do |reservation| # excludes reservastions outside date range - reservation.check_out < date_range.check_in && reservation.check_in > date_range.check_out + reservation.check_out < date_range.check_in || reservation.check_in > date_range.check_out end rooms_in_range = reservations_in_range.map do |reservation| # iterates over reservations_in_range and converts each reservation into its room number (instead of list of obj, becomes list of int) diff --git a/lib/room.rb b/lib/room.rb index 9304d6c91..02712d117 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,5 +1,6 @@ require 'date' require 'csv' +require_relative 'invalid_room_error' module Hotel class Room @@ -17,5 +18,14 @@ def self.all end return all_rooms end # end #self.all + + def self.find(room_number) + self.all.each do |room| + if room_number == room.room_number + return room + end + end + raise InvalidRoomError.new ('Invalid Room Number') + end # end #self.find end # end Room class end # Hotel module diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index 0e9dd4c3d..61ebf0dd2 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -22,16 +22,4 @@ @puppy_dates.length_of_stay.must_equal 18 end # end test end # end #length_of_stay - - describe 'is_available?' do - xit 'checks if a room is available on given dates' do - - end # end test - end # end #is_available? - - describe 'reserve_room' do - xit 'reserves room if given dates are available' do - - end # end test - end # end #reserve_room end # end of all DateRange tests diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 352fb02b1..fe7e5eb55 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' -puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31), 13) -kitten_expo = Hotel::Reservation.new('Girlie', Date.new(2018, 1, 17), Date.new(2018, 1, 31), 11) +puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31), Hotel::Room.find(13)) +kitten_expo = Hotel::Reservation.new('Girlie', Date.new(2018, 1, 17), Date.new(2018, 1, 31), Hotel::Room.find(11)) describe 'Reservation' do describe 'initialize' do @@ -31,7 +31,11 @@ describe 'self.available_rooms' do it 'excludes reservations outside a given date range' do - + given_range = Hotel::DateRange.new(Date.new(2017, 01, 01), Date.new(2017, 12, 31)) + + Hotel::Reservation.available_rooms(given_range).map do |room| + room.room_number + end.wont_include 13 end # end test end # end #self.available_rooms end # end of all Reservation tests diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 23cf2322f..b6164b731 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1,66 +1,43 @@ require_relative 'spec_helper' -xdescribe 'Room' do - before do - @puppy_room = Hotel::Room.new - @kitten_room = Hotel::Room.new - @bat_room = Hotel::Room.new - end # end before - +describe 'Room' do describe 'initialize' do it 'creates an instance of Room' do - @puppy_room.class.must_equal Hotel::Room end # end test end # end #initialize - describe 'assign_room' do - it 'removes unavailable rooms from the rooms_available array each time a room is booked' do - Hotel::Room.rooms_available.length # 20 - @puppy_room.assign_room # -1 - @kitten_room.assign_room # -1 - Hotel::Room.rooms_available.length.must_equal 18 - end # end test - - it 'assigns a different room number as they are assigned and made unavailable' do - @puppy_room.assign_room # room 1 - @kitten_room.assign_room # room 2 - @bat_room.assign_room # room 3 - @bat_room.room_number.must_equal 3 - end # end test - end # end assign_room - - describe 'check_out_of_room' do - it 'returns the room number to the rooms_available array when a guest checks out' do - @puppy_room.assign_room # room 1 - @kitten_room.assign_room # room 2 - @puppy_room.check_out_of_room # return 1 to array - - Hotel::Room.rooms_available.must_include 1 + describe 'self.all' do + it "Returns an Array when Room.all is called" do + Hotel::Room.all.must_be_kind_of Array end # end test - it 'will sort the rooms_available array each time a room is assigned so the remaining rooms are in order (this will help when consecutive rooms need to be booked together)' do - @puppy_room.assign_room # room 1 - @kitten_room.assign_room # room 2 - @bat_room.assign_room # room 3 - @puppy_room.check_out_of_room # room 1 - @kitten_room.check_out_of_room # room 2 - @bat_room.check_out_of_room # room 3 - - Hotel::Room.rooms_available.must_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + it "Verifies the number of rooms is correct" do + total_rooms = CSV.read("support/rooms.csv", 'r').length + Hotel::Room.all.length.must_equal total_rooms end # end test - end # end #check_out_of_room - describe 'available?' do - it 'compares list of reservation with list of rooms' do - Hotel::Reservation.reservations.room.wont_equal Hotel::Reservation.rooms_available + it "Verifies everything in the Array is a Room" do + Hotel::Room.all.each do |room| + room.must_be_kind_of Hotel::Room + end end # end test - it 'returns false if a room is already on the list of reservations for a given date' do - + it "Matches the first and last room numbers with the CSV file" do + Hotel::Room.all.first.room_number.must_equal 1 + Hotel::Room.all.last.room_number.must_equal 20 end # end test + end # end #self.all - it 'returns true if a room is not on the list of reservations for a given date' do + describe 'self.find(room_number)' do + it "Can find the room 1 from the CSV" do + Hotel::Room.find(1).room_number.must_equal Hotel::Room.all.first.room_number + end + it "Can find the last order from the CSV" do + Hotel::Room.find(20).room_number.must_equal Hotel::Room.all.last.room_number + end + it 'raises an ArgumentError if room number does not exist' do + proc{Hotel::Room.find(666)}.must_raise Hotel::InvalidRoomError end # end test - end # end #available? + end # end #self.find(room_number) end # end all Room tests diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index ec45fa495..9b145b5fb 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -7,5 +7,6 @@ require_relative '../lib/reservation' require_relative '../lib/date_range' require_relative '../lib/room' +require_relative '../lib/invalid_room_error' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 0d1b5d37b2933a5328028275844993aa32b5c467 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Mon, 11 Sep 2017 01:09:36 -0700 Subject: [PATCH 29/43] cannot book already booked room --- lib/reservation.rb | 6 ++++++ specs/reservation_spec.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/reservation.rb b/lib/reservation.rb index 98b7dceda..abe451b81 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -16,6 +16,12 @@ def initialize(guest_name, check_in, check_out, room) @dates = Hotel::DateRange.new(check_in, check_out) @room = room @cost = (COST * @dates.length_of_stay).to_i + available_room_numbers = Hotel::Reservation.available_rooms(@dates).map do |room| + room.room_number + end + if !available_room_numbers.include?(@room.room_number) + raise InvalidRoomError.new('This room has already been booked') + end # tests if room has already been booked, raises error if so @@reservations << self # each new instance put into the list of total reservations end # end initialize diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index fe7e5eb55..0cf3dd7dc 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -9,6 +9,20 @@ puppy_expo.dates.check_in.to_s.must_equal '2017-10-13' puppy_expo.dates.check_out.to_s.must_equal '2017-10-31' end # end test + + it 'raises an InvalidRoomError if room has already been booked' do + proc{Hotel::Reservation.new('Suge', Date.new(2017, 10, 15), Date.new(2017, 10, 20), Hotel::Room.find(13))}.must_raise Hotel::InvalidRoomError + end # end test + + it 'will not add invalid reservation to @@reservations' do + number_of_reservations = Hotel::Reservation.reservations.length + begin + Hotel::Reservation.new('Suge', Date.new(2017, 10, 15), Date.new(2017, 10, 20), Hotel::Room.find(13)) + rescue + end + + Hotel::Reservation.reservations.length.must_equal number_of_reservations # makes sure number did not change! + end # end test end # end #initialize describe 'self.reservations' do From c12430cab0a06dfe127fec2fe36f49c644e2e1e9 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Thu, 28 Sep 2017 16:30:51 -0700 Subject: [PATCH 30/43] answer most of design activity questions --- design-activity.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 design-activity.md diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..7a60d66e8 --- /dev/null +++ b/design-activity.md @@ -0,0 +1,31 @@ +What classes does each implementation include? Are the lists the same? +A: CartEntry, ShoppingCart, Order +B: CartEntry, ShoppingCart, Order +(The same!) + +Write down a sentence to describe each class. +CartEntry: In both implementations, it collects the unit price and quantity. B will also find the price by multiplying the two arguments passed in. +ShoppingCart: Both create an array of items in the cart. In B, I _think_ it is trying to iterate through the entries array and add the price of each item in the cart to sum (it is unclear where entry.price is coming from, but I assume from CartEntry.price?) +Order: Each implementation finds the total price of the order, including tax. A does it by iterating through the entries array and adding each item with its own tax to a total price, whereas B adds tax to the final subtotal. + +How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. +CartEntry collects info of an item placed in the cart > ShoppingCart stores each entry into an array > Order calculates the total cost of items in the array, plus tax. + +What data does each class store? How (if at all) does this differ between the two implementations? +@unit_price, @quantity, @entries, @cart. They all seem the same to me--initialized the same and seem to hold the same information. + +What methods does each class have? How (if at all) does this differ between the two implementations? +Each class has an initialize method. Both Order classes have a total_price method. implementation B has an additional price method for its CartEntry and ShoppingCart classes. + +Consider the Order#total_price method. In each implementation: +Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order? + + +Does total_price directly manipulate the instance variables of other classes? +No + +If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? + +Which implementation better adheres to the single responsibility principle? + +Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? From b732072c49c39a9cd4194d5677ca541c985ae7a1 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 29 Sep 2017 15:33:03 -0700 Subject: [PATCH 31/43] move logic from reservation to daterange, add test to init in daterang --- design-activity.md | 2 +- lib/date_range.rb | 19 ++++++++++++++----- lib/reservation.rb | 12 +++++------- lib/room.rb | 6 +++--- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/design-activity.md b/design-activity.md index 7a60d66e8..e829135d0 100644 --- a/design-activity.md +++ b/design-activity.md @@ -17,7 +17,7 @@ What data does each class store? How (if at all) does this differ between the tw What methods does each class have? How (if at all) does this differ between the two implementations? Each class has an initialize method. Both Order classes have a total_price method. implementation B has an additional price method for its CartEntry and ShoppingCart classes. -Consider the Order#total_price method. In each implementation: +_Consider the Order#total_price method. In each implementation: Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order? diff --git a/lib/date_range.rb b/lib/date_range.rb index 1bcd26b7f..6c243300e 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -4,13 +4,22 @@ module Hotel class DateRange attr_reader :check_in, :check_out - def initialize(check_in, check_out) - @check_in = check_in - @check_out = check_out + def initialize(checkin, checkout) + unless checkout > checkin + raise InvalidDateRange.new("Invalid dates #{checkin} to #{checkout}") # I took this from the example--I wouldn't have thought to put this here and it is such a good idea + end + + @checkin = checkin + @checkout = checkout end # end initialize def length_of_stay - @check_out - @check_in - end # end date_range + return @check_out - @check_in + end # end length_of_stay + + def overlap?(other) + @checkout < other.checkin || @checkin > other.checkout + end # end overlap? + end # end of class end # end of module diff --git a/lib/reservation.rb b/lib/reservation.rb index abe451b81..9156b35ca 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -7,12 +7,10 @@ module Hotel class Reservation # various ways to list reservations COST = 200 # per night @@reservations = [] # list of all reservations made - attr_reader :guest_name, :check_in, :check_out, :dates, :room, :cost, :list + attr_reader :guest_name, :dates, :room, :cost, :list def initialize(guest_name, check_in, check_out, room) @guest_name = guest_name - @check_in = check_in - @check_out = check_out @dates = Hotel::DateRange.new(check_in, check_out) @room = room @cost = (COST * @dates.length_of_stay).to_i @@ -35,17 +33,17 @@ def self.print_list bookings << "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.room_number}\nTotal Cost: $#{booking.cost}" # turns out you can't use instance variables within a class method end return bookings - end # end #self.print_list + end # end self.print_list def self.on_date(date) # list reservations on a given date @@reservations.select do |reservation| reservation.check_in == date end - end # end #self.on_date + end # end self.on_date def self.available_rooms(date_range) # list reservations on given date range reservations_in_range = @@reservations.reject do |reservation| # excludes reservastions outside date range - reservation.check_out < date_range.check_in || reservation.check_in > date_range.check_out + reservation.dates.overlap?(date_range) end rooms_in_range = reservations_in_range.map do |reservation| # iterates over reservations_in_range and converts each reservation into its room number (instead of list of obj, becomes list of int) @@ -55,6 +53,6 @@ def self.available_rooms(date_range) # list reservations on given date range return Hotel::Room.all.reject do |room| # remove from list of rooms without reservations in date range rooms_in_range.include?(room.room_number) end - end # end #self.available_rooms + end # end self.available_rooms end # end of Reservation end # end of Hotel module diff --git a/lib/room.rb b/lib/room.rb index 02712d117..3e875be9e 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -8,7 +8,7 @@ class Room def initialize(room_number) @room_number = room_number - end # end #initialize + end # end initialize def self.all all_rooms = [] @@ -17,7 +17,7 @@ def self.all all_rooms << self.new(room_number) end return all_rooms - end # end #self.all + end # end self.all def self.find(room_number) self.all.each do |room| @@ -26,6 +26,6 @@ def self.find(room_number) end end raise InvalidRoomError.new ('Invalid Room Number') - end # end #self.find + end # end self.find end # end Room class end # Hotel module From bf25ae6bf3a134aa992bc37de067e4cfdc0f362c Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 29 Sep 2017 15:39:30 -0700 Subject: [PATCH 32/43] add custom errors to daterange and room classes --- lib/date_range.rb | 3 ++- lib/invalid_room_error.rb | 4 ---- lib/room.rb | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) delete mode 100644 lib/invalid_room_error.rb diff --git a/lib/date_range.rb b/lib/date_range.rb index 6c243300e..a8c40c51e 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -2,6 +2,7 @@ module Hotel class DateRange + class InvalidDateRange < StandardError ; end attr_reader :check_in, :check_out def initialize(checkin, checkout) @@ -20,6 +21,6 @@ def length_of_stay def overlap?(other) @checkout < other.checkin || @checkin > other.checkout end # end overlap? - + end # end of class end # end of module diff --git a/lib/invalid_room_error.rb b/lib/invalid_room_error.rb deleted file mode 100644 index e7f185165..000000000 --- a/lib/invalid_room_error.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Hotel - class InvalidRoomError < StandardError - end -end diff --git a/lib/room.rb b/lib/room.rb index 3e875be9e..872c08865 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,9 +1,9 @@ require 'date' require 'csv' -require_relative 'invalid_room_error' module Hotel class Room + class InvalidRoomNumber < StandardError ; end attr_reader :room_number, :rooms_available def initialize(room_number) @@ -25,7 +25,7 @@ def self.find(room_number) return room end end - raise InvalidRoomError.new ('Invalid Room Number') + raise InvalidRoomNumber.new ('Invalid Room Number') end # end self.find end # end Room class end # Hotel module From 55a62ee87a233aaaf2f90beba56673c77ba9e9db Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Fri, 29 Sep 2017 15:43:41 -0700 Subject: [PATCH 33/43] update spec_helper, add hotel class --- lib/date_range.rb | 2 +- lib/hotel.rb | 7 +++++++ lib/reservation.rb | 5 +---- lib/room.rb | 3 +-- specs/spec_helper.rb | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 lib/hotel.rb diff --git a/lib/date_range.rb b/lib/date_range.rb index a8c40c51e..ec8d3dc05 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -1,4 +1,4 @@ -require 'date' +require 'spec_helper' module Hotel class DateRange diff --git a/lib/hotel.rb b/lib/hotel.rb new file mode 100644 index 000000000..ecd6661b2 --- /dev/null +++ b/lib/hotel.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +module Hotel + class Hotel + + end # end class +end # end module diff --git a/lib/reservation.rb b/lib/reservation.rb index 9156b35ca..389da33b1 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,7 +1,4 @@ - -require 'date' -require_relative 'date_range' -require_relative 'room' +require 'spec_helper' module Hotel class Reservation # various ways to list reservations diff --git a/lib/room.rb b/lib/room.rb index 872c08865..1c5d5e1ab 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,5 +1,4 @@ -require 'date' -require 'csv' +require 'spec_helper' module Hotel class Room diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 9b145b5fb..66963f852 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -4,9 +4,9 @@ require 'minitest/autorun' require 'minitest/reporters' require 'minitest/skip_dsl' -require_relative '../lib/reservation' +require_relative '../lib/hotel' require_relative '../lib/date_range' +require_relative '../lib/reservation' require_relative '../lib/room' -require_relative '../lib/invalid_room_error' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 7a3dfc4c16f270546fe42ac4b88359d47ec63ad8 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 16:47:00 -0700 Subject: [PATCH 34/43] answer activity question --- design-activity.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/design-activity.md b/design-activity.md index e829135d0..a81245ee1 100644 --- a/design-activity.md +++ b/design-activity.md @@ -28,4 +28,7 @@ If we decide items are cheaper if bought in bulk, how would this change the code Which implementation better adheres to the single responsibility principle? -Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? +Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?_ + +Identify one place in your Hotel project where a class takes on multiple roles, or directly modifies the attributes of another class. +My Reservation class should only be responsible for a single reservation. Instead of Reservation creating AND storing every instance, I should have a Hotel class to store all reservations in. That would make it much easier to create a Blocks class, which I was unable to do when the project was originally assigned. From 13922bf7ed5e41a2075b83e7df34fd98e7500bba Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 16:57:35 -0700 Subject: [PATCH 35/43] methods number_of_nights, total_cost --- lib/date_range.rb | 16 ++++---- lib/reservation.rb | 91 ++++++++++++++++++++++++---------------------- 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index ec8d3dc05..96135341f 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -5,21 +5,21 @@ class DateRange class InvalidDateRange < StandardError ; end attr_reader :check_in, :check_out - def initialize(checkin, checkout) - unless checkout > checkin - raise InvalidDateRange.new("Invalid dates #{checkin} to #{checkout}") # I took this from the example--I wouldn't have thought to put this here and it is such a good idea + def initialize(check_in, check_out) + unless check_out > check_in + raise InvalidDateRange.new("Invalid dates #{check_in} to #{check_out}") # I took this from the example--I wouldn't have thought to put this here and it is such a good idea end - @checkin = checkin - @checkout = checkout + @check_in = check_in + @check_out = check_out end # end initialize - def length_of_stay + def number_of_nights return @check_out - @check_in - end # end length_of_stay + end # end number_of_nights def overlap?(other) - @checkout < other.checkin || @checkin > other.checkout + @check_out < other.check_in || @check_in > other.check_out end # end overlap? end # end of class diff --git a/lib/reservation.rb b/lib/reservation.rb index 389da33b1..bdd8c7162 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,54 +2,57 @@ module Hotel class Reservation # various ways to list reservations - COST = 200 # per night - @@reservations = [] # list of all reservations made - attr_reader :guest_name, :dates, :room, :cost, :list + # COST = 200 # per night + # @@reservations = [] # list of all reservations made + attr_reader :dates :room, :rate - def initialize(guest_name, check_in, check_out, room) - @guest_name = guest_name + def initialize(dates, room, rate) @dates = Hotel::DateRange.new(check_in, check_out) @room = room - @cost = (COST * @dates.length_of_stay).to_i - available_room_numbers = Hotel::Reservation.available_rooms(@dates).map do |room| - room.room_number - end - if !available_room_numbers.include?(@room.room_number) - raise InvalidRoomError.new('This room has already been booked') - end # tests if room has already been booked, raises error if so - @@reservations << self # each new instance put into the list of total reservations + @rate = 200 + # available_room_numbers = Hotel::Reservation.available_rooms(@dates).map do |room| + # room.room_number + # end + # if !available_room_numbers.include?(@room.room_number) + # raise InvalidRoomError.new('This room has already been booked') + # end # tests if room has already been booked, raises error if so + # @@reservations << self # each new instance put into the list of total reservations end # end initialize - def self.reservations - @@reservations - end # end self.reservations - - def self.print_list - bookings = [] - @@reservations.each do |booking| - bookings << "Name: #{booking.guest_name}\nCheck In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.room_number}\nTotal Cost: $#{booking.cost}" # turns out you can't use instance variables within a class method - end - return bookings - end # end self.print_list - - def self.on_date(date) # list reservations on a given date - @@reservations.select do |reservation| - reservation.check_in == date - end - end # end self.on_date - - def self.available_rooms(date_range) # list reservations on given date range - reservations_in_range = @@reservations.reject do |reservation| # excludes reservastions outside date range - reservation.dates.overlap?(date_range) - end - - rooms_in_range = reservations_in_range.map do |reservation| # iterates over reservations_in_range and converts each reservation into its room number (instead of list of obj, becomes list of int) - reservation.room.room_number - end - - return Hotel::Room.all.reject do |room| # remove from list of rooms without reservations in date range - rooms_in_range.include?(room.room_number) - end - end # end self.available_rooms + def final_cost + return @rate * @dates.number_of_nights + end + + # def self.reservations + # @@reservations + # end # end self.reservations + + # def self.print_list + # bookings = [] + # @@reservations.each do |booking| + # bookings << "Check In: #{booking.check_in}\nCheck Out: #{booking.check_out}\nRoom Number: #{booking.room.room_number}\nTotal Cost: $#{booking.cost}" # turns out you can't use instance variables within a class method + # end + # return bookings + # end # end self.print_list + + # def self.on_date(date) # list reservations on a given date + # @@reservations.select do |reservation| + # reservation.check_in == date + # end + # end # end self.on_date + # + # def self.available_rooms(date_range) # list reservations on given date range + # reservations_in_range = @@reservations.reject do |reservation| # excludes reservastions outside date range + # reservation.dates.overlap?(date_range) + # end + # + # rooms_in_range = reservations_in_range.map do |reservation| # iterates over reservations_in_range and converts each reservation into its room number (instead of list of obj, becomes list of int) + # reservation.room.room_number + # end + # + # return Hotel::Room.all.reject do |room| # remove from list of rooms without reservations in date range + # rooms_in_range.include?(room.room_number) + # end + # end # end self.available_rooms end # end of Reservation end # end of Hotel module From 0170e45d503afb87b06fe20bc18e58799962080f Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 17:04:28 -0700 Subject: [PATCH 36/43] comment out all of room.rb --- lib/date_range.rb | 1 - lib/reservation.rb | 2 +- lib/room.rb | 62 +++++++++++++++++++++++--------------------- specs/spec_helper.rb | 2 +- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 96135341f..e227f3eb0 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -21,6 +21,5 @@ def number_of_nights def overlap?(other) @check_out < other.check_in || @check_in > other.check_out end # end overlap? - end # end of class end # end of module diff --git a/lib/reservation.rb b/lib/reservation.rb index bdd8c7162..4f18069ad 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -21,7 +21,7 @@ def initialize(dates, room, rate) def final_cost return @rate * @dates.number_of_nights - end + end # end final_cost # def self.reservations # @@reservations diff --git a/lib/room.rb b/lib/room.rb index 1c5d5e1ab..7f4c8573c 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,30 +1,34 @@ -require 'spec_helper' +# require 'spec_helper' +# +# module Hotel +# class Room +# class InvalidRoomNumber < StandardError ; end +# attr_reader :room_number, :rooms_available +# +# def initialize(room_number) +# @room_number = room_number +# end # end initialize +# +# def self.all +# all_rooms = [] +# CSV.open("support/rooms.csv", 'r').each do |line| +# room_number = line[0].to_i +# all_rooms << self.new(room_number) +# end +# return all_rooms +# end # end self.all +# +# def self.find(room_number) +# self.all.each do |room| +# if room_number == room.room_number +# return room +# end +# end +# raise InvalidRoomNumber.new ('Invalid Room Number') +# end # end self.find +# end # end Room class +# end # Hotel module -module Hotel - class Room - class InvalidRoomNumber < StandardError ; end - attr_reader :room_number, :rooms_available - - def initialize(room_number) - @room_number = room_number - end # end initialize - - def self.all - all_rooms = [] - CSV.open("support/rooms.csv", 'r').each do |line| - room_number = line[0].to_i - all_rooms << self.new(room_number) - end - return all_rooms - end # end self.all - - def self.find(room_number) - self.all.each do |room| - if room_number == room.room_number - return room - end - end - raise InvalidRoomNumber.new ('Invalid Room Number') - end # end self.find - end # end Room class -end # Hotel module +################################# +# decided I don't need this class +################################# diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 66963f852..7b67033f7 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -7,6 +7,6 @@ require_relative '../lib/hotel' require_relative '../lib/date_range' require_relative '../lib/reservation' -require_relative '../lib/room' +# require_relative '../lib/room' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From bf1daaa7ba5dcf93e2c6bfe9a99c1860fdfd02db Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 17:57:34 -0700 Subject: [PATCH 37/43] create and pass tests for reservation_spec --- lib/date_range.rb | 3 +- lib/hotel.rb | 6 +- lib/reservation.rb | 9 ++- specs/reservation_spec.rb | 134 ++++++++++++++++++++++++-------------- specs/room_spec.rb | 2 +- 5 files changed, 95 insertions(+), 59 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index e227f3eb0..528f47765 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -1,5 +1,4 @@ -require 'spec_helper' - +require_relative 'reservation' module Hotel class DateRange class InvalidDateRange < StandardError ; end diff --git a/lib/hotel.rb b/lib/hotel.rb index ecd6661b2..34f57ec9c 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,7 +1,11 @@ -require 'spec_helper' module Hotel class Hotel + attr_reader :reservations, :rooms + def initialize + @reservations = [] + @rooms = (1..20).to_a + end # initialize end # end class end # end module diff --git a/lib/reservation.rb b/lib/reservation.rb index 4f18069ad..2cc73063a 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,13 +1,12 @@ -require 'spec_helper' - +require_relative 'date_range' module Hotel class Reservation # various ways to list reservations # COST = 200 # per night # @@reservations = [] # list of all reservations made - attr_reader :dates :room, :rate + attr_reader :dates, :room, :rate def initialize(dates, room, rate) - @dates = Hotel::DateRange.new(check_in, check_out) + @dates = dates @room = room @rate = 200 # available_room_numbers = Hotel::Reservation.available_rooms(@dates).map do |room| @@ -20,7 +19,7 @@ def initialize(dates, room, rate) end # end initialize def final_cost - return @rate * @dates.number_of_nights + return @rate * @dates.number_of_nights.to_i end # end final_cost # def self.reservations diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 0cf3dd7dc..14bd63cff 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1,55 +1,89 @@ require_relative 'spec_helper' -puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31), Hotel::Room.find(13)) -kitten_expo = Hotel::Reservation.new('Girlie', Date.new(2018, 1, 17), Date.new(2018, 1, 31), Hotel::Room.find(11)) +# puppy_expo = Hotel::Reservation.new('Finn', Date.new(2017, 10, 13), Date.new(2017, 10, 31), Hotel::Room.find(13)) +# kitten_expo = Hotel::Reservation.new('Girlie', Date.new(2018, 1, 17), Date.new(2018, 1, 31), Hotel::Room.find(11)) describe 'Reservation' do describe 'initialize' do - it 'initializes with guest name, date range from DateRange, and room number from Room' do - puppy_expo.guest_name.must_equal 'Finn' - puppy_expo.dates.check_in.to_s.must_equal '2017-10-13' - puppy_expo.dates.check_out.to_s.must_equal '2017-10-31' - end # end test - - it 'raises an InvalidRoomError if room has already been booked' do - proc{Hotel::Reservation.new('Suge', Date.new(2017, 10, 15), Date.new(2017, 10, 20), Hotel::Room.find(13))}.must_raise Hotel::InvalidRoomError - end # end test - - it 'will not add invalid reservation to @@reservations' do - number_of_reservations = Hotel::Reservation.reservations.length - begin - Hotel::Reservation.new('Suge', Date.new(2017, 10, 15), Date.new(2017, 10, 20), Hotel::Room.find(13)) - rescue - end - - Hotel::Reservation.reservations.length.must_equal number_of_reservations # makes sure number did not change! - end # end test - end # end #initialize - - describe 'self.reservations' do - it 'calls the class variable @@reservations, which holds all instances of Reservation in an array' do - Hotel::Reservation.reservations.must_equal [puppy_expo, kitten_expo] - end # end test - end # end #self.reservations - - describe 'self.print_list' do - it 'returns list of all reservations' do - Hotel::Reservation.print_list.must_equal ["Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 13\nTotal Cost: $3600", "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 11\nTotal Cost: $2800"] - end # end test - end # end #self.print_list - - describe 'self.on_date' do - it 'returns a list of reservations for a specific date' do - Hotel::Reservation.on_date(Date.new(2018, 1, 17)).must_equal [kitten_expo] - end # end test - end # end #self.on_date - - describe 'self.available_rooms' do - it 'excludes reservations outside a given date range' do - given_range = Hotel::DateRange.new(Date.new(2017, 01, 01), Date.new(2017, 12, 31)) - - Hotel::Reservation.available_rooms(given_range).map do |room| - room.room_number - end.wont_include 13 - end # end test - end # end #self.available_rooms + it 'creates a room instance with the dates, room, and rate' do + dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) + honeymoon = Hotel::Reservation.new(dates, 13, 200) + + honeymoon.dates.check_in.must_equal Date.new(2017, 10, 13) + honeymoon.dates.check_out.must_equal Date.new(2017, 10, 31) + honeymoon.room.must_equal 13 + honeymoon.rate.must_equal 200 + end + + it 'passes in a DateRange object as the dates argument' do + dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) + honeymoon = Hotel::Reservation.new(dates, 13, 200) + + honeymoon.dates.must_be_kind_of Hotel::DateRange + end + + it 'will not pass in anything but a DateRange object as the dates argument' do + dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) + honeymoon = Hotel::Reservation.new(dates, 13, 200) + + honeymoon.dates.wont_be_kind_of Date + end + end + + describe 'final_cost' do + it 'calculates the cost of the stay based on number of nights times the rate' do + dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) + honeymoon = Hotel::Reservation.new(dates, 13, 200) + + honeymoon.final_cost.must_equal 3600 + end + end + # describe 'initialize' do + # it 'initializes with guest name, date range from DateRange, and room number from Room' do + # puppy_expo.guest_name.must_equal 'Finn' + # puppy_expo.dates.check_in.to_s.must_equal '2017-10-13' + # puppy_expo.dates.check_out.to_s.must_equal '2017-10-31' + # end # end test + # + # it 'raises an InvalidRoomError if room has already been booked' do + # proc{Hotel::Reservation.new('Suge', Date.new(2017, 10, 15), Date.new(2017, 10, 20), Hotel::Room.find(13))}.must_raise Hotel::InvalidRoomError + # end # end test + # + # it 'will not add invalid reservation to @@reservations' do + # number_of_reservations = Hotel::Reservation.reservations.length + # begin + # Hotel::Reservation.new('Suge', Date.new(2017, 10, 15), Date.new(2017, 10, 20), Hotel::Room.find(13)) + # rescue + # end + # + # Hotel::Reservation.reservations.length.must_equal number_of_reservations # makes sure number did not change! + # end # end test + # end # end #initialize + # + # describe 'self.reservations' do + # it 'calls the class variable @@reservations, which holds all instances of Reservation in an array' do + # Hotel::Reservation.reservations.must_equal [puppy_expo, kitten_expo] + # end # end test + # end # end #self.reservations + # + # describe 'self.print_list' do + # it 'returns list of all reservations' do + # Hotel::Reservation.print_list.must_equal ["Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 13\nTotal Cost: $3600", "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 11\nTotal Cost: $2800"] + # end # end test + # end # end #self.print_list + # + # describe 'self.on_date' do + # it 'returns a list of reservations for a specific date' do + # Hotel::Reservation.on_date(Date.new(2018, 1, 17)).must_equal [kitten_expo] + # end # end test + # end # end #self.on_date + # + # describe 'self.available_rooms' do + # it 'excludes reservations outside a given date range' do + # given_range = Hotel::DateRange.new(Date.new(2017, 01, 01), Date.new(2017, 12, 31)) + # + # Hotel::Reservation.available_rooms(given_range).map do |room| + # room.room_number + # end.wont_include 13 + # end # end test + # end # end #self.available_rooms end # end of all Reservation tests diff --git a/specs/room_spec.rb b/specs/room_spec.rb index b6164b731..76227f469 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1,4 +1,4 @@ -require_relative 'spec_helper' +require_relative '../specs/spec_helper' describe 'Room' do describe 'initialize' do From 31f6a4c295c03c805972b1930fa383ec6287bebc Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 18:13:27 -0700 Subject: [PATCH 38/43] date_range_spec initialize tests pass --- specs/date_range_spec.rb | 64 ++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index 61ebf0dd2..225e52909 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -1,25 +1,51 @@ require_relative 'spec_helper' describe 'DateRange' do - before do - @puppy_dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) - end # end before describe 'initialize' do - it 'takes a check in date and a check out date' do - @puppy_dates.check_in.to_s.must_equal '2017-10-13' - @puppy_dates.check_out.to_s.must_equal '2017-10-31' - end # end test - - it 'passes check_in and check_out in as Date objects' do - @puppy_dates.check_in.class.must_equal Date - @puppy_dates.check_out.class.must_equal Date - end # end test - end # end #initialize - - describe 'length_of_stay' do - it 'finds the number of days needed for the reservation based on given dates' do - @puppy_dates.length_of_stay.must_equal 18 - end # end test - end # end #length_of_stay + it 'passes in two Date objects as check in and check out arguments' do + check_in = Date.new(2017, 10, 13) + check_out = Date.new(2017, 10, 31) + honeymoon = Hotel::DateRange.new(check_in, check_out) + + honeymoon.check_in.must_be_kind_of Date + honeymoon.check_out.must_be_kind_of Date + end + + it 'cannot have a negative number of nights' do + check_out = Date.new(2017, 10, 13) + check_in = Date.new(2017, 10, 31) + + proc { Hotel::DateRange.new(check_in, check_out) }.must_raise Hotel::DateRange::InvalidDateRange + end + + it 'cannot book zero nights' do + check_out = Date.new(2017, 10, 13) + check_in = Date.new(2017, 10, 13) + + proc { Hotel::DateRange.new(check_in, check_out) }.must_raise Hotel::DateRange::InvalidDateRange + end + end + + # before do + # @puppy_dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) + # end # end before + # + # describe 'initialize' do + # it 'takes a check in date and a check out date' do + # @puppy_dates.check_in.to_s.must_equal '2017-10-13' + # @puppy_dates.check_out.to_s.must_equal '2017-10-31' + # end # end test + # + # it 'passes check_in and check_out in as Date objects' do + # @puppy_dates.check_in.class.must_equal Date + # @puppy_dates.check_out.class.must_equal Date + # end # end test + # end # end #initialize + # + # describe 'length_of_stay' do + # it 'finds the number of days needed for the reservation based on given dates' do + # @puppy_dates.length_of_stay.must_equal 18 + # end # end test + # end # end #length_of_stay end # end of all DateRange tests From 47eaf1d431c4ddbbd222b889d275e2d0625cf16c Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 20:55:38 -0700 Subject: [PATCH 39/43] move extraneous methods from reservation to hotel --- lib/hotel.rb | 36 ++++++++++++++++ lib/reservation.rb | 6 ++- lib/room.rb | 8 ++-- specs/date_range_spec.rb | 14 +++++++ specs/reservation_spec.rb | 6 ++- specs/room_spec.rb | 87 +++++++++++++++++++++------------------ 6 files changed, 109 insertions(+), 48 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 34f57ec9c..1769b491f 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -7,5 +7,41 @@ def initialize @reservations = [] @rooms = (1..20).to_a end # initialize + + def available_rooms(date_range) + reservations = @reservations.reject do |reservation| # removes rooms already booked + reservation.dates.overlap?(date_range) + end + reserved_rooms = reservations.map do |reservation| # converts each reservation in reservations into its room number + reservation.room + end + return @rooms.reject do |room| # returns the available room numbers by removing reserved rooms from the @rooms list + reserved_rooms.include?(room) + end + end # end available_rooms + + def add_reservation(reservation) + available = available_rooms(reservation.dates) + if !available.include?(reservation.room) + raise InvalidRoomError.new('This room has already been booked') # tests if room has already been booked + else + @reservations << reservation + end + end # end add_reservation + + def all_reservations + return @reservations.map do |reservation| + return reservation.pretty_print + end + end # end all_reservations + + def list_on_date(date) + reservations = @reservations.select do |reservation| + reservation.dates.check_in == date + end + return reservations.map do |reservation| + return reservation.pretty_print + end + end # end on_date end # end class end # end module diff --git a/lib/reservation.rb b/lib/reservation.rb index 2cc73063a..6986248ed 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -10,7 +10,7 @@ def initialize(dates, room, rate) @room = room @rate = 200 # available_room_numbers = Hotel::Reservation.available_rooms(@dates).map do |room| - # room.room_number + # room.room_number # end # if !available_room_numbers.include?(@room.room_number) # raise InvalidRoomError.new('This room has already been booked') @@ -22,6 +22,10 @@ def final_cost return @rate * @dates.number_of_nights.to_i end # end final_cost + def pretty_print + return "Check In: #{@dates.check_in}\nCheck Out: #{@dates.check_out}\nRoom Number: #{@room}\nTotal Cost: $#{final_cost}" + end + # def self.reservations # @@reservations # end # end self.reservations diff --git a/lib/room.rb b/lib/room.rb index 7f4c8573c..5a30de660 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,3 +1,7 @@ +################################# +# decided I don't need this class +################################# + # require 'spec_helper' # # module Hotel @@ -28,7 +32,3 @@ # end # end self.find # end # end Room class # end # Hotel module - -################################# -# decided I don't need this class -################################# diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index 225e52909..b16977ce6 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -25,6 +25,20 @@ proc { Hotel::DateRange.new(check_in, check_out) }.must_raise Hotel::DateRange::InvalidDateRange end + end # end initialize + + describe 'number_of_nights' do + it 'returns the number of nights passed in' do + check_in = Date.new(2017, 10, 13) + check_out = Date.new(2017, 10, 31) + honeymoon = Hotel::DateRange.new(check_in, check_out) + + honeymoon.number_of_nights.must_equal 18 + end + end # end number_of_nights + + describe 'overlap?' do + it '' end # before do diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 14bd63cff..d0f3792f7 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -27,7 +27,7 @@ honeymoon.dates.wont_be_kind_of Date end - end + end # end initialize describe 'final_cost' do it 'calculates the cost of the stay based on number of nights times the rate' do @@ -36,7 +36,9 @@ honeymoon.final_cost.must_equal 3600 end - end + end # end final_cost + + # describe 'initialize' do # it 'initializes with guest name, date range from DateRange, and room number from Room' do # puppy_expo.guest_name.must_equal 'Finn' diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 76227f469..ce21a095a 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1,43 +1,48 @@ -require_relative '../specs/spec_helper' +################################# +# decided I don't need this class +################################# -describe 'Room' do - describe 'initialize' do - it 'creates an instance of Room' do - end # end test - end # end #initialize - describe 'self.all' do - it "Returns an Array when Room.all is called" do - Hotel::Room.all.must_be_kind_of Array - end # end test - - it "Verifies the number of rooms is correct" do - total_rooms = CSV.read("support/rooms.csv", 'r').length - Hotel::Room.all.length.must_equal total_rooms - end # end test - - it "Verifies everything in the Array is a Room" do - Hotel::Room.all.each do |room| - room.must_be_kind_of Hotel::Room - end - end # end test - - it "Matches the first and last room numbers with the CSV file" do - Hotel::Room.all.first.room_number.must_equal 1 - Hotel::Room.all.last.room_number.must_equal 20 - end # end test - end # end #self.all - - describe 'self.find(room_number)' do - it "Can find the room 1 from the CSV" do - Hotel::Room.find(1).room_number.must_equal Hotel::Room.all.first.room_number - end - - it "Can find the last order from the CSV" do - Hotel::Room.find(20).room_number.must_equal Hotel::Room.all.last.room_number - end - it 'raises an ArgumentError if room number does not exist' do - proc{Hotel::Room.find(666)}.must_raise Hotel::InvalidRoomError - end # end test - end # end #self.find(room_number) -end # end all Room tests +# require_relative '../specs/spec_helper' +# +# describe 'Room' do +# describe 'initialize' do +# it 'creates an instance of Room' do +# end # end test +# end # end #initialize +# +# describe 'self.all' do +# it "Returns an Array when Room.all is called" do +# Hotel::Room.all.must_be_kind_of Array +# end # end test +# +# it "Verifies the number of rooms is correct" do +# total_rooms = CSV.read("support/rooms.csv", 'r').length +# Hotel::Room.all.length.must_equal total_rooms +# end # end test +# +# it "Verifies everything in the Array is a Room" do +# Hotel::Room.all.each do |room| +# room.must_be_kind_of Hotel::Room +# end +# end # end test +# +# it "Matches the first and last room numbers with the CSV file" do +# Hotel::Room.all.first.room_number.must_equal 1 +# Hotel::Room.all.last.room_number.must_equal 20 +# end # end test +# end # end #self.all +# +# describe 'self.find(room_number)' do +# it "Can find the room 1 from the CSV" do +# Hotel::Room.find(1).room_number.must_equal Hotel::Room.all.first.room_number +# end +# +# it "Can find the last order from the CSV" do +# Hotel::Room.find(20).room_number.must_equal Hotel::Room.all.last.room_number +# end +# it 'raises an ArgumentError if room number does not exist' do +# proc{Hotel::Room.find(666)}.must_raise Hotel::InvalidRoomError +# end # end test +# end # end #self.find(room_number) +# end # end all Room tests From 69f5f63fc1dd2c80ec013fefd5a44ddce588d99c Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 21:12:37 -0700 Subject: [PATCH 40/43] pretty_print, list reservations, list by date, list all date_range_spec tests for overlap --- lib/date_range.rb | 2 +- specs/date_range_spec.rb | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 528f47765..9266e429c 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -18,7 +18,7 @@ def number_of_nights end # end number_of_nights def overlap?(other) - @check_out < other.check_in || @check_in > other.check_out + !(@check_out < other.check_in || @check_in > other.check_out) end # end overlap? end # end of class end # end of module diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index b16977ce6..fcc6a14c6 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -38,7 +38,41 @@ end # end number_of_nights describe 'overlap?' do - it '' + it 'returns true if the check in dates are the same' do + + end + + it 'returns true if the reservation starts before the other ends' do + + end + + it 'returns true if the reservation ends after the other starts' do + + end + + it 'returns true if the new date range is contained in the other date range' do + + end + + it 'returns true if the new date range contains the other date range' do + + end + + it 'returns false if the reservation ends before the other starts' do + + end + + it 'returns false if the reservation begins after the other ends' do + + end + + it 'returns false if the reservation begins on the other check out date' do + + end + + it 'returns false if the reservation ends on the other check in date' do + + end end # before do From 90976dc0f6779f8071e8136cd14d99d45c35554c Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 21:29:28 -0700 Subject: [PATCH 41/43] pass the 'true' overlap tests in date_range_spec --- specs/date_range_spec.rb | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index fcc6a14c6..1446bf29c 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -38,24 +38,47 @@ end # end number_of_nights describe 'overlap?' do - it 'returns true if the check in dates are the same' do + before do + @check_in = Date.new(2017, 10, 13) + @check_out = Date.new(2017, 10, 31) + @honeymoon = Hotel::DateRange.new(@check_in, @check_out) + end + it 'returns true if the check in dates are the same' do + birthday = Hotel::DateRange.new(@check_in, @check_out) + @honeymoon.overlap?(birthday).must_equal true end it 'returns true if the reservation starts before the other ends' do + check_in = Date.new(2017, 10, 10) + check_out = Date.new(2017, 10, 15) + birthday = Hotel::DateRange.new(check_in, check_out) + @honeymoon.overlap?(birthday).must_equal true end it 'returns true if the reservation ends after the other starts' do + check_in = Date.new(2017, 10, 30) + check_out = Date.new(2017, 11, 1) + birthday = Hotel::DateRange.new(check_in, check_out) + @honeymoon.overlap?(birthday).must_equal true end it 'returns true if the new date range is contained in the other date range' do + check_in = Date.new(2017, 10, 15) + check_out = Date.new(2017, 10, 16) + birthday = Hotel::DateRange.new(check_in, check_out) + @honeymoon.overlap?(birthday).must_equal true end it 'returns true if the new date range contains the other date range' do + check_in = Date.new(2017, 10, 1) + check_out = Date.new(2017, 11, 1) + birthday = Hotel::DateRange.new(check_in, check_out) + @honeymoon.overlap?(birthday).must_equal true end it 'returns false if the reservation ends before the other starts' do @@ -71,7 +94,7 @@ end it 'returns false if the reservation ends on the other check in date' do - + end end From 7103fa4847905baa4f664f5d170e8e277d399b61 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 21:34:15 -0700 Subject: [PATCH 42/43] pass date_range_spec overlap tests --- lib/date_range.rb | 2 +- specs/date_range_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 9266e429c..2c484a71e 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -18,7 +18,7 @@ def number_of_nights end # end number_of_nights def overlap?(other) - !(@check_out < other.check_in || @check_in > other.check_out) + !(@check_out <= other.check_in || @check_in >= other.check_out) end # end overlap? end # end of class end # end of module diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index 1446bf29c..7184516d0 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -82,19 +82,35 @@ end it 'returns false if the reservation ends before the other starts' do + check_in = Date.new(2017, 10, 1) + check_out = Date.new(2017, 10, 12) + birthday = Hotel::DateRange.new(check_in, check_out) + @honeymoon.overlap?(birthday).must_equal false end it 'returns false if the reservation begins after the other ends' do + check_in = Date.new(2017, 11, 1) + check_out = Date.new(2017, 11, 2) + birthday = Hotel::DateRange.new(check_in, check_out) + @honeymoon.overlap?(birthday).must_equal false end it 'returns false if the reservation begins on the other check out date' do + check_in = Date.new(2017, 10, 1) + check_out = Date.new(2017, 10, 13) + birthday = Hotel::DateRange.new(check_in, check_out) + @honeymoon.overlap?(birthday).must_equal false end it 'returns false if the reservation ends on the other check in date' do + check_in = Date.new(2017, 10, 31) + check_out = Date.new(2017, 11, 1) + birthday = Hotel::DateRange.new(check_in, check_out) + @honeymoon.overlap?(birthday).must_equal false end end From 8b0b45287d1b3e9a01890c0dc3dd6de77d0c6f53 Mon Sep 17 00:00:00 2001 From: Sara Frandsen Date: Sun, 1 Oct 2017 23:47:51 -0700 Subject: [PATCH 43/43] finish all tests and questions --- design-activity.md | 10 +-- lib/date_range.rb | 1 - lib/hotel.rb | 15 +++-- specs/date_range_spec.rb | 2 +- specs/hotel_spec.rb | 137 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 151 insertions(+), 14 deletions(-) create mode 100644 specs/hotel_spec.rb diff --git a/design-activity.md b/design-activity.md index a81245ee1..9a1d1b2f8 100644 --- a/design-activity.md +++ b/design-activity.md @@ -17,18 +17,18 @@ What data does each class store? How (if at all) does this differ between the tw What methods does each class have? How (if at all) does this differ between the two implementations? Each class has an initialize method. Both Order classes have a total_price method. implementation B has an additional price method for its CartEntry and ShoppingCart classes. -_Consider the Order#total_price method. In each implementation: +Consider the Order#total_price method. In each implementation: Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order? - +implementation A does not--it retains all logic in itself, and only uses values from other classes. B does, using ShoppingCart#price. Does total_price directly manipulate the instance variables of other classes? -No +No. They both use the values in local variables. If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? +I feel like A would be easier to modify because it calculates the price only once, and it would be simpler to make changes in one class than the several classes it would be in B. Which implementation better adheres to the single responsibility principle? - -Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?_ +A. A keeps all of its pricing math within the Order class, whereas B calculates price in some way in each of its classes. Identify one place in your Hotel project where a class takes on multiple roles, or directly modifies the attributes of another class. My Reservation class should only be responsible for a single reservation. Instead of Reservation creating AND storing every instance, I should have a Hotel class to store all reservations in. That would make it much easier to create a Blocks class, which I was unable to do when the project was originally assigned. diff --git a/lib/date_range.rb b/lib/date_range.rb index 2c484a71e..c475113ee 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -1,4 +1,3 @@ -require_relative 'reservation' module Hotel class DateRange class InvalidDateRange < StandardError ; end diff --git a/lib/hotel.rb b/lib/hotel.rb index 1769b491f..041197b08 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,6 +1,7 @@ module Hotel class Hotel + class InvalidRoomError < StandardError ; end attr_reader :reservations, :rooms def initialize @@ -10,7 +11,7 @@ def initialize def available_rooms(date_range) reservations = @reservations.reject do |reservation| # removes rooms already booked - reservation.dates.overlap?(date_range) + !reservation.dates.overlap?(date_range) end reserved_rooms = reservations.map do |reservation| # converts each reservation in reservations into its room number reservation.room @@ -31,17 +32,17 @@ def add_reservation(reservation) def all_reservations return @reservations.map do |reservation| - return reservation.pretty_print + reservation.pretty_print end end # end all_reservations def list_on_date(date) reservations = @reservations.select do |reservation| - reservation.dates.check_in == date + reservation.dates.check_in <= date && date <= reservation.dates.check_out end - return reservations.map do |reservation| - return reservation.pretty_print - end - end # end on_date + return reservations.map do |reservation| + reservation.pretty_print + end + end # end on_date end # end class end # end module diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb index 7184516d0..086f39824 100644 --- a/specs/date_range_spec.rb +++ b/specs/date_range_spec.rb @@ -112,7 +112,7 @@ @honeymoon.overlap?(birthday).must_equal false end - end + end # end overlap? # before do # @puppy_dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb new file mode 100644 index 000000000..850581531 --- /dev/null +++ b/specs/hotel_spec.rb @@ -0,0 +1,137 @@ +require_relative 'spec_helper' + +describe 'Hotel' do + before do + @peach_castle = Hotel::Hotel.new + + dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) + @honeymoon = Hotel::Reservation.new(dates, 13, 200) + + dates = Hotel::DateRange.new(Date.new(2017, 1, 13), Date.new(2017, 1, 31)) + @birthday = Hotel::Reservation.new(dates, 13, 200) + + @peach_castle.add_reservation(@honeymoon) + @peach_castle.add_reservation(@birthday) + end + + describe 'available_rooms' do + it 'returns a list of all rooms when all are available' do + dates = Hotel::DateRange.new(Date.new(2018, 10, 13), Date.new(2018, 10, 31)) + @peach_castle.available_rooms(dates).must_equal @peach_castle.rooms + end + + it 'returns list of rooms available' do + dates = Hotel::DateRange.new(Date.new(2017, 10, 10), Date.new(2017, 10, 15)) + @peach_castle.available_rooms(dates).wont_include 13 + @peach_castle.available_rooms(dates).length.must_equal 19 + end + end # end available_rooms + + describe 'add_reservation' do + it 'adds a reservation' do + dates = Hotel::DateRange.new(Date.new(2017, 2, 13), Date.new(2017, 2, 28)) + batmitzvah = Hotel::Reservation.new(dates, 13, 200) + @peach_castle.add_reservation(batmitzvah) + + @peach_castle.reservations.length.must_equal 3 + end + + it 'raises an error if the room is already booked' do + dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) + batmitzvah = Hotel::Reservation.new(dates, 13, 200) + + proc{@peach_castle.add_reservation(batmitzvah)}.must_raise Hotel::Hotel::InvalidRoomError + end + + it 'will not add an invalid reservation to the array' do + dates = Hotel::DateRange.new(Date.new(2017, 10, 13), Date.new(2017, 10, 31)) + batmitzvah = Hotel::Reservation.new(dates, 13, 200) + + proc{@peach_castle.add_reservation(batmitzvah)}.must_raise Hotel::Hotel::InvalidRoomError + @peach_castle.reservations.length.must_equal 2 + end + end # end add_reservation + + describe 'all_reservations' do + it 'returns a list of all reservations' do + @peach_castle.all_reservations.must_equal ["Check In: 2017-10-13 +Check Out: 2017-10-31 +Room Number: 13 +Total Cost: $3600", +"Check In: 2017-01-13 +Check Out: 2017-01-31 +Room Number: 13 +Total Cost: $3600"] + end # sorry I know this is ugly but tabbing it will make it fail! + end # end all_reservations + + describe 'list_on_date' do + it 'returns a list of reservations on a date' do + @peach_castle.list_on_date(Date.new(2017, 10, 20)).must_equal ["Check In: 2017-10-13 +Check Out: 2017-10-31 +Room Number: 13 +Total Cost: $3600"] + end + + it 'returns an empty array if there are no reservations on a date' do + @peach_castle.list_on_date(Date.new(2020, 12, 25)).must_equal [] + end + + it 'returns a list including an added reservation on a date' do + dates = Hotel::DateRange.new(Date.new(2017, 10, 10), Date.new(2017, 10, 15)) + batmitzvah = Hotel::Reservation.new(dates, 1, 200) + @peach_castle.add_reservation(batmitzvah) + + @peach_castle.list_on_date(Date.new(2017, 10, 13)).must_equal ["Check In: 2017-10-13 +Check Out: 2017-10-31 +Room Number: 13 +Total Cost: $3600", "Check In: 2017-10-10 +Check Out: 2017-10-15 +Room Number: 1 +Total Cost: $1000"] + end + end # end list_on_date + + # it 'raises an InvalidRoomError if room has already been booked' do + # proc{Hotel::Reservation.new('Suge', Date.new(2017, 10, 15), Date.new(2017, 10, 20), Hotel::Room.find(13))}.must_raise Hotel::InvalidRoomError + # end # end test + # + # it 'will not add invalid reservation to @@reservations' do + # number_of_reservations = Hotel::Reservation.reservations.length + # begin + # Hotel::Reservation.new('Suge', Date.new(2017, 10, 15), Date.new(2017, 10, 20), Hotel::Room.find(13)) + # rescue + # end + # + # Hotel::Reservation.reservations.length.must_equal number_of_reservations # makes sure number did not change! + # end # end test + # end # end #initialize + # + # describe 'self.reservations' do + # it 'calls the class variable @@reservations, which holds all instances of Reservation in an array' do + # Hotel::Reservation.reservations.must_equal [puppy_expo, kitten_expo] + # end # end test + # end # end #self.reservations + # + # describe 'self.print_list' do + # it 'returns list of all reservations' do + # Hotel::Reservation.print_list.must_equal ["Name: Finn\nCheck In: 2017-10-13\nCheck Out: 2017-10-31\nRoom Number: 13\nTotal Cost: $3600", "Name: Girlie\nCheck In: 2018-01-17\nCheck Out: 2018-01-31\nRoom Number: 11\nTotal Cost: $2800"] + # end # end test + # end # end #self.print_list + # + # describe 'self.on_date' do + # it 'returns a list of reservations for a specific date' do + # Hotel::Reservation.on_date(Date.new(2018, 1, 17)).must_equal [kitten_expo] + # end # end test + # end # end #self.on_date + # + # describe 'self.available_rooms' do + # it 'excludes reservations outside a given date range' do + # given_range = Hotel::DateRange.new(Date.new(2017, 01, 01), Date.new(2017, 12, 31)) + # + # Hotel::Reservation.available_rooms(given_range).map do |room| + # room.room_number + # end.wont_include 13 + # end # end test + # end # end #self.available_rooms +end