From 94cb11ed1da1d32237f8f83699ce33ebc1986234 Mon Sep 17 00:00:00 2001 From: cojenco Date: Mon, 2 Mar 2020 13:16:02 -0800 Subject: [PATCH 01/51] Add coverage directory to .gitignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5e1422c9c..c0ac3dc53 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc +coverage From 0b568c49350270c60883a71af65a07b3ca6d39cf Mon Sep 17 00:00:00 2001 From: cojenco Date: Mon, 2 Mar 2020 13:17:40 -0800 Subject: [PATCH 02/51] Added SimpleCov into test helper --- test/test_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index c3a7695cf..bb7f25502 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,9 @@ # Add simplecov +require 'simplecov' +SimpleCov.start do + add_filter 'test/' # Tests should not be checked for coverage. +end + require "minitest" require "minitest/autorun" require "minitest/reporters" From f3ed103e666a8ede931ecfdfc76505e4ee938c8c Mon Sep 17 00:00:00 2001 From: cojenco Date: Mon, 2 Mar 2020 17:29:12 -0800 Subject: [PATCH 03/51] Setup files and gems. Started DateRange class and tests. --- lib/date_range.rb | 32 ++++++++++++++++++++ lib/reservation.rb | 21 +++++++++++++ lib/room.rb | 16 ++++++++++ lib/system_coordinator.rb | 27 +++++++++++++++++ test/daterange_test.rb | 62 +++++++++++++++++++++++++++++++++++++++ test/reservation_test.rb | 3 ++ test/test_helper.rb | 5 ++++ 7 files changed, 166 insertions(+) create mode 100644 lib/date_range.rb create mode 100644 lib/reservation.rb create mode 100644 lib/room.rb create mode 100644 lib/system_coordinator.rb create mode 100644 test/daterange_test.rb create mode 100644 test/reservation_test.rb diff --git a/lib/date_range.rb b/lib/date_range.rb new file mode 100644 index 000000000..bbea53a7e --- /dev/null +++ b/lib/date_range.rb @@ -0,0 +1,32 @@ +require 'date' + +module Hotel + class DateRange + + attr_reader :start_date, :end_date + + # your library code should assume that it's receiving Date objects to start + def initialize(start_date, end_date) + raise ArgumentError.new("Arguments passed in should be a Date class instance ") if !(start_date.is_a? Date) || !(end_date.is_a? Date) + raise ArgumentError.new("End date should not be earlier than start date") if end_date < start_date + + @start_date = start_date + @end_date = end_date + end + + def count_nights + nights = (@end_date - @start_date).to_i + return nights + end + + + end +end + + +# def initialize(start_year:, start_month:, start_day:, end_year:, end_month:, end_day:) +# @start_date = Date.new(start_year, start_month, start_day) +# @end_date = Date.new(end_year, end_month, end_day) + +# raise ArgumentError.new("End date should not be earlier than start date") if @end_date < @start_date +# end \ No newline at end of file diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..2fee49c43 --- /dev/null +++ b/lib/reservation.rb @@ -0,0 +1,21 @@ + +module Hotel + class Reservation + # attr_reader :id, :date_range, :room_id + + # def initialize + # @id + # @date_range + # @start_date + # @end_date + + # @room_id + # @total_cost? + + # end + + # def find(date_range) + # end + + end +end diff --git a/lib/room.rb b/lib/room.rb new file mode 100644 index 000000000..747d24ca4 --- /dev/null +++ b/lib/room.rb @@ -0,0 +1,16 @@ + +module Hotel + class Room + # attr_reader :room_num, :cost + + # def initialize + # @room_num + # @cost? + + # end + + # def find(date_range) + # end + + end +end diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb new file mode 100644 index 000000000..761210b8a --- /dev/null +++ b/lib/system_coordinator.rb @@ -0,0 +1,27 @@ +module Hotel + class SystemCoordinator + + # attr_reader + # SystemCoordinator should know rooms + + # def initialize + # @rooms? (I can access the list of all of the rooms in the hotel) + # end + + + + # # many methods + # # method to make reservation + # def make_reservation(date_range) + # end + + # [method] track reservation by date to find list of reservations by date + # [method] access the list of reservations for a specified room and a given date range + + # [method] avail rooms for that day. I can view a list of rooms that are not reserved for a given date range + + + + + end +end \ No newline at end of file diff --git a/test/daterange_test.rb b/test/daterange_test.rb new file mode 100644 index 000000000..a7bc77d2c --- /dev/null +++ b/test/daterange_test.rb @@ -0,0 +1,62 @@ +require_relative 'test_helper' + +describe "DateRange Class" do + before do + start_date = Date.new(2020, 03, 25) + end_date = Date.new(2020,03,27) + + @range01 = Hotel::DateRange.new(start_date, end_date) + end + + describe "Initialize" do + + it "Is an instance of DateRange" do + expect(@range01).must_be_kind_of Hotel::DateRange + end + + it "Stores a start date that is a Date class" do + expect(@range01.start_date).must_be_kind_of Date + end + + it "Stores an end date that is a Date class" do + expect(@range01.end_date).must_be_kind_of Date + end + + it "raises an ArgumentError if end date is before start date" do + start_date = Date.new(2020, 03, 25) + end_date = Date.new(2020,03,02) + expect{Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError + end + + it "raises ArgumentError if start_date or end_date is not a Date class" do + start_date = Date.new(2020, 03, 25) + end_date = Date.new(2020,03,27) + expect{Hotel::DateRange.new("2020/03/25", end_date)}.must_raise ArgumentError + expect{Hotel::DateRange.new(start_date, 20200327)}.must_raise ArgumentError + end + + + + + end + + describe "count_nights" do + it "counts the total nights of stay within a date range" do + expect(@range01.count_nights).must_equal 2 + end + end +end + + +# before do +# start_year = 2020 +# start_month = 03 +# start_day = 25 +# end_year = 2020 +# end_month = 03 +# end_day = 27 +# @range01 = Hotel::DateRange.new( +# start_year: start_year, start_month: start_month, start_day: start_day, +# end_year: end_year, end_month: end_month, end_day: end_day) +# end + diff --git a/test/reservation_test.rb b/test/reservation_test.rb new file mode 100644 index 000000000..b81c86b9d --- /dev/null +++ b/test/reservation_test.rb @@ -0,0 +1,3 @@ +require_relative 'test_helper' + + diff --git a/test/test_helper.rb b/test/test_helper.rb index bb7f25502..e9d53731f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -7,7 +7,12 @@ require "minitest" require "minitest/autorun" require "minitest/reporters" +# require "minitest/skip_dsl" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # require_relative your lib files here! +require_relative '../lib/date_range' +require_relative '../lib/reservation' +require_relative '../lib/system_coordinator' +require_relative '../lib/room' \ No newline at end of file From 6cd1e664b9c3d4ebc2ef7b9ec6e6eaf8881d5690 Mon Sep 17 00:00:00 2001 From: cojenco Date: Mon, 2 Mar 2020 17:47:44 -0800 Subject: [PATCH 04/51] Revised DateRange tests using more of Date.today --- lib/date_range.rb | 3 ++- test/daterange_test.rb | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index bbea53a7e..e58d6505e 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -8,7 +8,8 @@ class DateRange # your library code should assume that it's receiving Date objects to start def initialize(start_date, end_date) raise ArgumentError.new("Arguments passed in should be a Date class instance ") if !(start_date.is_a? Date) || !(end_date.is_a? Date) - raise ArgumentError.new("End date should not be earlier than start date") if end_date < start_date + raise ArgumentError.new("Dates should not be earlier than today") if start_date < Date.today + raise ArgumentError.new("End date should not be earlier than start date") if end_date <= start_date @start_date = start_date @end_date = end_date diff --git a/test/daterange_test.rb b/test/daterange_test.rb index a7bc77d2c..a5def13c5 100644 --- a/test/daterange_test.rb +++ b/test/daterange_test.rb @@ -2,8 +2,8 @@ describe "DateRange Class" do before do - start_date = Date.new(2020, 03, 25) - end_date = Date.new(2020,03,27) + start_date = Date.today + 5 + end_date = Date.today + 10 @range01 = Hotel::DateRange.new(start_date, end_date) end @@ -23,18 +23,30 @@ end it "raises an ArgumentError if end date is before start date" do - start_date = Date.new(2020, 03, 25) - end_date = Date.new(2020,03,02) + start_date = Date.today + 5 + end_date = Date.today + 1 expect{Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError end it "raises ArgumentError if start_date or end_date is not a Date class" do - start_date = Date.new(2020, 03, 25) - end_date = Date.new(2020,03,27) + start_date = Date.today + 10 + end_date = Date.today + 15 expect{Hotel::DateRange.new("2020/03/25", end_date)}.must_raise ArgumentError expect{Hotel::DateRange.new(start_date, 20200327)}.must_raise ArgumentError end + it "raises ArgumentError if start_date is in the past" do + start_date = Date.today - 5 + end_date = Date.today + 1 + expect{Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError + end + + it "raises ArgumentError for a 0-length date range" do + start_date = Date.today + end_date = start_date + expect{Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError + end + @@ -42,7 +54,7 @@ describe "count_nights" do it "counts the total nights of stay within a date range" do - expect(@range01.count_nights).must_equal 2 + expect(@range01.count_nights).must_equal 5 end end end From 8f69ba5d2d89cc8433dd91ce3d95c77860560428 Mon Sep 17 00:00:00 2001 From: cojenco Date: Mon, 2 Mar 2020 18:01:05 -0800 Subject: [PATCH 05/51] Added DateRange#count_nights method and tests. --- test/daterange_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/daterange_test.rb b/test/daterange_test.rb index a5def13c5..204b55ac3 100644 --- a/test/daterange_test.rb +++ b/test/daterange_test.rb @@ -55,6 +55,7 @@ describe "count_nights" do it "counts the total nights of stay within a date range" do expect(@range01.count_nights).must_equal 5 + expect(@range01.count_nights).must_be_instance_of Integer end end end From 7f9a4739107e1419b93f13c00a876a7d9bfb77dd Mon Sep 17 00:00:00 2001 From: cojenco Date: Mon, 2 Mar 2020 19:46:36 -0800 Subject: [PATCH 06/51] Added DateRange#include method and tests. --- lib/date_range.rb | 16 +++++++++++++++ test/daterange_test.rb | 44 ++++++++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index e58d6505e..8dcab6d96 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -20,6 +20,22 @@ def count_nights return nights end + def include(date) + if date >= @start_date && date < @end_date + return true + else + return false + end + end + + def overlap(other_range) + if other_range.start_date < @end_date && @start_date < other_range.end_date + return true + else + return false + end + end + end end diff --git a/test/daterange_test.rb b/test/daterange_test.rb index 204b55ac3..100ed1289 100644 --- a/test/daterange_test.rb +++ b/test/daterange_test.rb @@ -47,29 +47,43 @@ expect{Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError end - - - end - describe "count_nights" do + describe "#count_nights" do it "counts the total nights of stay within a date range" do expect(@range01.count_nights).must_equal 5 expect(@range01.count_nights).must_be_instance_of Integer end end + + describe "#include" do + it "returns true if the date is included in the date range" do + day01 = Date.today + 7 + expect(@range01.include(day01)).must_equal true + end + + it "returns false if the date is not included in the date range" do + day02 = Date.today + 1 + expect(@range01.include(day02)).must_equal false + end + end + + describe "#overlap" do + it "returns true if the two date ranges overlap" do + start_date = Date.today + 6 + end_date = Date.today + 8 + range03 = Hotel::DateRange.new(start_date, end_date) + expect(@range01.overlap(range03)).must_equal true + end + + it "returns false if it is only the start date overlaps end date" do + start_date = Date.today + 10 + end_date = Date.today + 12 + range04 = Hotel::DateRange.new(start_date, end_date) + expect(@range01.overlap(range04)).must_equal false + end + end end -# before do -# start_year = 2020 -# start_month = 03 -# start_day = 25 -# end_year = 2020 -# end_month = 03 -# end_day = 27 -# @range01 = Hotel::DateRange.new( -# start_year: start_year, start_month: start_month, start_day: start_day, -# end_year: end_year, end_month: end_month, end_day: end_day) -# end From d6abc6ea0cbbad24888152eac07139873ca187f4 Mon Sep 17 00:00:00 2001 From: cojenco Date: Mon, 2 Mar 2020 21:01:52 -0800 Subject: [PATCH 07/51] Added DateRange#overlapping method and tests. Revised #including method and tests. --- lib/date_range.rb | 23 +++++---------- test/daterange_test.rb | 66 +++++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 8dcab6d96..481b5c686 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -3,13 +3,13 @@ module Hotel class DateRange - attr_reader :start_date, :end_date + attr_accessor :start_date, :end_date # your library code should assume that it's receiving Date objects to start def initialize(start_date, end_date) - raise ArgumentError.new("Arguments passed in should be a Date class instance ") if !(start_date.is_a? Date) || !(end_date.is_a? Date) - raise ArgumentError.new("Dates should not be earlier than today") if start_date < Date.today - raise ArgumentError.new("End date should not be earlier than start date") if end_date <= start_date + raise ArgumentError.new("Please pass in Date class instances.") if !(start_date.is_a? Date) || !(end_date.is_a? Date) + raise ArgumentError.new("Live in the present! Dates should not be prior to today.") if start_date < Date.today + raise ArgumentError.new("End date should not be earlier than or the same day as start date.") if end_date <= start_date @start_date = start_date @end_date = end_date @@ -20,15 +20,15 @@ def count_nights return nights end - def include(date) - if date >= @start_date && date < @end_date + def including(other_range) + if other_range.start_date >= @start_date && other_range.end_date <= @end_date return true else return false end end - def overlap(other_range) + def overlapping(other_range) if other_range.start_date < @end_date && @start_date < other_range.end_date return true else @@ -36,14 +36,5 @@ def overlap(other_range) end end - end end - - -# def initialize(start_year:, start_month:, start_day:, end_year:, end_month:, end_day:) -# @start_date = Date.new(start_year, start_month, start_day) -# @end_date = Date.new(end_year, end_month, end_day) - -# raise ArgumentError.new("End date should not be earlier than start date") if @end_date < @start_date -# end \ No newline at end of file diff --git a/test/daterange_test.rb b/test/daterange_test.rb index 100ed1289..233f165a9 100644 --- a/test/daterange_test.rb +++ b/test/daterange_test.rb @@ -4,21 +4,19 @@ before do start_date = Date.today + 5 end_date = Date.today + 10 - @range01 = Hotel::DateRange.new(start_date, end_date) end describe "Initialize" do - - it "Is an instance of DateRange" do + it "is an instance of DateRange" do expect(@range01).must_be_kind_of Hotel::DateRange end - it "Stores a start date that is a Date class" do + it "stores a start date that is a Date class" do expect(@range01.start_date).must_be_kind_of Date end - it "Stores an end date that is a Date class" do + it "stores an end date that is a Date class" do expect(@range01.end_date).must_be_kind_of Date end @@ -31,8 +29,8 @@ it "raises ArgumentError if start_date or end_date is not a Date class" do start_date = Date.today + 10 end_date = Date.today + 15 - expect{Hotel::DateRange.new("2020/03/25", end_date)}.must_raise ArgumentError - expect{Hotel::DateRange.new(start_date, 20200327)}.must_raise ArgumentError + expect{Hotel::DateRange.new("2025/03/25", end_date)}.must_raise ArgumentError + expect{Hotel::DateRange.new(start_date, 20250327)}.must_raise ArgumentError end it "raises ArgumentError if start_date is in the past" do @@ -56,34 +54,48 @@ end end - describe "#include" do - it "returns true if the date is included in the date range" do - day01 = Date.today + 7 - expect(@range01.include(day01)).must_equal true + describe "#including" do + it "returns true if the other date range is included in the date range" do + range21 = Hotel::DateRange.new(Date.today + 7, Date.today + 8) + expect(@range01.including(range21)).must_equal true + range23 = Hotel::DateRange.new(Date.today + 5, Date.today + 6) + expect(@range01.including(range23)).must_equal true end - it "returns false if the date is not included in the date range" do - day02 = Date.today + 1 - expect(@range01.include(day02)).must_equal false + it "returns false if the other date range is not included in the date range" do + range22 = Hotel::DateRange.new(Date.today + 1, Date.today + 2) + expect(@range01.including(range22)).must_equal false + range24 = Hotel::DateRange.new(Date.today + 8, Date.today + 20) + expect(@range01.including(range24)).must_equal false + range26 = Hotel::DateRange.new(Date.today + 10, Date.today + 11) #edge case for checkout date + expect(@range01.including(range26)).must_equal false + range28 = Hotel::DateRange.new(Date.today + 4, Date.today + 5) #edge case for checkout date + expect(@range01.including(range28)).must_equal false end end - describe "#overlap" do + describe "#overlapping" do it "returns true if the two date ranges overlap" do - start_date = Date.today + 6 - end_date = Date.today + 8 - range03 = Hotel::DateRange.new(start_date, end_date) - expect(@range01.overlap(range03)).must_equal true + range03 = Hotel::DateRange.new(Date.today + 6, Date.today + 8) + expect(@range01.overlapping(range03)).must_equal true + range04 = Hotel::DateRange.new(Date.today + 5, Date.today + 6) + expect(@range01.overlapping(range04)).must_equal true + range05 = Hotel::DateRange.new(Date.today+8, Date.today+20) + expect(@range01.overlapping(range05)).must_equal true end - it "returns false if it is only the start date overlaps end date" do - start_date = Date.today + 10 - end_date = Date.today + 12 - range04 = Hotel::DateRange.new(start_date, end_date) - expect(@range01.overlap(range04)).must_equal false + it "returns false if the two date ranges do not overlap" do + range06 = Hotel::DateRange.new(Date.today + 1, Date.today + 3) + expect(@range01.overlapping(range06)).must_equal false + range09 = Hotel::DateRange.new(Date.today + 100, Date.today + 103) + expect(@range01.overlapping(range09)).must_equal false + end + + it "returns false if it is only the start date overlapping end date" do + range07 = Hotel::DateRange.new(Date.today + 10, Date.today + 12) #edge case for checkout date + expect(@range01.overlapping(range07)).must_equal false + range08 = Hotel::DateRange.new(Date.today + 1, Date.today + 5) #edge case for checkout date + expect(@range01.overlapping(range08)).must_equal false end end end - - - From 1d16a538b8dd1d4f73776c7dbd35fb615a168e2d Mon Sep 17 00:00:00 2001 From: cojenco Date: Mon, 2 Mar 2020 23:44:15 -0800 Subject: [PATCH 08/51] Created Reservation#initialize and #get_price methods and tests. --- .DS_Store | Bin 0 -> 6148 bytes lib/reservation.rb | 32 +++++++++++------- lib/system_coordinator.rb | 2 +- test/reservation_test.rb | 66 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..38b33a5a7ae0bd378cbd079b8c8bceb932902a2e GIT binary patch literal 6148 zcmeHK&2G~`5T0!etWzO!Kx&V^AaRIL8YnqbNG45%dO$)L!2wWf$8KxYwJY0cR6>w1 zyaVtCJPJ?1gYW?G?GNDmaIGS=Bh7xZyEBvB&+)96h**CVZV|PJh(iThO*BhH%nMzR zH9cYjnaq)sPsbGPC)sep+YA^63Khz{}!AlaZz?U-`QHjx_12r=S|+c*?jArWMi-N%Tdwy^Vg#H%r8#@ZNJE}D1;MceWnwAD&&lo4lWX_$;?V424U|Esek73ycL~F1$QVvh)~pB5s|I zKw3m01t@$&I;DGbMxiKwHTu57vreB)PiO@H9C1e!Q=$sy-w3ub7tw%EOu=kk_HoXO z({p4!#d?-!{W0fn!+(z+(}11=m#thp_)oP5Z&8Wt1(mZaA+f`{AG$_Xp8@^X=j*G# zRI@_EfMMW@84&fsfeLgrRtjb5KqIdJKnufCV2e)%5#wldHC75S17Ru@s6v^(VlWks zaYy^P8Y_h=oS43RF#XF+-%yzRb>w%XJ26+GX$=F0fmsF`s@oFh|K7jv|Fc1+XBaRH z{8tPxYv2v~*pfb57d9u(S_gUv6(am9g)#(p Date: Tue, 3 Mar 2020 00:02:27 -0800 Subject: [PATCH 09/51] Added Room#initialize method and tests --- lib/room.rb | 13 +++++++------ test/room_test.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 test/room_test.rb diff --git a/lib/room.rb b/lib/room.rb index 747d24ca4..cc9e788c3 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,13 +1,14 @@ module Hotel class Room - # attr_reader :room_num, :cost + attr_reader :id, :cost - # def initialize - # @room_num - # @cost? - - # end + def initialize(room_id, cost = 200) + raise ArgumentError if !room_id.is_a? Integer + raise ArgumentError if room_id < 1 || room_id > 20 + @id = room_id + @cost = cost + end # def find(date_range) # end diff --git a/test/room_test.rb b/test/room_test.rb new file mode 100644 index 000000000..5b1d314ee --- /dev/null +++ b/test/room_test.rb @@ -0,0 +1,29 @@ +require_relative 'test_helper' + +describe Hotel::Room do + before do + @room_id = 10 + @room01 = Hotel::Room.new(@room_id) + end + + describe "#initialize" do + it "is an instance of Room" do + expect(@room01).must_be_instance_of Hotel::Room + end + + it "stores a room_id as id" do + expect(@room01.id).must_equal @room_id + end + + it "raises ArgumentError if the room_id is not an integer within 1~20" do + expect{Hotel::Room.new(38)}.must_raise ArgumentError + expect{Hotel::Room.new(-10)}.must_raise ArgumentError + expect{Hotel::Room.new("suite")}.must_raise ArgumentError + end + + it "stores a cost for the room instance" do + expect(@room01.cost).must_equal 200 + end + + end +end \ No newline at end of file From 2e1e6b5a99b5043d7bf64b2955dc5a5903329735 Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 12:58:39 -0800 Subject: [PATCH 10/51] Added @rooms to SystemCoordinator constructor. Revised Room constructor and tests. --- .DS_Store | Bin 6148 -> 8196 bytes lib/.DS_Store | Bin 0 -> 6148 bytes lib/room.rb | 9 +++++++-- lib/system_coordinator.rb | 13 +++++++------ test/room_test.rb | 16 +++++++++++++--- test/system_coordinator_test.rb | 26 ++++++++++++++++++++++++++ test/test_helper.rb | 3 ++- 7 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 lib/.DS_Store create mode 100644 test/system_coordinator_test.rb diff --git a/.DS_Store b/.DS_Store index 38b33a5a7ae0bd378cbd079b8c8bceb932902a2e..c35f78aca97c19862c3ef72db0d2d7d0df43d99b 100644 GIT binary patch delta 171 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMA$h$FMH}hr%jz7$c**Q2SHn1@A zZsuV*#W;BbEBoXCmK(y%3^@#$3`u3dMR_^-dFdeICSPXlf1h|2OD@en}!tczJ`DHvo+8LN2MuALc*c{I@hZz7RPZE#- diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..16b79835ce70a67a13a80a78f2816f7d7f8f4196 GIT binary patch literal 6148 zcmeHKO-lnY5S`J21yOntJ?7|1@a$zN_2Ahbpl(~F(7LdGfVaK)i~Rxm-b@sC%~?ce z%H&OwnaSiqH;IVo^l@=2G7*t6l&CZc!r|i7R(2i%)pA@(D>rf{x3VlG`i(=ZeNPss z`T;e6t^WjjsV~;eyk0joyhza*^!UvLmdHMQmU0hm<;ilaq{03Rv3fX&-9b!)-=^sO zGVngYD$h_>xj~(Ci)~T)3hS}@2Kh?sz78^>8xjlz1HnKr@UI!bnN1n*Iz}4|1Ovgq zCjL_HMfp_-o<>fsnq*{{mjIeNHg zetc+N`Q!1TwmR}Ba~G`~qYVavfj$G<-ktFLKgVCD_{i^vL@yW!2L2cWI+|V1rr1 20 + raise ArgumentError if room_id < 1 @id = room_id @cost = cost + end + + # def self.all + + # def find(date_range) - # end + end end diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index f47e7ae58..79e0048d2 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -1,12 +1,13 @@ -module Hotel - class SystemCoordinator +require_relative 'room' - # attr_reader +module Hotel + class SystemCoordinator + attr_reader :rooms # SystemCoordinator should know rooms - # def initialize - # @rooms? (I can access the list of all of the rooms in the hotel) - # end + def initialize + @rooms = Array.new(20){|i| Hotel::Room.new(i+1)} #access the list of all of the rooms in the hotel + end diff --git a/test/room_test.rb b/test/room_test.rb index 5b1d314ee..e61f6fb2f 100644 --- a/test/room_test.rb +++ b/test/room_test.rb @@ -15,8 +15,7 @@ expect(@room01.id).must_equal @room_id end - it "raises ArgumentError if the room_id is not an integer within 1~20" do - expect{Hotel::Room.new(38)}.must_raise ArgumentError + it "raises ArgumentError if the room_id is not a positive integer" do expect{Hotel::Room.new(-10)}.must_raise ArgumentError expect{Hotel::Room.new("suite")}.must_raise ArgumentError end @@ -24,6 +23,17 @@ it "stores a cost for the room instance" do expect(@room01.cost).must_equal 200 end - end + + # describe "self.all" do + # it "returns an array of all the rooms" do + + # end + # end + + # describe "self.find(id)" do + # it "returns the room instance via room_id" do + + # end + # end end \ No newline at end of file diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb new file mode 100644 index 000000000..84f9db64e --- /dev/null +++ b/test/system_coordinator_test.rb @@ -0,0 +1,26 @@ +require_relative 'test_helper' + +describe Hotel::SystemCoordinator do + before do + @coordinator01 = Hotel::SystemCoordinator.new + end + + describe "#initialize" do + it "stores an instance variable @rooms that is an array" do + expect(@coordinator01.rooms).must_be_instance_of Array + end + + it "stores each element in the @rooms array as an instance of Room" do + @coordinator01.rooms.each do |room| + expect(room).must_be_instance_of Hotel::Room + end + end + + it "stores the correct room ids from 1 ~20" do + @coordinator01.rooms.each_with_index do |room,i| + expect(room.id).must_equal (i+1) + end + end + + end +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index e9d53731f..a7ec1c9c0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,4 +15,5 @@ require_relative '../lib/date_range' require_relative '../lib/reservation' require_relative '../lib/system_coordinator' -require_relative '../lib/room' \ No newline at end of file +require_relative '../lib/room' +require_relative '../lib/location' \ No newline at end of file From c35d83e2ec0bc11040bbfa5e136feee630c5b6a6 Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 13:17:45 -0800 Subject: [PATCH 11/51] Revised Room@cost to be a Float, and changed corresponding tests. --- lib/room.rb | 2 +- test/room_test.rb | 3 ++- test/system_coordinator_test.rb | 11 +++++++++-- test/test_helper.rb | 3 +-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 9aa971255..96ce74eb2 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -3,7 +3,7 @@ module Hotel class Room attr_reader :id, :cost - def initialize(room_id, cost = 200) + def initialize(room_id, cost = 200.00) raise ArgumentError if !room_id.is_a? Integer raise ArgumentError if room_id < 1 @id = room_id diff --git a/test/room_test.rb b/test/room_test.rb index e61f6fb2f..250ecba85 100644 --- a/test/room_test.rb +++ b/test/room_test.rb @@ -21,7 +21,8 @@ end it "stores a cost for the room instance" do - expect(@room01.cost).must_equal 200 + expect(@room01.cost).must_be_instance_of Float + expect(@room01.cost).must_equal 200.00 end end diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 84f9db64e..8682614d4 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -4,8 +4,8 @@ before do @coordinator01 = Hotel::SystemCoordinator.new end - - describe "#initialize" do + + describe "@rooms" do it "stores an instance variable @rooms that is an array" do expect(@coordinator01.rooms).must_be_instance_of Array end @@ -22,5 +22,12 @@ end end + it "stores the correct cost $200 in each room instance" do + @coordinator01.rooms.each do |room| + expect(room.cost).must_be_instance_of Float + expect(room.cost).must_equal 200.00 + end + end + end end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index a7ec1c9c0..e9d53731f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,5 +15,4 @@ require_relative '../lib/date_range' require_relative '../lib/reservation' require_relative '../lib/system_coordinator' -require_relative '../lib/room' -require_relative '../lib/location' \ No newline at end of file +require_relative '../lib/room' \ No newline at end of file From 326034fba33e99bdd80ee5ae231b43112ca89be5 Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 13:42:35 -0800 Subject: [PATCH 12/51] Revised Reservation class to pass in date_range as parameter. Revised reservation_test. --- lib/reservation.rb | 36 +++++++++++++++++++++------- lib/system_coordinator.rb | 8 +++++-- test/reservation_test.rb | 49 +++++++++++++++++++++------------------ 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 8cfa1e6b1..c38e63d7e 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,22 +2,21 @@ module Hotel class Reservation - attr_reader :id, :start_date, :end_date, :date_range, :room_id + attr_reader :id, :start_date, :end_date, :date_range, :room_id, :hotel_block_id @@next_id = 1 - def initialize(start_date, end_date, room_id) - raise ArgumentError.new("Please pass in Date class instances.") if !(start_date.is_a? Date) || !(end_date.is_a? Date) - raise ArgumentError.new("Live in the present! Dates should not be prior to today.") if start_date < Date.today - raise ArgumentError.new("End date should not be earlier than or the same day as start date.") if end_date <= start_date - @start_date = start_date - @end_date = end_date - @date_range = DateRange.new(start_date, end_date) + def initialize(date_range, room_id) + @date_range = date_range + @start_date = date_range.start_date + @end_date = date_range.end_date + @room_id = room_id @id = @@next_id @@next_id += 1 - # @hotel_block_id + + @hotel_block_id = -1 end def get_price @@ -29,3 +28,22 @@ def get_price end end + + +# attr_reader :id, :start_date, :end_date, :date_range, :room_id + +# @@next_id = 1 + +# def initialize(start_date, end_date, room_id) +# raise ArgumentError.new("Please pass in Date class instances.") if !(start_date.is_a? Date) || !(end_date.is_a? Date) +# raise ArgumentError.new("Live in the present! Dates should not be prior to today.") if start_date < Date.today +# raise ArgumentError.new("End date should not be earlier than or the same day as start date.") if end_date <= start_date +# @start_date = start_date +# @end_date = end_date +# @date_range = DateRange.new(start_date, end_date) +# @room_id = room_id + +# @id = @@next_id +# @@next_id += 1 +# # @hotel_block_id +# end \ No newline at end of file diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 79e0048d2..bd1435743 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -13,13 +13,17 @@ def initialize # # many methods # # method to make reservation - # def make_reservation(date_range) - # end + # def make_reservation(start_date, end_date) # [method] track reservation by date to find list of reservations by date + # def find_reservation_date (date_range) + # def find_reservation_date (start_date, end_date) + # [method] access the list of reservations for a specified room and a given date range + # def find_reservation_room_date(room_id, date_range) # [method] avail rooms for that day. I can view a list of rooms that are not reserved for a given date range + # def find_availabile_rooms(date_range) # handle/ rescue exceptions when there is no availability diff --git a/test/reservation_test.rb b/test/reservation_test.rb index 6cc80e684..61031fc57 100644 --- a/test/reservation_test.rb +++ b/test/reservation_test.rb @@ -2,10 +2,9 @@ describe Hotel::Reservation do before do - start_date = Date.today + 5 - end_date = Date.today + 10 - room_id = 10 - @reservation01 = Hotel::Reservation.new(start_date, end_date, room_id) + date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + @room_id = 10 + @reservation01 = Hotel::Reservation.new(date_range, @room_id) end describe "#initialize" do @@ -17,35 +16,29 @@ expect(@reservation01.id).must_be_instance_of Integer end + it "stores the correct room_id in the reservation" do + expect(@reservation01.room_id).must_be_instance_of Integer + expect(@reservation01.room_id).must_equal @room_id + end + it "stores a date_range that is an instance of DateRange" do expect(@reservation01.date_range).must_be_instance_of Hotel::DateRange end it "stores start_date and end_date that are both an instance of Date" do - expect(@reservation01.start_date).must_be_instance_of Date - expect(@reservation01.end_date).must_be_instance_of Date - end - - it "stores a room_id that is passed in as an argument" do - expect(@reservation01.room_id).must_equal 10 - end - end - - describe "#get_price" do - it "returns the total price for the reservation" do - expect(@reservation01.get_price).must_be_instance_of Float - expect(@reservation01.get_price).must_equal 1000 + expect(@reservation01.date_range.start_date).must_be_instance_of Date + expect(@reservation01.date_range.end_date).must_be_instance_of Date end - end end # describe Hotel::Reservation do # before do -# date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) +# start_date = Date.today + 5 +# end_date = Date.today + 10 # room_id = 10 -# @reservation01 = Hotel::Reservation.new(date_range, room_id) +# @reservation01 = Hotel::Reservation.new(start_date, end_date, room_id) # end # describe "#initialize" do @@ -62,8 +55,20 @@ # end # it "stores start_date and end_date that are both an instance of Date" do -# expect(@reservation01.date_range.start_date).must_be_instance_of Date -# expect(@reservation01.date_range.end_date).must_be_instance_of Date +# expect(@reservation01.start_date).must_be_instance_of Date +# expect(@reservation01.end_date).must_be_instance_of Date +# end + +# it "stores a room_id that is passed in as an argument" do +# expect(@reservation01.room_id).must_equal 10 # end +# end + +# describe "#get_price" do +# it "returns the total price for the reservation" do +# expect(@reservation01.get_price).must_be_instance_of Float +# expect(@reservation01.get_price).must_equal 1000 +# end + # end # end From 205f236438ef1657a4db418d0b848a6852348f14 Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 14:06:28 -0800 Subject: [PATCH 13/51] Added back Reservation#get_price tests. --- lib/reservation.rb | 3 ++- test/reservation_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index c38e63d7e..4970c190a 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -12,6 +12,7 @@ def initialize(date_range, room_id) @end_date = date_range.end_date @room_id = room_id + #do i want to also know about the room instance? @id = @@next_id @@next_id += 1 @@ -20,7 +21,7 @@ def initialize(date_range, room_id) end def get_price - price = date_range.count_nights * 200.00 + price = date_range.count_nights * 200.00 #should require relative room and take room.cost return price end diff --git a/test/reservation_test.rb b/test/reservation_test.rb index 61031fc57..818fd6abb 100644 --- a/test/reservation_test.rb +++ b/test/reservation_test.rb @@ -30,6 +30,13 @@ expect(@reservation01.date_range.end_date).must_be_instance_of Date end end + + describe "#get_price" do + it "returns the total price for the reservation" do + expect(@reservation01.get_price).must_be_instance_of Float + expect(@reservation01.get_price).must_equal 1000.00 + end + end end From 543b708f29a890a4cb27136401fada9f31d703ed Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 14:30:44 -0800 Subject: [PATCH 14/51] Added DateRange#include_date method to pass in specific date instead of date_range. --- lib/date_range.rb | 5 +++++ lib/system_coordinator.rb | 24 +++++++++++++++++++++--- test/daterange_test.rb | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 481b5c686..3ec01e2ef 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -28,6 +28,11 @@ def including(other_range) end end + def include_date(date) + return true if date >= @start_date && date < @end_date + return false + end + def overlapping(other_range) if other_range.start_date < @end_date && @start_date < other_range.end_date return true diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index bd1435743..971508ab1 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -1,4 +1,5 @@ require_relative 'room' +require_relative 'date_range' module Hotel class SystemCoordinator @@ -9,15 +10,32 @@ def initialize @rooms = Array.new(20){|i| Hotel::Room.new(i+1)} #access the list of all of the rooms in the hotel end + # [method] track reservation by date to find list of reservations for a specific date + def find_reservation_by_date (date) + + end + + + # method to make reservation + # def make_reservation(start_date, end_date) + # date_range = Hotel::DateRange.new(start_date,end_date) + # room_id = 1 + # reservation = Hotel::Reservation.new(date_range, room_id) + # return reservation + + # end + # # many methods # # method to make reservation # def make_reservation(start_date, end_date) - # [method] track reservation by date to find list of reservations by date - # def find_reservation_date (date_range) - # def find_reservation_date (start_date, end_date) + # # [method] track reservation by date to find list of reservations by date + # def find_reservation_by_date (date) + # def find_reservation_date (start_date, end_date) + # can access the list of reservations for a specific date + # [method] access the list of reservations for a specified room and a given date range # def find_reservation_room_date(room_id, date_range) diff --git a/test/daterange_test.rb b/test/daterange_test.rb index 233f165a9..9b4ba28e2 100644 --- a/test/daterange_test.rb +++ b/test/daterange_test.rb @@ -74,6 +74,24 @@ end end + describe "#include_date" do + it "returns true if the specific date is included in the date range" do + date01 = Date.today + 8 + date03 = Date.today + 5 + expect(@range01.include_date(date01)).must_equal true + expect(@range01.include_date(date03)).must_equal true + end + + it "returns false if the specific date is not included in the date range" do + date02 = Date.today + 1 + date04 = Date.today + 20 + date06 = Date.today + 10 + expect(@range01.include_date(date02)).must_equal false + expect(@range01.include_date(date04)).must_equal false + expect(@range01.include_date(date06)).must_equal false + end + end + describe "#overlapping" do it "returns true if the two date ranges overlap" do range03 = Hotel::DateRange.new(Date.today + 6, Date.today + 8) From 17d6682df2575ad63e0012adcad28762b90742ad Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 16:26:50 -0800 Subject: [PATCH 15/51] Added SystemCoordinator#find_reservation_by_date method and @reservations. Added corresponding tests. --- .DS_Store | Bin 8196 -> 8196 bytes lib/reservation.rb | 2 +- lib/room.rb | 6 +++- lib/system_coordinator.rb | 12 ++++--- test/.DS_Store | Bin 0 -> 6148 bytes test/system_coordinator_test.rb | 57 +++++++++++++++++++++++++++++++- 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 test/.DS_Store diff --git a/.DS_Store b/.DS_Store index c35f78aca97c19862c3ef72db0d2d7d0df43d99b..d24a5b6301bd1bf8e9525d6c125c874dc3f365cc 100644 GIT binary patch delta 14 VcmZp1XmQx^UYOBj^9NxO9sn#r1x5e> delta 16 XcmZp1XmQx^UU+hzko#sck#pPtI>-iV diff --git a/lib/reservation.rb b/lib/reservation.rb index 4970c190a..3aece6d8d 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -17,7 +17,7 @@ def initialize(date_range, room_id) @id = @@next_id @@next_id += 1 - @hotel_block_id = -1 + # @hotel_block_id = -1 end def get_price diff --git a/lib/room.rb b/lib/room.rb index 96ce74eb2..45b947d83 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -3,14 +3,18 @@ module Hotel class Room attr_reader :id, :cost - def initialize(room_id, cost = 200.00) + def initialize(room_id, cost = 200.00) #reservations = nil raise ArgumentError if !room_id.is_a? Integer raise ArgumentError if room_id < 1 @id = room_id @cost = cost + #@reservations = reservations || [] end + # def add_reservation_to_room + # end + # def self.all diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 971508ab1..e1c28b294 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -3,16 +3,18 @@ module Hotel class SystemCoordinator - attr_reader :rooms + attr_reader :rooms, :reservations # SystemCoordinator should know rooms def initialize @rooms = Array.new(20){|i| Hotel::Room.new(i+1)} #access the list of all of the rooms in the hotel + @reservations = [] end # [method] track reservation by date to find list of reservations for a specific date def find_reservation_by_date (date) - + found_reservations = @reservations.select{|reservation|reservation.date_range.include_date(date)} + return found_reservations end @@ -20,8 +22,10 @@ def find_reservation_by_date (date) # def make_reservation(start_date, end_date) # date_range = Hotel::DateRange.new(start_date,end_date) # room_id = 1 - # reservation = Hotel::Reservation.new(date_range, room_id) - # return reservation + # new_reservation = Hotel::Reservation.new(date_range, room_id) + # @reservations << new_reservation + # push new reservation into room reservation container + # return new_reservation # end diff --git a/test/.DS_Store b/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..bf121634751d380e020a129aeb60820bafc49401 GIT binary patch literal 6148 zcmeHK%}T>S5T2|D_fPI0VLgF0zbMK{UX(e!eJiF<3r9bx2Go$E|vCz@q}Rn0L6Sy_q9KhNc(k#o16c}BNbS3wWD zx-K@}m)Jn6kYFGf2nN=g0n}`f!M0(v!9Xw&4AczB_aT7_rjC`Nemc6Z_$VePs3%3hU^|pQt-=Y8Y)W5Dcs` zuwl1DssHEQ=l|89xC;h?fq%sS_s5sx5tih&wY4~@wF&eJDk6TBVI6{wmSXryDL#a% Zz@A74m^xO5ut4HRKxv3382D2Lz5oZ4VmJT* literal 0 HcmV?d00001 diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 8682614d4..2f3dca93a 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -6,7 +6,7 @@ end describe "@rooms" do - it "stores an instance variable @rooms that is an array" do + it "is an instance variable @rooms that is an array" do expect(@coordinator01.rooms).must_be_instance_of Array end @@ -28,6 +28,61 @@ expect(room.cost).must_equal 200.00 end end + end + + describe "@reservations" do + before do + date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + @room_id = 10 + @reservation01 = Hotel::Reservation.new(date_range, @room_id) + @coordinator01.reservations << @reservation01 + end + # let (:reservation01) { + # Hotel::Reservation.new(Hotel::DateRange.new(Date.today + 5, Date.today + 10), 10) + # } + + it "returns an array of reservations that include that date" do + expect(@coordinator01.reservations).must_be_instance_of Array + end + + it "stores Reservation instances in each element of @reservations" do + @coordinator01.reservations.each do |reservation| + expect(reservation).must_be_instance_of Hotel::Reservation + expect(reservation.date_range).must_be_instance_of Hotel::DateRange + expect(reservation.room_id).must_equal @room_id + end + end + + it "stores the correct room_id in each of the Reservation instances" do + expect(@coordinator01.reservations[0].room_id).must_equal @room_id + end + end + + describe "#find_reservation_by_date" do + before do + date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + @room_id = 10 + @reservation01 = Hotel::Reservation.new(date_range, @room_id) + @coordinator01.reservations << @reservation01 + + @found_reservations = @coordinator01.find_reservation_by_date(Date.today + 7) + end + + it "returns an array" do + expect(@found_reservations).must_be_instance_of Array + # expect(@coordinator01.find_reservation_by_date(date10)).must_be_instance_of Array + end + + it "returns what? when the date is not included" do + date11 = Date.today + 1 + expect(@coordinator01.find_reservation_by_date(date11)).must_equal [] + end + + it "stores Reservation instances in the returned array" do + @found_reservations.each do |reservation| + expect(reservation).must_be_instance_of Hotel::Reservation + end + end end end \ No newline at end of file From 9026b3e5ad773407269c462afa875f0f5178c926 Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 17:26:28 -0800 Subject: [PATCH 16/51] Added @bookings to Room and updated tests --- lib/room.rb | 10 +++++----- test/room_test.rb | 12 +++++++++++- test/system_coordinator_test.rb | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 45b947d83..e8ea24cc6 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,15 +1,15 @@ +require_relative 'reservation' module Hotel class Room - attr_reader :id, :cost + attr_reader :room_id, :cost, :bookings - def initialize(room_id, cost = 200.00) #reservations = nil + def initialize(room_id, cost = 200.00, bookings = nil) raise ArgumentError if !room_id.is_a? Integer raise ArgumentError if room_id < 1 - @id = room_id + @room_id = room_id @cost = cost - #@reservations = reservations || [] - + @bookings = bookings || [] end # def add_reservation_to_room diff --git a/test/room_test.rb b/test/room_test.rb index 250ecba85..d171b72ec 100644 --- a/test/room_test.rb +++ b/test/room_test.rb @@ -12,7 +12,7 @@ end it "stores a room_id as id" do - expect(@room01.id).must_equal @room_id + expect(@room01.room_id).must_equal @room_id end it "raises ArgumentError if the room_id is not a positive integer" do @@ -24,6 +24,16 @@ expect(@room01.cost).must_be_instance_of Float expect(@room01.cost).must_equal 200.00 end + + it "stores an instance variable @reservations that is an array" do + expect(@room01.bookings).must_be_instance_of Array + end + + # it "stores an @reservations array where each element is a Reservation instance " do + # expect(@room01.bookings[0]).must_be_instance_of Hotel::Reservation + # end + + end # describe "self.all" do diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 2f3dca93a..9af55581b 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -18,7 +18,7 @@ it "stores the correct room ids from 1 ~20" do @coordinator01.rooms.each_with_index do |room,i| - expect(room.id).must_equal (i+1) + expect(room.room_id).must_equal (i+1) end end From 81831db1c0805a23043ebe0a6730beac10bc885f Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 17:40:53 -0800 Subject: [PATCH 17/51] Added Room#add_booking_to_room method and tests. --- lib/room.rb | 5 +++-- test/room_test.rb | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index e8ea24cc6..1c3346470 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -12,8 +12,9 @@ def initialize(room_id, cost = 200.00, bookings = nil) @bookings = bookings || [] end - # def add_reservation_to_room - # end + def add_booking_to_room(new_reservation) + @bookings << new_reservation + end # def self.all diff --git a/test/room_test.rb b/test/room_test.rb index d171b72ec..396ed45de 100644 --- a/test/room_test.rb +++ b/test/room_test.rb @@ -32,8 +32,30 @@ # it "stores an @reservations array where each element is a Reservation instance " do # expect(@room01.bookings[0]).must_be_instance_of Hotel::Reservation # end + + end + + describe "#add_booking_to_room" do + before do + date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + room_id = 10 + @reservation01 = Hotel::Reservation.new(date_range, room_id) + end + + it "returns an array of all the current bookings" do + expect(@room01.add_booking_to_room(@reservation01)).must_be_instance_of Array + end + + it "includes the new booking into @bookings" do + expect(@room01.add_booking_to_room(@reservation01)).must_include @reservation01 + end + + it "increases @bookings size by 1" do + before_size = @room01.bookings.length + after_size = (@room01.add_booking_to_room(@reservation01)).length + expect(after_size).must_equal before_size + 1 + end - end # describe "self.all" do From 1c4c68635f3488ac6d0edd2ac1e0dab4a33c0bcd Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 20:32:25 -0800 Subject: [PATCH 18/51] Added SystemCoordinator#find_reservations_room_date method and tests. --- lib/room.rb | 7 ----- lib/system_coordinator.rb | 34 ++++++++++++++--------- test/room_test.rb | 12 --------- test/system_coordinator_test.rb | 48 ++++++++++++++++++++++++++++++--- 4 files changed, 67 insertions(+), 34 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 1c3346470..7fa707693 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -15,13 +15,6 @@ def initialize(room_id, cost = 200.00, bookings = nil) def add_booking_to_room(new_reservation) @bookings << new_reservation end - - - # def self.all - - - # def find(date_range) - end end diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index e1c28b294..c8465b792 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -11,11 +11,29 @@ def initialize @reservations = [] end - # [method] track reservation by date to find list of reservations for a specific date - def find_reservation_by_date (date) - found_reservations = @reservations.select{|reservation|reservation.date_range.include_date(date)} - return found_reservations + # #method# track reservation by date to find list of reservations for a specific date + def find_reservations_by_date (date) + # what returns if no match + reservations_by_date = @reservations.select{|reservation|reservation.date_range.include_date(date)} + return reservations_by_date end + + # #method# access the list of reservations for a specified room and a given date range + def find_reservations_room_date(room_id, date_range) + # what returns if no match + reservations_room_date = @reservations.select{ + |reservation|reservation.room_id == room_id && reservation.date_range.overlapping(date_range) + } + return reservations_room_date + # alternatively, we can search through the collection of rooms + # selected_room = @rooms.find{|room|room.room_id == room_id} + # reservations_room_date = selected_room.bookings.select{|reservation|reservation.date_range.overlapping(date_range)} + end + + # [method] avail rooms for that day. I can view a list of rooms that are not reserved for a given date range + # def find_availabile_rooms(date_range) + + # end # method to make reservation @@ -35,14 +53,6 @@ def find_reservation_by_date (date) # # method to make reservation # def make_reservation(start_date, end_date) - # # [method] track reservation by date to find list of reservations by date - # def find_reservation_by_date (date) - # def find_reservation_date (start_date, end_date) - # can access the list of reservations for a specific date - - - # [method] access the list of reservations for a specified room and a given date range - # def find_reservation_room_date(room_id, date_range) # [method] avail rooms for that day. I can view a list of rooms that are not reserved for a given date range # def find_availabile_rooms(date_range) diff --git a/test/room_test.rb b/test/room_test.rb index 396ed45de..6d49e9a47 100644 --- a/test/room_test.rb +++ b/test/room_test.rb @@ -57,16 +57,4 @@ end end - - # describe "self.all" do - # it "returns an array of all the rooms" do - - # end - # end - - # describe "self.find(id)" do - # it "returns the room instance via room_id" do - - # end - # end end \ No newline at end of file diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 9af55581b..5a6a40628 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -58,14 +58,14 @@ end end - describe "#find_reservation_by_date" do + describe "#find_reservations_by_date" do before do date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) @room_id = 10 @reservation01 = Hotel::Reservation.new(date_range, @room_id) @coordinator01.reservations << @reservation01 - @found_reservations = @coordinator01.find_reservation_by_date(Date.today + 7) + @found_reservations = @coordinator01.find_reservations_by_date(Date.today + 7) end it "returns an array" do @@ -75,7 +75,7 @@ it "returns what? when the date is not included" do date11 = Date.today + 1 - expect(@coordinator01.find_reservation_by_date(date11)).must_equal [] + expect(@coordinator01.find_reservations_by_date(date11)).must_equal [] end it "stores Reservation instances in the returned array" do @@ -83,6 +83,48 @@ expect(reservation).must_be_instance_of Hotel::Reservation end end + end + + describe "#find_reservations_room_date" do + before do + @room_id = 10 + @room01 = Hotel::Room.new(@room_id) + + @date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + @reservation01 = Hotel::Reservation.new(@date_range, @room_id) + @coordinator01.reservations << @reservation01 + @room01.add_booking_to_room(@reservation01) + + @reservation_list = @coordinator01.find_reservations_room_date(@room_id, @date_range) + end + + it "returns an array of reservations" do + expect(@reservation_list).must_be_instance_of Array + end + it "stores Reservation instances in each element of the array" do + @reservation_list.each do |reservation| + expect(reservation).must_be_instance_of Hotel::Reservation + end + end end + + # describe "#find_availabile_rooms" do + # before do + # @room_id = 10 + # @room01 = Hotel::Room.new(@room_id) + + # @date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + # @reservation01 = Hotel::Reservation.new(@date_range, @room_id) + # @coordinator01.reservations << @reservation01 + # @room01.add_booking_to_room(@reservation01) + + # @reservation_list = @coordinator01.find_reservations_room_date(@room_id, @date_range) + # end + + # it "returns an array" do + # expect(@coordinator01.find_availabile_rooms(@date_range)).must_be_instance_of Array + # end + # end + end \ No newline at end of file From f5d36d4232d924770f7900f81f3b41e29db08c8b Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 21:25:38 -0800 Subject: [PATCH 19/51] Added SystemCoordinator#find_availabile_rooms method and tests. --- lib/system_coordinator.rb | 38 ++++++++++++++++++++++++--- test/system_coordinator_test.rb | 46 +++++++++++++++++++++++---------- 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index c8465b792..06c47aed3 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -30,10 +30,27 @@ def find_reservations_room_date(room_id, date_range) # reservations_room_date = selected_room.bookings.select{|reservation|reservation.date_range.overlapping(date_range)} end + def find_reservations_range(given_range) + # what returns if no match + reservations_range = @reservations.select{|reservation|reservation.date_range.overlapping(given_range)} + return reservations_range + end + # [method] avail rooms for that day. I can view a list of rooms that are not reserved for a given date range - # def find_availabile_rooms(date_range) + def find_availabile_rooms(given_range) + available_rooms = [] + unavailabes = find_reservations_range(given_range) + # unavailabes = @reservations.select{|reservation|reservation.date_range.overlapping(given_range)} + unavailable_room_ids = unavailabes.map do |reservation| + reservation.room_id + end - # end + unavailable_room_ids.each do |id| + available_rooms = @rooms.reject{|room|room.room_id == id} + end + + return available_rooms + end # method to make reservation @@ -61,4 +78,19 @@ def find_reservations_room_date(room_id, date_range) end -end \ No newline at end of file +end + + +# def find_availabile_rooms(given_range) +# @rooms.each do |room| +# room.bookings.find{|reservation|reservation.date_range.overlapping(given_range)} + + +# room.bookings.each do |reservation| +# if reservation.date_range.overlapping(given_range) +# #not available +# #break +# end +# end +# available_rooms << room +# end \ No newline at end of file diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 5a6a40628..f4c060d00 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -109,22 +109,40 @@ end end - # describe "#find_availabile_rooms" do - # before do - # @room_id = 10 - # @room01 = Hotel::Room.new(@room_id) + describe "#find_availabile_rooms" do + before do + @room_id = 10 + @room01 = Hotel::Room.new(@room_id) - # @date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) - # @reservation01 = Hotel::Reservation.new(@date_range, @room_id) - # @coordinator01.reservations << @reservation01 - # @room01.add_booking_to_room(@reservation01) + @date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + @reservation01 = Hotel::Reservation.new(@date_range, @room_id) + @coordinator01.reservations << @reservation01 + @room01.add_booking_to_room(@reservation01) - # @reservation_list = @coordinator01.find_reservations_room_date(@room_id, @date_range) - # end + @available_rooms = @coordinator01.find_availabile_rooms(@date_range) + end + + it "returns an array" do + expect(@available_rooms).must_be_instance_of Array + end + + it "stores Room instances in the array" do + @available_rooms.each do |room| + expect(room).must_be_instance_of Hotel::Room + end + end - # it "returns an array" do - # expect(@coordinator01.find_availabile_rooms(@date_range)).must_be_instance_of Array - # end - # end + it "represents number of rooms as the size of the array" do + expect(@available_rooms.length).must_equal 19 + end + + it "should not include rooms that have reservations in the given date_range" do + @available_rooms.each do |room| + room.bookings.each do |booking| + expect(booking.date_range.overlapping(@date_range)).must_equal false + end + end + end + end end \ No newline at end of file From f074a791fac0c3611d295748e5cc2b839a655e96 Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 22:12:35 -0800 Subject: [PATCH 20/51] Added SystemCoordinator#make_reservation method and tests initial version. --- lib/system_coordinator.rb | 23 ++++++++++++++--------- test/system_coordinator_test.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 06c47aed3..040cc8b5b 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -1,5 +1,6 @@ require_relative 'room' require_relative 'date_range' +require_relative 'reservation' module Hotel class SystemCoordinator @@ -51,18 +52,22 @@ def find_availabile_rooms(given_range) return available_rooms end + + # method to find room + # def find_room(room_id) # method to make reservation - # def make_reservation(start_date, end_date) - # date_range = Hotel::DateRange.new(start_date,end_date) - # room_id = 1 - # new_reservation = Hotel::Reservation.new(date_range, room_id) - # @reservations << new_reservation - # push new reservation into room reservation container - # return new_reservation - - # end + def make_reservation(start_date, end_date) + range_created = Hotel::DateRange.new(start_date,end_date) + available_rooms = find_availabile_rooms(range_created) + chosen_room_id = available_rooms[0].room_id + + new_reservation = Hotel::Reservation.new(range_created, chosen_room_id) + @reservations << new_reservation + #push new reservation into room reservation container + return new_reservation + end diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index f4c060d00..d565f37bf 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -145,4 +145,30 @@ end end + describe "#make_reservation" do + before do + room01 = Hotel::Room.new(10) + date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + reservation01 = Hotel::Reservation.new(date_range, 10) + room01.add_booking_to_room(reservation01) + @coordinator01.reservations << reservation01 + + + + start_date = Date.today + 5 + end_date = Date.today + 10 + @new_rs = @coordinator01.make_reservation(start_date, end_date) + end + + it "returns a Reservation" do + expect(@new_rs).must_be_instance_of Hotel::Reservation + end + + it "stores the room_id in the Reservation returned" do + puts @new_rs.room_id + expect(@new_rs.room_id).must_be_instance_of Integer + end + + end + end \ No newline at end of file From 4baafe984d805fc8dd4b09400c1001a3d5152533 Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 22:32:20 -0800 Subject: [PATCH 21/51] Added SystemCoordinator#find_room method and tests. --- lib/system_coordinator.rb | 5 ++++- test/system_coordinator_test.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 040cc8b5b..197643286 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -54,7 +54,10 @@ def find_availabile_rooms(given_range) end # method to find room - # def find_room(room_id) + def find_room(given_room_id) + room_found = @rooms.find{|room|room.room_id == given_room_id} + return room_found + end # method to make reservation diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index d565f37bf..675a96c94 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -171,4 +171,14 @@ end + describe "#find_room" do + it "returns an instance of Room" do + expect(@coordinator01.find_room(10)).must_be_instance_of Hotel::Room + end + + it "returns nil??? if an invalid room_id is passed in" do + expect(@coordinator01.find_room(999)).must_be_nil + end + end + end \ No newline at end of file From 83984e0b1554d83e20bc1e76e39e56475bf075fe Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 22:35:51 -0800 Subject: [PATCH 22/51] Revised SystemCoordinator#make_reservation method to push reservating to room @bookings. --- lib/system_coordinator.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 197643286..79dbd4a4f 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -65,10 +65,12 @@ def make_reservation(start_date, end_date) range_created = Hotel::DateRange.new(start_date,end_date) available_rooms = find_availabile_rooms(range_created) chosen_room_id = available_rooms[0].room_id - + chosen_room = find_room(chosen_room_id) new_reservation = Hotel::Reservation.new(range_created, chosen_room_id) + @reservations << new_reservation - #push new reservation into room reservation container + chosen_room.add_booking_to_room(new_reservation) + return new_reservation end From a3bdc8fa2d2071302f97737f5174e99009b2a643 Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 22:47:46 -0800 Subject: [PATCH 23/51] Added SystemCoordinator#list_rooms method and tests. --- lib/system_coordinator.rb | 43 ++++++++------------------------- test/system_coordinator_test.rb | 13 ++++++++++ 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 79dbd4a4f..1c235d7fe 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -5,13 +5,16 @@ module Hotel class SystemCoordinator attr_reader :rooms, :reservations - # SystemCoordinator should know rooms def initialize @rooms = Array.new(20){|i| Hotel::Room.new(i+1)} #access the list of all of the rooms in the hotel @reservations = [] end + def list_rooms + return @rooms + end + # #method# track reservation by date to find list of reservations for a specific date def find_reservations_by_date (date) # what returns if no match @@ -21,7 +24,7 @@ def find_reservations_by_date (date) # #method# access the list of reservations for a specified room and a given date range def find_reservations_room_date(room_id, date_range) - # what returns if no match + # what returns if no match?!!!! reservations_room_date = @reservations.select{ |reservation|reservation.room_id == room_id && reservation.date_range.overlapping(date_range) } @@ -32,7 +35,7 @@ def find_reservations_room_date(room_id, date_range) end def find_reservations_range(given_range) - # what returns if no match + # what returns if no match?!!!!! reservations_range = @reservations.select{|reservation|reservation.date_range.overlapping(given_range)} return reservations_range end @@ -41,7 +44,7 @@ def find_reservations_range(given_range) def find_availabile_rooms(given_range) available_rooms = [] unavailabes = find_reservations_range(given_range) - # unavailabes = @reservations.select{|reservation|reservation.date_range.overlapping(given_range)} + # what returns if no match?!!!!! rescue an raised exception???????? unavailable_room_ids = unavailabes.map do |reservation| reservation.room_id end @@ -59,11 +62,11 @@ def find_room(given_room_id) return room_found end - # method to make reservation def make_reservation(start_date, end_date) range_created = Hotel::DateRange.new(start_date,end_date) available_rooms = find_availabile_rooms(range_created) + # what returns if no match?!!!!! rescue an raised exception???????? chosen_room_id = available_rooms[0].room_id chosen_room = find_room(chosen_room_id) new_reservation = Hotel::Reservation.new(range_created, chosen_room_id) @@ -74,33 +77,7 @@ def make_reservation(start_date, end_date) return new_reservation end - - - # # many methods - # # method to make reservation - # def make_reservation(start_date, end_date) - - - # [method] avail rooms for that day. I can view a list of rooms that are not reserved for a given date range - # def find_availabile_rooms(date_range) - - # handle/ rescue exceptions when there is no availability - - + # handle/ rescue exceptions + # edge cases end end - - -# def find_availabile_rooms(given_range) -# @rooms.each do |room| -# room.bookings.find{|reservation|reservation.date_range.overlapping(given_range)} - - -# room.bookings.each do |reservation| -# if reservation.date_range.overlapping(given_range) -# #not available -# #break -# end -# end -# available_rooms << room -# end \ No newline at end of file diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 675a96c94..811d7502b 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -58,6 +58,19 @@ end end + describe "#list_rooms" do + it "returns an Array with size of 20" do + expect(@coordinator01.list_rooms).must_be_instance_of Array + expect(@coordinator01.list_rooms.length).must_equal 20 + end + + it "stores Room instance in each array element" do + @coordinator01.list_rooms.each do |room| + expect(room).must_be_instance_of Hotel::Room + end + end + end + describe "#find_reservations_by_date" do before do date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) From b4ae83eebe3b0412dd997ddae05ef914ba736b26 Mon Sep 17 00:00:00 2001 From: cojenco Date: Tue, 3 Mar 2020 23:08:20 -0800 Subject: [PATCH 24/51] Added more tests for #make_reservation and cleaned up draft. --- lib/system_coordinator.rb | 12 +++++++++--- test/system_coordinator_test.rb | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 1c235d7fe..aee661a0f 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -15,14 +15,14 @@ def list_rooms return @rooms end - # #method# track reservation by date to find list of reservations for a specific date + # method to find list of reservations for a specific date def find_reservations_by_date (date) # what returns if no match reservations_by_date = @reservations.select{|reservation|reservation.date_range.include_date(date)} return reservations_by_date end - # #method# access the list of reservations for a specified room and a given date range + # method to access list of reservations for a specified room and a given date range def find_reservations_room_date(room_id, date_range) # what returns if no match?!!!! reservations_room_date = @reservations.select{ @@ -40,7 +40,7 @@ def find_reservations_range(given_range) return reservations_range end - # [method] avail rooms for that day. I can view a list of rooms that are not reserved for a given date range + # method to view a list of rooms that are not reserved for a given date range def find_availabile_rooms(given_range) available_rooms = [] unavailabes = find_reservations_range(given_range) @@ -66,7 +66,13 @@ def find_room(given_room_id) def make_reservation(start_date, end_date) range_created = Hotel::DateRange.new(start_date,end_date) available_rooms = find_availabile_rooms(range_created) + # what returns if no match?!!!!! rescue an raised exception???????? + # I want an exception raised if I try to reserve a room during a date range when all rooms are reserved, + # so that I cannot make two reservations for the same room that overlap by date + # I want exception raised when an invalid date range is provided, + # so that I can't make a reservation for an invalid date range + chosen_room_id = available_rooms[0].room_id chosen_room = find_room(chosen_room_id) new_reservation = Hotel::Reservation.new(range_created, chosen_room_id) diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 811d7502b..0f94f7cb8 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -170,6 +170,7 @@ start_date = Date.today + 5 end_date = Date.today + 10 + @reservation_range = Hotel::DateRange.new(start_date, end_date) @new_rs = @coordinator01.make_reservation(start_date, end_date) end @@ -178,10 +179,15 @@ end it "stores the room_id in the Reservation returned" do - puts @new_rs.room_id expect(@new_rs.room_id).must_be_instance_of Integer end + it "reserves a room that will not be part of any other reservation overlapping that date range" do + room_chosen = @coordinator01.find_room(@new_rs.room_id) + (room_chosen.bookings.length - 1).times do |reservation| + expect(reservation.date_range).wont_equal @new_rs.date_range + end + end end describe "#find_room" do From e0085454044d2e88319600a39670c603bf0f5fe2 Mon Sep 17 00:00:00 2001 From: cojenco Date: Wed, 4 Mar 2020 23:14:24 -0800 Subject: [PATCH 25/51] Deleted @reservations container. Only Room holds its reservations. When making a reservation, it will be added to room's tracking collection. --- lib/system_coordinator.rb | 101 ++++++++------- test/system_coordinator_test.rb | 210 ++++++++++++++++---------------- 2 files changed, 159 insertions(+), 152 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index aee661a0f..b0efcf7ac 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -4,86 +4,99 @@ module Hotel class SystemCoordinator - attr_reader :rooms, :reservations + attr_reader :rooms def initialize - @rooms = Array.new(20){|i| Hotel::Room.new(i+1)} #access the list of all of the rooms in the hotel - @reservations = [] + @rooms = build_rooms(20) #access the list of all of the rooms in the hotel + + end + + def build_rooms(quantity) + Array.new(quantity){|i| Hotel::Room.new(i+1)} end + def list_rooms return @rooms end - # method to find list of reservations for a specific date - def find_reservations_by_date (date) - # what returns if no match - reservations_by_date = @reservations.select{|reservation|reservation.date_range.include_date(date)} + + def find_reservations_by_date(date) + reservations_by_date = [] + + @rooms.each do |room| + room.bookings.each do |reservation| + reservations_by_date << reservation if reservation.date_range.include_date(date) + end + end + return reservations_by_date end - # method to access list of reservations for a specified room and a given date range + def find_reservations_room_date(room_id, date_range) - # what returns if no match?!!!! - reservations_room_date = @reservations.select{ - |reservation|reservation.room_id == room_id && reservation.date_range.overlapping(date_range) - } - return reservations_room_date - # alternatively, we can search through the collection of rooms - # selected_room = @rooms.find{|room|room.room_id == room_id} - # reservations_room_date = selected_room.bookings.select{|reservation|reservation.date_range.overlapping(date_range)} + selected_room = find_room(room_id) + reservations_room_date = selected_room.bookings.select{|reservation|reservation.date_range.overlapping(date_range)} + return reservations_room_date #what returns if no match? end + def find_reservations_range(given_range) - # what returns if no match?!!!!! - reservations_range = @reservations.select{|reservation|reservation.date_range.overlapping(given_range)} + reservations_range = [] + + @rooms.each do |room| + room.bookings.each do |reservation| + reservations_range << reservation if reservation.date_range.overlapping(given_range) + end + end + return reservations_range end - # method to view a list of rooms that are not reserved for a given date range - def find_availabile_rooms(given_range) - available_rooms = [] - unavailabes = find_reservations_range(given_range) - # what returns if no match?!!!!! rescue an raised exception???????? - unavailable_room_ids = unavailabes.map do |reservation| - reservation.room_id - end - unavailable_room_ids.each do |id| - available_rooms = @rooms.reject{|room|room.room_id == id} + def find_availabile_rooms(given_range) + available_rooms = @rooms.reject do |room| + room.bookings.any? do |reservation| + reservation.date_range.overlapping(given_range) == true + end end return available_rooms end - # method to find room + def find_room(given_room_id) room_found = @rooms.find{|room|room.room_id == given_room_id} return room_found end + - # method to make reservation def make_reservation(start_date, end_date) range_created = Hotel::DateRange.new(start_date,end_date) available_rooms = find_availabile_rooms(range_created) - - # what returns if no match?!!!!! rescue an raised exception???????? - # I want an exception raised if I try to reserve a room during a date range when all rooms are reserved, - # so that I cannot make two reservations for the same room that overlap by date - # I want exception raised when an invalid date range is provided, - # so that I can't make a reservation for an invalid date range - - chosen_room_id = available_rooms[0].room_id - chosen_room = find_room(chosen_room_id) - new_reservation = Hotel::Reservation.new(range_created, chosen_room_id) + raise ArgumentError if available_rooms == [] - @reservations << new_reservation + chosen_room = available_rooms.shift + new_reservation = Hotel::Reservation.new(range_created, chosen_room.room_id) + chosen_room.add_booking_to_room(new_reservation) return new_reservation end - - # handle/ rescue exceptions - # edge cases end end + + + + # # handle/ rescue exceptions + # # edge cases + # end +# end + + + + # what returns if no match?!!!!! rescue an raised exception???????? + # I want an exception raised if I try to reserve a room during a date range when all rooms are reserved, + # so that I cannot make two reservations for the same room that overlap by date + # I want exception raised when an invalid date range is provided, + # so that I can't make a reservation for an invalid date range \ No newline at end of file diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 0f94f7cb8..98f681d74 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -28,34 +28,12 @@ expect(room.cost).must_equal 200.00 end end - end - - describe "@reservations" do - before do - date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) - @room_id = 10 - @reservation01 = Hotel::Reservation.new(date_range, @room_id) - @coordinator01.reservations << @reservation01 - end - # let (:reservation01) { - # Hotel::Reservation.new(Hotel::DateRange.new(Date.today + 5, Date.today + 10), 10) - # } - - it "returns an array of reservations that include that date" do - expect(@coordinator01.reservations).must_be_instance_of Array - end - it "stores Reservation instances in each element of @reservations" do - @coordinator01.reservations.each do |reservation| - expect(reservation).must_be_instance_of Hotel::Reservation - expect(reservation.date_range).must_be_instance_of Hotel::DateRange - expect(reservation.room_id).must_equal @room_id + it "stores an array of its reservations" do + @coordinator01.rooms.each do |room| + expect(room.bookings).must_be_instance_of Array end end - - it "stores the correct room_id in each of the Reservation instances" do - expect(@coordinator01.reservations[0].room_id).must_equal @room_id - end end describe "#list_rooms" do @@ -71,133 +49,149 @@ end end - describe "#find_reservations_by_date" do - before do - date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) - @room_id = 10 - @reservation01 = Hotel::Reservation.new(date_range, @room_id) - @coordinator01.reservations << @reservation01 - @found_reservations = @coordinator01.find_reservations_by_date(Date.today + 7) + describe "#find_availabile_rooms" do + before do + @start_date = Date.today + 5 + @end_date = Date.today + 10 + @date_range = Hotel::DateRange.new(@start_date,@end_date) end it "returns an array" do - expect(@found_reservations).must_be_instance_of Array - # expect(@coordinator01.find_reservation_by_date(date10)).must_be_instance_of Array - end - - it "returns what? when the date is not included" do - date11 = Date.today + 1 - expect(@coordinator01.find_reservations_by_date(date11)).must_equal [] + available_rooms = @coordinator01.find_availabile_rooms(@date_range) + expect(available_rooms).must_be_instance_of Array end - it "stores Reservation instances in the returned array" do - @found_reservations.each do |reservation| - expect(reservation).must_be_instance_of Hotel::Reservation + it "stores Room instances in the array" do + available_rooms = @coordinator01.find_availabile_rooms(@date_range) + available_rooms.each do |room| + expect(room).must_be_instance_of Hotel::Room end end - end - describe "#find_reservations_room_date" do - before do - @room_id = 10 - @room01 = Hotel::Room.new(@room_id) - - @date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) - @reservation01 = Hotel::Reservation.new(@date_range, @room_id) - @coordinator01.reservations << @reservation01 - @room01.add_booking_to_room(@reservation01) - - @reservation_list = @coordinator01.find_reservations_room_date(@room_id, @date_range) + it "returns the correct number of available rooms when there are no reservations" do + available_rooms = @coordinator01.find_availabile_rooms(@date_range) + expect(available_rooms.length).must_equal 20 end - it "returns an array of reservations" do - expect(@reservation_list).must_be_instance_of Array + it "returns the correct number of available rooms when there are reservations" do + @coordinator01.make_reservation(@start_date, @end_date) + @coordinator01.make_reservation(@start_date, @end_date) + @coordinator01.make_reservation(Date.today + 10, Date.today + 12) + @coordinator01.make_reservation(Date.today + 1, Date.today + 2) + available_rooms = @coordinator01.find_availabile_rooms(@date_range) + expect(available_rooms.length).must_equal 18 end - it "stores Reservation instances in each element of the array" do - @reservation_list.each do |reservation| - expect(reservation).must_be_instance_of Hotel::Reservation + it "should not include rooms that have reservations in the given date_range" do + @coordinator01.make_reservation(@start_date, @end_date) + available_rooms = @coordinator01.find_availabile_rooms(@date_range) + available_rooms.each do |room| + room.bookings.each do |booking| + expect(booking.date_range.overlapping(@date_range)).must_equal false + end end end end - describe "#find_availabile_rooms" do + describe "#make_reservation" do before do - @room_id = 10 - @room01 = Hotel::Room.new(@room_id) - - @date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) - @reservation01 = Hotel::Reservation.new(@date_range, @room_id) - @coordinator01.reservations << @reservation01 - @room01.add_booking_to_room(@reservation01) - - @available_rooms = @coordinator01.find_availabile_rooms(@date_range) + @start_date = Date.today + 5 + @end_date = Date.today + 10 + @date_range = Hotel::DateRange.new(@start_date,@end_date) end - it "returns an array" do - expect(@available_rooms).must_be_instance_of Array + it "returns a Reservation" do + new_reservation = @coordinator01.make_reservation(@start_date, @end_date) + expect(new_reservation).must_be_instance_of Hotel::Reservation end - it "stores Room instances in the array" do - @available_rooms.each do |room| - expect(room).must_be_instance_of Hotel::Room - end + it "stores the room_id in the Reservation returned" do + new_reservation = @coordinator01.make_reservation(@start_date, @end_date) + expect(new_reservation.room_id).must_equal 1 end + end - it "represents number of rooms as the size of the array" do - expect(@available_rooms.length).must_equal 19 + describe "#find_room" do + it "returns an instance of Room" do + expect(@coordinator01.find_room(10)).must_be_instance_of Hotel::Room end - it "should not include rooms that have reservations in the given date_range" do - @available_rooms.each do |room| - room.bookings.each do |booking| - expect(booking.date_range.overlapping(@date_range)).must_equal false - end - end + it "returns nil??? if an invalid room_id is passed in" do + expect(@coordinator01.find_room(999)).must_be_nil end end - describe "#make_reservation" do + describe "#find_reservations_by_date" do before do - room01 = Hotel::Room.new(10) - date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) - reservation01 = Hotel::Reservation.new(date_range, 10) - room01.add_booking_to_room(reservation01) - @coordinator01.reservations << reservation01 - - - start_date = Date.today + 5 end_date = Date.today + 10 - @reservation_range = Hotel::DateRange.new(start_date, end_date) - @new_rs = @coordinator01.make_reservation(start_date, end_date) + @coordinator01.make_reservation(start_date, end_date) end - it "returns a Reservation" do - expect(@new_rs).must_be_instance_of Hotel::Reservation + it "returns an array" do + date10 = Date.today + 7 + expect(@coordinator01.find_reservations_by_date(date10)).must_be_instance_of Array end - it "stores the room_id in the Reservation returned" do - expect(@new_rs.room_id).must_be_instance_of Integer + it "returns empty array when the date is not included" do + date11 = Date.today + 1 + expect(@coordinator01.find_reservations_by_date(date11)).must_equal [] end - it "reserves a room that will not be part of any other reservation overlapping that date range" do - room_chosen = @coordinator01.find_room(@new_rs.room_id) - (room_chosen.bookings.length - 1).times do |reservation| - expect(reservation.date_range).wont_equal @new_rs.date_range + it "stores Reservation instances in the returned array" do + date10 = Date.today + 7 + found_reservations = @coordinator01.find_reservations_by_date(date10) + found_reservations.each do |reservation| + expect(reservation).must_be_instance_of Hotel::Reservation end end end - describe "#find_room" do - it "returns an instance of Room" do - expect(@coordinator01.find_room(10)).must_be_instance_of Hotel::Room + describe "#find_reservations_room_date" do + before do + @start_date = Date.today + 5 + @end_date = Date.today + 10 + @date_range = Hotel::DateRange.new(@start_date,@end_date) + new_reservation = @coordinator01.make_reservation(@start_date, @end_date) + @room_id = new_reservation.room_id end - it "returns nil??? if an invalid room_id is passed in" do - expect(@coordinator01.find_room(999)).must_be_nil + it "returns an array of reservations" do + reservation_list = @coordinator01.find_reservations_room_date(@room_id,@date_range) + expect(reservation_list).must_be_instance_of Array + end + + it "stores Reservation instances in each element of the array" do + reservation_list = @coordinator01.find_reservations_room_date(@room_id,@date_range) + reservation_list.each do |reservation| + expect(reservation).must_be_instance_of Hotel::Reservation + end end end -end \ No newline at end of file + describe "#find_reservations_range" do + before do + @start_date = Date.today + 5 + @end_date = Date.today + 10 + @date_range = Hotel::DateRange.new(@start_date,@end_date) + @coordinator01.make_reservation(@start_date, @end_date) + end + + it "returns an array of reservations" do + reservations_range = @coordinator01.find_reservations_range(@date_range) + expect(reservations_range).must_be_instance_of Array + expect(reservations_range.length).must_equal 1 + end + + it "returns the correct quantity of reservations" do + @coordinator01.make_reservation(Date.today + 5, Date.today + 6) + @coordinator01.make_reservation(Date.today + 8, Date.today + 18) + reservations_range = @coordinator01.find_reservations_range(@date_range) + expect(reservations_range).must_be_instance_of Array + expect(reservations_range.length).must_equal 3 + end + end +end + + From 86d90f6f543e2b26d26e9b0aaba80c667765db9e Mon Sep 17 00:00:00 2001 From: cojenco Date: Wed, 4 Mar 2020 23:15:18 -0800 Subject: [PATCH 26/51] Switched #get_price from Reservation to Room class. Revised tests. --- lib/reservation.rb | 15 ++++++--------- lib/room.rb | 8 +++++++- test/reservation_test.rb | 15 ++++++++------- test/room_test.rb | 37 ++++++++++++++++++++++++++++++------- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 3aece6d8d..b668424f0 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,7 +2,7 @@ module Hotel class Reservation - attr_reader :id, :start_date, :end_date, :date_range, :room_id, :hotel_block_id + attr_reader :id, :start_date, :end_date, :date_range, :room_id @@next_id = 1 @@ -19,14 +19,6 @@ def initialize(date_range, room_id) # @hotel_block_id = -1 end - - def get_price - price = date_range.count_nights * 200.00 #should require relative room and take room.cost - return price - end - - # def self.find(date_range) - end end @@ -47,4 +39,9 @@ def get_price # @id = @@next_id # @@next_id += 1 # # @hotel_block_id +# end + +# def get_price +# price = date_range.count_nights * 200.00 #should require relative room and take room.cost +# return price # end \ No newline at end of file diff --git a/lib/room.rb b/lib/room.rb index 7fa707693..3b0f7d8df 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -2,7 +2,8 @@ module Hotel class Room - attr_reader :room_id, :cost, :bookings + attr_reader :room_id,:bookings + attr_accessor :cost def initialize(room_id, cost = 200.00, bookings = nil) raise ArgumentError if !room_id.is_a? Integer @@ -15,6 +16,11 @@ def initialize(room_id, cost = 200.00, bookings = nil) def add_booking_to_room(new_reservation) @bookings << new_reservation end + + def get_price(reservation) + price = reservation.date_range.count_nights * cost + return price + end end end diff --git a/test/reservation_test.rb b/test/reservation_test.rb index 818fd6abb..7c19b6ffd 100644 --- a/test/reservation_test.rb +++ b/test/reservation_test.rb @@ -30,16 +30,17 @@ expect(@reservation01.date_range.end_date).must_be_instance_of Date end end - - describe "#get_price" do - it "returns the total price for the reservation" do - expect(@reservation01.get_price).must_be_instance_of Float - expect(@reservation01.get_price).must_equal 1000.00 - end - end end + # describe "#get_price" do + # it "returns the total price for the reservation" do + # expect(@reservation01.get_price).must_be_instance_of Float + # expect(@reservation01.get_price).must_equal 1000.00 + # end + # end + + # describe Hotel::Reservation do # before do # start_date = Date.today + 5 diff --git a/test/room_test.rb b/test/room_test.rb index 6d49e9a47..afbd8e2a8 100644 --- a/test/room_test.rb +++ b/test/room_test.rb @@ -24,22 +24,30 @@ expect(@room01.cost).must_be_instance_of Float expect(@room01.cost).must_equal 200.00 end + end - it "stores an instance variable @reservations that is an array" do + describe "@bookings" do + before do + date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + @reservation01 = Hotel::Reservation.new(date_range, @room_id) + @room01.add_booking_to_room(@reservation01) + end + + it "stores an instance variable @bookings that is an array" do expect(@room01.bookings).must_be_instance_of Array end - # it "stores an @reservations array where each element is a Reservation instance " do - # expect(@room01.bookings[0]).must_be_instance_of Hotel::Reservation - # end - + it "stores each element as a Reservation instance " do + @room01.bookings.each do |reservation| + expect(reservation).must_be_instance_of Hotel::Reservation + end + end end describe "#add_booking_to_room" do before do date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) - room_id = 10 - @reservation01 = Hotel::Reservation.new(date_range, room_id) + @reservation01 = Hotel::Reservation.new(date_range, @room_id) end it "returns an array of all the current bookings" do @@ -55,6 +63,21 @@ after_size = (@room01.add_booking_to_room(@reservation01)).length expect(after_size).must_equal before_size + 1 end + end + + describe "#get_price" do + before do + date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + @reservation01 = Hotel::Reservation.new(date_range, @room_id) + @room01.add_booking_to_room(@reservation01) + end + it "returns a Float for the reservation" do + expect(@room01.get_price(@reservation01)).must_be_instance_of Float + end + + it "returns the total price for the reservation" do + expect(@room01.get_price(@reservation01)).must_equal 1000.00 + end end end \ No newline at end of file From 9667db6d03a83e2dc0bb3e2c0ada14e9e214bb24 Mon Sep 17 00:00:00 2001 From: cojenco Date: Wed, 4 Mar 2020 23:29:58 -0800 Subject: [PATCH 27/51] Added SystemCoordinator#build_rooms method for the constructor. Added tests. --- lib/system_coordinator.rb | 15 +++++---------- test/system_coordinator_test.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index b0efcf7ac..bdf97dcea 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -6,11 +6,11 @@ module Hotel class SystemCoordinator attr_reader :rooms - def initialize - @rooms = build_rooms(20) #access the list of all of the rooms in the hotel - + def initialize(room_quantity = 20) + @rooms = build_rooms(room_quantity) end + def build_rooms(quantity) Array.new(quantity){|i| Hotel::Room.new(i+1)} end @@ -87,13 +87,8 @@ def make_reservation(start_date, end_date) end - - # # handle/ rescue exceptions - # # edge cases - # end -# end - - + # handle/ rescue exceptions + # edge cases i.e. what happens if no match? # what returns if no match?!!!!! rescue an raised exception???????? # I want an exception raised if I try to reserve a room during a date range when all rooms are reserved, diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 98f681d74..2ef44ae1c 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -36,6 +36,21 @@ end end + describe "#build_rooms" do + it "returns an array" do + quantity = 5 + expect(@coordinator01.build_rooms(quantity)).must_be_instance_of Array + expect(@coordinator01.build_rooms(quantity).length).must_equal quantity + end + + it "stores Room instance in each element" do + built01 = @coordinator01.build_rooms(5) + built01.each do |room| + expect(room).must_be_instance_of Hotel::Room + end + end + end + describe "#list_rooms" do it "returns an Array with size of 20" do expect(@coordinator01.list_rooms).must_be_instance_of Array From eb2d44d818f61d9554e490d66cc1b975958cbbdb Mon Sep 17 00:00:00 2001 From: cojenco Date: Wed, 4 Mar 2020 23:33:25 -0800 Subject: [PATCH 28/51] Revised @cost to be attr_accessor in Room class. --- lib/room.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/room.rb b/lib/room.rb index 3b0f7d8df..2ed850339 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -21,6 +21,5 @@ def get_price(reservation) price = reservation.date_range.count_nights * cost return price end - end end From d85a9d3fbcc7e883b990a79249f717bc9af175fe Mon Sep 17 00:00:00 2001 From: cojenco Date: Wed, 4 Mar 2020 23:48:15 -0800 Subject: [PATCH 29/51] Formatting and adding comments. --- lib/date_range.rb | 1 - lib/system_coordinator.rb | 10 +--------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 3ec01e2ef..f2f2a16e1 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -40,6 +40,5 @@ def overlapping(other_range) return false end end - end end diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index bdf97dcea..a14b4b23a 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -10,17 +10,14 @@ def initialize(room_quantity = 20) @rooms = build_rooms(room_quantity) end - def build_rooms(quantity) Array.new(quantity){|i| Hotel::Room.new(i+1)} end - def list_rooms return @rooms end - def find_reservations_by_date(date) reservations_by_date = [] @@ -33,14 +30,12 @@ def find_reservations_by_date(date) return reservations_by_date end - def find_reservations_room_date(room_id, date_range) selected_room = find_room(room_id) reservations_room_date = selected_room.bookings.select{|reservation|reservation.date_range.overlapping(date_range)} return reservations_room_date #what returns if no match? end - def find_reservations_range(given_range) reservations_range = [] @@ -53,10 +48,9 @@ def find_reservations_range(given_range) return reservations_range end - def find_availabile_rooms(given_range) available_rooms = @rooms.reject do |room| - room.bookings.any? do |reservation| + room.bookings.any? do |reservation| #returns true if there are overlapping reservations reservation.date_range.overlapping(given_range) == true end end @@ -64,12 +58,10 @@ def find_availabile_rooms(given_range) return available_rooms end - def find_room(given_room_id) room_found = @rooms.find{|room|room.room_id == given_room_id} return room_found end - def make_reservation(start_date, end_date) range_created = Hotel::DateRange.new(start_date,end_date) From e8b9edb278066471280ca5db1d847e42c8cc8746 Mon Sep 17 00:00:00 2001 From: cojenco Date: Thu, 5 Mar 2020 16:39:34 -0800 Subject: [PATCH 30/51] Added tests for SystemCoordinator. --- lib/system_coordinator.rb | 1 + test/system_coordinator_test.rb | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index a14b4b23a..a429927b3 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -18,6 +18,7 @@ def list_rooms return @rooms end + # below method needs to also show me the reservations made from hotel block def find_reservations_by_date(date) reservations_by_date = [] diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 2ef44ae1c..4bfd4e2a3 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -91,11 +91,12 @@ it "returns the correct number of available rooms when there are reservations" do @coordinator01.make_reservation(@start_date, @end_date) - @coordinator01.make_reservation(@start_date, @end_date) + expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 19 @coordinator01.make_reservation(Date.today + 10, Date.today + 12) @coordinator01.make_reservation(Date.today + 1, Date.today + 2) - available_rooms = @coordinator01.find_availabile_rooms(@date_range) - expect(available_rooms.length).must_equal 18 + expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 19 + @coordinator01.make_reservation(@start_date, @end_date) + expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 18 end it "should not include rooms that have reservations in the given date_range" do @@ -107,6 +108,14 @@ end end end + + it "returns an empty array when there are no rooms available" do + 20.times do + @coordinator01.make_reservation(@start_date, @end_date) + end + available_rooms = @coordinator01.find_availabile_rooms(@date_range) + expect(available_rooms).must_equal [] + end end describe "#make_reservation" do @@ -125,6 +134,13 @@ new_reservation = @coordinator01.make_reservation(@start_date, @end_date) expect(new_reservation.room_id).must_equal 1 end + + it "raises ArgumentError when there are no rooms available" do + 20.times do + @coordinator01.make_reservation(@start_date, @end_date) + end + expect{@coordinator01.make_reservation(@start_date, @end_date)}.must_raise ArgumentError + end end describe "#find_room" do From c997c2c80922f376d2a2b27be3d7d5d49d595fea Mon Sep 17 00:00:00 2001 From: cojenco Date: Thu, 5 Mar 2020 16:41:47 -0800 Subject: [PATCH 31/51] Created a NoAvailabilityError class and yet to implement. --- lib/no_availability_error.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lib/no_availability_error.rb diff --git a/lib/no_availability_error.rb b/lib/no_availability_error.rb new file mode 100644 index 000000000..7bda955ee --- /dev/null +++ b/lib/no_availability_error.rb @@ -0,0 +1,3 @@ + +class NoAvailabilityError < StandardError +end \ No newline at end of file From 8a8177c8a1a0fe5650acf55ebced0a12cb96d57c Mon Sep 17 00:00:00 2001 From: cojenco Date: Thu, 5 Mar 2020 16:43:54 -0800 Subject: [PATCH 32/51] Added Block class and test file and updated test helper. --- lib/block.rb | 38 ++++++++++++++++++++++++++++++++++++++ test/block_test.rb | 4 ++++ test/test_helper.rb | 4 +++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 lib/block.rb create mode 100644 test/block_test.rb diff --git a/lib/block.rb b/lib/block.rb new file mode 100644 index 000000000..d9f796df9 --- /dev/null +++ b/lib/block.rb @@ -0,0 +1,38 @@ +require_relative 'room' +require_relative 'date_range' +require_relative 'reservation' + +module Hotel + class Block + + def initialize(date_range,room_id_array,cost) + # raise Exception if any of the rooms is not availalbe in the given range + + end + + + ##method## I can check whether a given block has any rooms available + # def check_block_vacancy + + + # A block can contain a maximum of 5 rooms + # date_range has to be exactly the same + + #I can create a Hotel Block if I give a date range, collection of rooms, and a discounted room rate + + # A block can contain a maximum of 5 rooms + # When a room is reserved from a block of rooms, the reservation dates will always match the date range of the block + # All of the availability checking logic from Wave 2 should now respect room blocks as well as individual reservations + + end +end + + +# I can create a Hotel Block if I give a date range, collection of rooms, and a discounted room rate +# I want an exception raised if I try to create a Hotel Block and at least one of the rooms is unavailable for the given date range +# Given a specific date, and that a room is set aside in a hotel block for that specific date, I cannot reserve that specific room for that specific date, because it is unavailable +# Given a specific date, and that a room is set aside in a hotel block for that specific date, I cannot create another hotel block that includes that specific room for that specific date, because it is unavailable +# I can check whether a given block has any rooms available +# I can reserve a specific room from a hotel block +# I can only reserve that room from a hotel block for the full duration of the block +# I can see a reservation made from a hotel block from the list of reservations for that date (see wave 1 requirements) \ No newline at end of file diff --git a/test/block_test.rb b/test/block_test.rb new file mode 100644 index 000000000..d84e7ccc8 --- /dev/null +++ b/test/block_test.rb @@ -0,0 +1,4 @@ +require_relative 'test_helper' + +describe Hotel::Block do +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index e9d53731f..0201aca79 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,4 +15,6 @@ require_relative '../lib/date_range' require_relative '../lib/reservation' require_relative '../lib/system_coordinator' -require_relative '../lib/room' \ No newline at end of file +require_relative '../lib/room' +require_relative '../lib/no_availability_error' +require_relative '../lib/block' From a42701230294bfd9ec5c755f798faf7e96c2cc96 Mon Sep 17 00:00:00 2001 From: cojenco Date: Thu, 5 Mar 2020 18:30:28 -0800 Subject: [PATCH 33/51] Initial version for Wave2. Design thoughts and psuedocode starting Wave3. --- lib/block.rb | 56 ++++++++++++++++++++++++++++++++++++++++------ lib/reservation.rb | 2 +- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index d9f796df9..3eea3b81e 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -2,19 +2,62 @@ require_relative 'date_range' require_relative 'reservation' -module Hotel - class Block - def initialize(date_range,room_id_array,cost) - # raise Exception if any of the rooms is not availalbe in the given range +module Hotel + class Block < Reservation + def initialize(date_range, room_id, block) + super(date_range,room_id) + + @block = block end + end +end +# Scenario 1: +# Block < Reservation +# Coordinator#find_available_rooms: +# loop through each room +# status = true #room is available +# loop through each reservation per room +# if rs.class == Hotel::Block +# if date_range overlap && rs.date_range is not the exact given date_range +# status = false +# break +# end +# else +# if rs.date_range overlaps +# status = false +# end +# end +# unavailables << room if status == false + +# Scenario 2: +# Reservation Class add extra attribute @block +# Coordinator#find_available_rooms: +# loop through each room +# status = true #room is available +# if room.bookings.empty? == false +# loop through each reservation per room +# if rs.block < 0 +# if rs.date_range overlap && rs.date_range is not the exact given date_range +# status = false +# break +# end +# else +# if rs.date_range overlaps +# status = false +# end +# end +# unavailables << room if status == false +# end + + + ##method## I can check whether a given block has any rooms available # def check_block_vacancy - # A block can contain a maximum of 5 rooms # date_range has to be exactly the same @@ -24,8 +67,7 @@ def initialize(date_range,room_id_array,cost) # When a room is reserved from a block of rooms, the reservation dates will always match the date range of the block # All of the availability checking logic from Wave 2 should now respect room blocks as well as individual reservations - end -end + # I can create a Hotel Block if I give a date range, collection of rooms, and a discounted room rate diff --git a/lib/reservation.rb b/lib/reservation.rb index b668424f0..8e48be1c5 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -17,7 +17,7 @@ def initialize(date_range, room_id) @id = @@next_id @@next_id += 1 - # @hotel_block_id = -1 + # @block = -1 end end end From 36551ca778d0555611bd68f5d9f9c4d035d06ed2 Mon Sep 17 00:00:00 2001 From: cojenco Date: Thu, 5 Mar 2020 18:32:07 -0800 Subject: [PATCH 34/51] Added comments. --- lib/block.rb | 22 +++++++++++----------- test/block_test.rb | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 3eea3b81e..c8fc442ef 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -1,18 +1,18 @@ -require_relative 'room' -require_relative 'date_range' -require_relative 'reservation' +# require_relative 'room' +# require_relative 'date_range' +# require_relative 'reservation' -module Hotel - class Block < Reservation +# module Hotel +# class Block < Reservation - def initialize(date_range, room_id, block) - super(date_range,room_id) +# def initialize(date_range, room_id, block) +# super(date_range,room_id) - @block = block - end - end -end +# @block = block +# end +# end +# end # Scenario 1: # Block < Reservation diff --git a/test/block_test.rb b/test/block_test.rb index d84e7ccc8..22cfffd7a 100644 --- a/test/block_test.rb +++ b/test/block_test.rb @@ -1,4 +1,4 @@ -require_relative 'test_helper' +# require_relative 'test_helper' -describe Hotel::Block do -end \ No newline at end of file +# describe Hotel::Block do +# end \ No newline at end of file From c65c3084e8855a34b5c598ac228b44feba1fbca5 Mon Sep 17 00:00:00 2001 From: cojenco Date: Thu, 5 Mar 2020 21:20:56 -0800 Subject: [PATCH 35/51] Revised Reservation to be superclass. Added @cost instance variable and #get_total_price method. --- lib/reservation.rb | 16 +++++++++++++--- test/reservation_test.rb | 13 +++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 8e48be1c5..ce94ad9c0 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -3,26 +3,36 @@ module Hotel class Reservation attr_reader :id, :start_date, :end_date, :date_range, :room_id + attr_accessor :cost @@next_id = 1 - def initialize(date_range, room_id) + def initialize(date_range, room_id, cost = 200.00) @date_range = date_range @start_date = date_range.start_date @end_date = date_range.end_date @room_id = room_id - #do i want to also know about the room instance? + @cost = cost @id = @@next_id @@next_id += 1 - # @block = -1 + # @block = -1 #another way is to give a hotel block attribute end + + def get_total_price + total_price = date_range.count_nights * cost + return total_price + end + end end + + + # attr_reader :id, :start_date, :end_date, :date_range, :room_id # @@next_id = 1 diff --git a/test/reservation_test.rb b/test/reservation_test.rb index 7c19b6ffd..17305dc3b 100644 --- a/test/reservation_test.rb +++ b/test/reservation_test.rb @@ -30,15 +30,16 @@ expect(@reservation01.date_range.end_date).must_be_instance_of Date end end + + describe "#get_total_price" do + it "returns the total price for the reservation" do + expect(@reservation01.get_total_price).must_be_instance_of Float + expect(@reservation01.get_total_price).must_equal 1000.00 + end + end end - # describe "#get_price" do - # it "returns the total price for the reservation" do - # expect(@reservation01.get_price).must_be_instance_of Float - # expect(@reservation01.get_price).must_equal 1000.00 - # end - # end # describe Hotel::Reservation do From 1b6312125e4937e772414081f2046b4b1b48e14f Mon Sep 17 00:00:00 2001 From: cojenco Date: Thu, 5 Mar 2020 21:21:57 -0800 Subject: [PATCH 36/51] Block class inherits from Reservation. Built constructor and tests. --- lib/block.rb | 31 +++++++++++++++---------- test/block_test.rb | 58 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index c8fc442ef..bfa6caaf3 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -1,19 +1,26 @@ -# require_relative 'room' -# require_relative 'date_range' -# require_relative 'reservation' +require_relative 'room' +require_relative 'date_range' +require_relative 'reservation' -# module Hotel -# class Block < Reservation +module Hotel + class Block < Reservation + attr_reader :block -# def initialize(date_range, room_id, block) -# super(date_range,room_id) - -# @block = block -# end -# end -# end + def initialize(date_range, room_id, block = 0, cost = 200.00) + + super(date_range, room_id, cost) + @block = block + + end + end +end + + + + + # Scenario 1: # Block < Reservation # Coordinator#find_available_rooms: diff --git a/test/block_test.rb b/test/block_test.rb index 22cfffd7a..aedcccbd2 100644 --- a/test/block_test.rb +++ b/test/block_test.rb @@ -1,4 +1,56 @@ -# require_relative 'test_helper' +require_relative 'test_helper' -# describe Hotel::Block do -# end \ No newline at end of file +describe Hotel::Block do + before do + @date_range = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + @roomid01 = 1 + @roomid02 = 2 + end + + describe "#initialize" do + it "creates an instance of a Block class" do + block01 = Hotel::Block.new(@date_range, @roomid01, 10) + expect(block01).must_be_instance_of Hotel::Block + end + + it "stores the correct room_id in the reservation" do + block01 = Hotel::Block.new(@date_range, @roomid01, 10) + expect(block01.room_id).must_be_instance_of Integer + expect(block01.room_id).must_equal @roomid01 + end + + it "stores a date_range that is an instance of DateRange" do + block01 = Hotel::Block.new(@date_range, @roomid01, 10) + expect(block01.date_range).must_be_instance_of Hotel::DateRange + end + + it "stores start_date and end_date that are both an instance of Date" do + block01 = Hotel::Block.new(@date_range, @roomid01, 10) + expect(block01.date_range.start_date).must_be_instance_of Date + expect(block01.date_range.end_date).must_be_instance_of Date + end + + it "shares the same block id for multiple rooms within the block" do + block01 = Hotel::Block.new(@date_range, @roomid01, 10) + block02 = Hotel::Block.new(@date_range, @roomid02, 10) + expect(block01.block).must_equal 10 + expect(block02.block).must_equal 10 + end + + it "stores an attribute @cost that reflects the correct cost" do + block01 = Hotel::Block.new(@date_range, @roomid01, 10) + expect(block01.cost).must_equal 200.00 + block02 = Hotel::Block.new(@date_range, @roomid02, 11, 100.00) + expect(block02.cost).must_equal 100.00 + end + end + + describe "#get_total_price" do + it "returns the total price for the reservation" do + block01 = Hotel::Block.new(@date_range, @roomid01, 10) + expect(block01.get_total_price).must_equal 1000.00 + block02 = Hotel::Block.new(@date_range, @roomid02, 11, 100.00) + expect(block02.get_total_price).must_equal 500.00 + end + end +end \ No newline at end of file From ee8f691c5c7125ca177af62831935661d7229a78 Mon Sep 17 00:00:00 2001 From: cojenco Date: Fri, 6 Mar 2020 15:05:36 -0800 Subject: [PATCH 37/51] Added #exactly_matching method and tests. --- lib/date_range.rb | 9 +++++++++ test/daterange_test.rb | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/date_range.rb b/lib/date_range.rb index f2f2a16e1..0db4faaf0 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -40,5 +40,14 @@ def overlapping(other_range) return false end end + + def exactly_matching(other_range) + if @start_date == other_range.start_date && @end_date == other_range.end_date + return true + else + return false + end + end + end end diff --git a/test/daterange_test.rb b/test/daterange_test.rb index 9b4ba28e2..9102b808f 100644 --- a/test/daterange_test.rb +++ b/test/daterange_test.rb @@ -116,4 +116,21 @@ expect(@range01.overlapping(range08)).must_equal false end end + + describe "#exactly_matching" do + it "returns true if the date range exactly matches" do + range21 = Hotel::DateRange.new(Date.today + 5, Date.today + 10) + expect(@range01.exactly_matching(range21)).must_equal true + end + + it "returns false if the date range is not an exact match" do + range03 = Hotel::DateRange.new(Date.today + 6, Date.today + 8) + expect(@range01.exactly_matching(range03)).must_equal false + range04 = Hotel::DateRange.new(Date.today + 5, Date.today + 6) + expect(@range01.exactly_matching(range04)).must_equal false + range05 = Hotel::DateRange.new(Date.today+8, Date.today+20) + expect(@range01.exactly_matching(range05)).must_equal false + end + + end end From 2f46e39c1554c6d4609f4b6f1eabf4a8625f186b Mon Sep 17 00:00:00 2001 From: cojenco Date: Fri, 6 Mar 2020 15:07:16 -0800 Subject: [PATCH 38/51] Renamed block_id and restored back to original naming. --- lib/block.rb | 2 +- test/block_test.rb | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index bfa6caaf3..4bc85ac2d 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -7,7 +7,7 @@ module Hotel class Block < Reservation attr_reader :block - def initialize(date_range, room_id, block = 0, cost = 200.00) + def initialize(date_range, room_id, cost = 200.00, block = 0) super(date_range, room_id, cost) @block = block diff --git a/test/block_test.rb b/test/block_test.rb index aedcccbd2..421c59bf5 100644 --- a/test/block_test.rb +++ b/test/block_test.rb @@ -9,47 +9,47 @@ describe "#initialize" do it "creates an instance of a Block class" do - block01 = Hotel::Block.new(@date_range, @roomid01, 10) + block01 = Hotel::Block.new(@date_range, @roomid01) expect(block01).must_be_instance_of Hotel::Block end it "stores the correct room_id in the reservation" do - block01 = Hotel::Block.new(@date_range, @roomid01, 10) + block01 = Hotel::Block.new(@date_range, @roomid01) expect(block01.room_id).must_be_instance_of Integer expect(block01.room_id).must_equal @roomid01 end it "stores a date_range that is an instance of DateRange" do - block01 = Hotel::Block.new(@date_range, @roomid01, 10) + block01 = Hotel::Block.new(@date_range, @roomid01) expect(block01.date_range).must_be_instance_of Hotel::DateRange end it "stores start_date and end_date that are both an instance of Date" do - block01 = Hotel::Block.new(@date_range, @roomid01, 10) + block01 = Hotel::Block.new(@date_range, @roomid01) expect(block01.date_range.start_date).must_be_instance_of Date expect(block01.date_range.end_date).must_be_instance_of Date end it "shares the same block id for multiple rooms within the block" do - block01 = Hotel::Block.new(@date_range, @roomid01, 10) - block02 = Hotel::Block.new(@date_range, @roomid02, 10) + block01 = Hotel::Block.new(@date_range, @roomid01, 100, 10) + block02 = Hotel::Block.new(@date_range, @roomid02, 100, 10) expect(block01.block).must_equal 10 expect(block02.block).must_equal 10 end it "stores an attribute @cost that reflects the correct cost" do - block01 = Hotel::Block.new(@date_range, @roomid01, 10) + block01 = Hotel::Block.new(@date_range, @roomid01, 200,10) expect(block01.cost).must_equal 200.00 - block02 = Hotel::Block.new(@date_range, @roomid02, 11, 100.00) + block02 = Hotel::Block.new(@date_range, @roomid02, 100, 11) expect(block02.cost).must_equal 100.00 end end describe "#get_total_price" do it "returns the total price for the reservation" do - block01 = Hotel::Block.new(@date_range, @roomid01, 10) + block01 = Hotel::Block.new(@date_range, @roomid01) expect(block01.get_total_price).must_equal 1000.00 - block02 = Hotel::Block.new(@date_range, @roomid02, 11, 100.00) + block02 = Hotel::Block.new(@date_range, @roomid02, 100) expect(block02.get_total_price).must_equal 500.00 end end From 992909573370c370f97ae789cb384eb34f89caf6 Mon Sep 17 00:00:00 2001 From: cojenco Date: Fri, 6 Mar 2020 15:09:36 -0800 Subject: [PATCH 39/51] Revised methods to integrate the Block class and concept. Revised tests. --- lib/system_coordinator.rb | 50 ++++++++++- test/system_coordinator_test.rb | 147 +++++++++++++++++++++++++++++--- 2 files changed, 184 insertions(+), 13 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index a429927b3..15d0304f5 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -1,11 +1,14 @@ require_relative 'room' require_relative 'date_range' require_relative 'reservation' +require_relative 'no_availability_error' module Hotel class SystemCoordinator attr_reader :rooms + @@next_block = 1 + def initialize(room_quantity = 20) @rooms = build_rooms(room_quantity) end @@ -50,6 +53,30 @@ def find_reservations_range(given_range) end def find_availabile_rooms(given_range) + available_rooms = [] + + @rooms.each do |room| + if room.bookings.empty? + available_rooms << room + else + status = true + room.bookings.each do |item| + if item.class == Hotel::Block + status = false if item.date_range.overlapping(given_range) && item.date_range.exactly_matching(given_range)== false #it is not an exact match #method + elsif item.class == Hotel::Reservation + status = false if item.date_range.overlapping(given_range) + end + end + available_rooms << room if true == status + end + end + + raise NoAvailabilityError.new "No Availability. Please try another date range." if available_rooms == [] + + return available_rooms + end + + def find_block_rooms(given_range) available_rooms = @rooms.reject do |room| room.bookings.any? do |reservation| #returns true if there are overlapping reservations reservation.date_range.overlapping(given_range) == true @@ -64,10 +91,10 @@ def find_room(given_room_id) return room_found end + # yet: def make_reservation(start_date, end_date) range_created = Hotel::DateRange.new(start_date,end_date) available_rooms = find_availabile_rooms(range_created) - raise ArgumentError if available_rooms == [] chosen_room = available_rooms.shift new_reservation = Hotel::Reservation.new(range_created, chosen_room.room_id) @@ -76,6 +103,27 @@ def make_reservation(start_date, end_date) return new_reservation end + + def make_block(date_range, room_quantity, cost) + raise ArgumentError.new "Maximum 5 rooms for a hotel block." if room_quantity > 5 + available_rooms = find_block_rooms(date_range) + raise NoAvailabilityError.new "No availability. Please try another date range." if available_rooms.length < room_quantity + + rooms_in_block = [] + + room_quantity.times do |i| + chosen_room = available_rooms[i] + room_id = chosen_room.room_id + room_block = Hotel::Block.new(date_range,room_id, cost, @@next_block) + chosen_room.add_booking_to_room(room_block) + rooms_in_block << room_block + end + + @@next_block += 1 + + return rooms_in_block + end + end end diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 4bfd4e2a3..01a6cffe4 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -64,7 +64,6 @@ end end - describe "#find_availabile_rooms" do before do @start_date = Date.today + 5 @@ -77,10 +76,10 @@ expect(available_rooms).must_be_instance_of Array end - it "stores Room instances in the array" do + it "stores Room instances or Block instances in the array" do available_rooms = @coordinator01.find_availabile_rooms(@date_range) available_rooms.each do |room| - expect(room).must_be_instance_of Hotel::Room + expect(room).must_be_instance_of Hotel::Room || Hotel::Block end end @@ -109,15 +108,81 @@ end end - it "returns an empty array when there are no rooms available" do + it "returns the correct number of available rooms when there are blocks" do + @coordinator01.make_block(@date_range, 3, 150) + expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 20 + range02 = Hotel::DateRange.new(Date.today + 5, Date.today + 7) + expect(@coordinator01.find_availabile_rooms(range02).length).must_equal 17 + range03 = Hotel::DateRange.new(Date.today + 5, Date.today + 15) + expect(@coordinator01.find_availabile_rooms(range03).length).must_equal 17 + range04 = Hotel::DateRange.new(Date.today + 3, Date.today + 12) + expect(@coordinator01.find_availabile_rooms(range04).length).must_equal 17 + @coordinator01.make_block(@date_range, 5, 100) + expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 20 + expect(@coordinator01.find_availabile_rooms(range02).length).must_equal 12 + end + + it "raises NoAvailabilityError when there are no rooms available" do 20.times do @coordinator01.make_reservation(@start_date, @end_date) end - available_rooms = @coordinator01.find_availabile_rooms(@date_range) - expect(available_rooms).must_equal [] + expect{@coordinator01.make_reservation(@start_date, @end_date)}.must_raise NoAvailabilityError end end + # describe "#find_availabile_rooms" do + # before do + # @start_date = Date.today + 5 + # @end_date = Date.today + 10 + # @date_range = Hotel::DateRange.new(@start_date,@end_date) + # end + + # it "returns an array" do + # available_rooms = @coordinator01.find_availabile_rooms(@date_range) + # expect(available_rooms).must_be_instance_of Array + # end + + # it "stores Room instances in the array" do + # available_rooms = @coordinator01.find_availabile_rooms(@date_range) + # available_rooms.each do |room| + # expect(room).must_be_instance_of Hotel::Room + # end + # end + + # it "returns the correct number of available rooms when there are no reservations" do + # available_rooms = @coordinator01.find_availabile_rooms(@date_range) + # expect(available_rooms.length).must_equal 20 + # end + + # it "returns the correct number of available rooms when there are reservations" do + # @coordinator01.make_reservation(@start_date, @end_date) + # expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 19 + # @coordinator01.make_reservation(Date.today + 10, Date.today + 12) + # @coordinator01.make_reservation(Date.today + 1, Date.today + 2) + # expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 19 + # @coordinator01.make_reservation(@start_date, @end_date) + # expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 18 + # end + + # it "should not include rooms that have reservations in the given date_range" do + # @coordinator01.make_reservation(@start_date, @end_date) + # available_rooms = @coordinator01.find_availabile_rooms(@date_range) + # available_rooms.each do |room| + # room.bookings.each do |booking| + # expect(booking.date_range.overlapping(@date_range)).must_equal false + # end + # end + # end + + # it "returns an empty array when there are no rooms available" do + # 20.times do + # @coordinator01.make_reservation(@start_date, @end_date) + # end + # available_rooms = @coordinator01.find_availabile_rooms(@date_range) + # expect(available_rooms).must_equal [] + # end + # end + describe "#make_reservation" do before do @start_date = Date.today + 5 @@ -135,12 +200,12 @@ expect(new_reservation.room_id).must_equal 1 end - it "raises ArgumentError when there are no rooms available" do - 20.times do - @coordinator01.make_reservation(@start_date, @end_date) - end - expect{@coordinator01.make_reservation(@start_date, @end_date)}.must_raise ArgumentError - end + # it "raises ArgumentError when there are no rooms available" do + # 20.times do + # @coordinator01.make_reservation(@start_date, @end_date) + # end + # expect{@coordinator01.make_reservation(@start_date, @end_date)}.must_raise ArgumentError + # end end describe "#find_room" do @@ -153,6 +218,7 @@ end end + describe "#find_reservations_by_date" do before do start_date = Date.today + 5 @@ -179,6 +245,7 @@ end end + describe "#find_reservations_room_date" do before do @start_date = Date.today + 5 @@ -201,6 +268,7 @@ end end + describe "#find_reservations_range" do before do @start_date = Date.today + 5 @@ -223,6 +291,61 @@ expect(reservations_range.length).must_equal 3 end end + + + describe "#make_block" do + before do + @date_range = Hotel::DateRange.new(Date.today + 50, Date.today + 60) + end + + it "returns an array" do + block10 = @coordinator01.make_block(@date_range, 5, 100) + expect(block10).must_be_instance_of Array + end + + it "returns the correct number of room blocks" do + block10 = @coordinator01.make_block(@date_range, 5, 100) + expect(block10.length).must_equal 5 + block20 = @coordinator01.make_block(@date_range, 3, 100) + expect(block20.length).must_equal 3 + end + + it "returns an array of Block instances that match the date range" do + block10 = @coordinator01.make_block(@date_range, 5, 100) + block10.each do |block| + expect(block).must_be_instance_of Hotel::Block + expect(block.date_range).must_equal @date_range + end + end + + it "has the same block_id for the same block" do + block10 = @coordinator01.make_block(@date_range, 5, 100) + block_id = block10[0].block + block10.each do |block| + expect(block.block).must_equal block_id + end + end + + it "reflects the correct cost that was passed in" do + block10 = @coordinator01.make_block(@date_range, 5, 100) + block10.each do |block| + expect(block.cost).must_equal 100.00 + expect(block.get_total_price).must_equal 1000.00 + end + end + + it "increases a booking in the room's tracking" do + block10 = @coordinator01.make_block(@date_range, 2, 100) + room_id01 = block10[0].room_id + room_id02 = block10[1].room_id + room01 = @coordinator01.find_room(room_id01) + room02 = @coordinator01.find_room(room_id02) + expect(room01.bookings.length).must_equal 1 + expect(room02.bookings.length).must_equal 1 + end + + end + end From d1a89b53d43174a536328b836848a50281d2abca Mon Sep 17 00:00:00 2001 From: cojenco Date: Fri, 6 Mar 2020 23:23:20 -0800 Subject: [PATCH 40/51] Added Room#is_available method and tests. --- lib/room.rb | 14 ++++++++++++++ test/room_test.rb | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/room.rb b/lib/room.rb index 2ed850339..5dee534f1 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -21,5 +21,19 @@ def get_price(reservation) price = reservation.date_range.count_nights * cost return price end + + def is_available(given_range) + return true if bookings.empty? + + bookings.each do |item| + if item.class == Hotel::Block + return false if item.date_range.overlapping(given_range) && item.date_range.exactly_matching(given_range)== false #it is not an exact match #method + elsif item.class == Hotel::Reservation + return false if item.date_range.overlapping(given_range) + end + end + + return true + end end end diff --git a/test/room_test.rb b/test/room_test.rb index afbd8e2a8..feb09ab2a 100644 --- a/test/room_test.rb +++ b/test/room_test.rb @@ -80,4 +80,49 @@ expect(@room01.get_price(@reservation01)).must_equal 1000.00 end end -end \ No newline at end of file + + describe "is_available" do + before do + @coordinator01 = Hotel::SystemCoordinator.new + @start_date = Date.today + 5 + @end_date = Date.today + 10 + @date_range = Hotel::DateRange.new(@start_date, @end_date) + end + + it "returns true if room is available with no reservations" do + expect(@room01.is_available(@date_range)).must_equal true + expect(@room01.bookings.length).must_equal 0 + end + + it "returns true if room is available with exact block match" do + block10 = Hotel::Block.new(@date_range, @room_id) + @room01.add_booking_to_room(block10) + expect(@room01.is_available(@date_range)).must_equal true + expect(@room01.bookings.length).must_equal 1 + end + + it "returns true if room is available with no overlapping reservations" do + range20 = Hotel::DateRange.new(Date.today + 10, Date.today + 12) + reservation01 = Hotel::Reservation.new(range20, @room_id) + @room01.add_booking_to_room(reservation01) + expect(@room01.is_available(@date_range)).must_equal true + expect(@room01.bookings.length).must_equal 1 + end + + it "returns false when room has overlapping block" do + range20 = Hotel::DateRange.new(Date.today + 5, Date.today + 11) + block20 = Hotel::Block.new(range20, @room_id) + @room01.add_booking_to_room(block20) + expect(@room01.is_available(@date_range)).must_equal false + expect(@room01.bookings.length).must_equal 1 + end + + it "returns false when room has overlapping reservation" do + range30 = Hotel::DateRange.new(Date.today + 5, Date.today + 6) + reservation01 = Hotel::Reservation.new(range30, @room_id) + @room01.add_booking_to_room(reservation01) + expect(@room01.is_available(@date_range)).must_equal false + expect(@room01.bookings.length).must_equal 1 + end + end +end From bd2940ffc7bf4bb56880adf53af0f5dc2479213b Mon Sep 17 00:00:00 2001 From: cojenco Date: Fri, 6 Mar 2020 23:25:55 -0800 Subject: [PATCH 41/51] Added #make_specific_block method and tests. Revised #find_available_rooms method to also consider blocks. --- lib/system_coordinator.rb | 115 ++++++++++++---- test/system_coordinator_test.rb | 233 ++++++++++++++++++++++++-------- 2 files changed, 264 insertions(+), 84 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 15d0304f5..f3e1f7522 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -10,18 +10,21 @@ class SystemCoordinator @@next_block = 1 def initialize(room_quantity = 20) - @rooms = build_rooms(room_quantity) + @rooms = [] # Array.new(quantity){|i| Hotel::Room.new(i+1)} + build_rooms(room_quantity) end - def build_rooms(quantity) - Array.new(quantity){|i| Hotel::Room.new(i+1)} + def build_rooms(room_quantity) + room_quantity.times do + @rooms << Hotel::Room.new(@rooms.length + 1) + end end def list_rooms return @rooms end - # below method needs to also show me the reservations made from hotel block + def find_reservations_by_date(date) reservations_by_date = [] @@ -34,12 +37,14 @@ def find_reservations_by_date(date) return reservations_by_date end + def find_reservations_room_date(room_id, date_range) selected_room = find_room(room_id) - reservations_room_date = selected_room.bookings.select{|reservation|reservation.date_range.overlapping(date_range)} - return reservations_room_date #what returns if no match? + reservations_room_date = selected_room.bookings.reject{|reservation|false == reservation.date_range.overlapping(date_range)} + return reservations_room_date end + def find_reservations_range(given_range) reservations_range = [] @@ -52,6 +57,7 @@ def find_reservations_range(given_range) return reservations_range end + def find_availabile_rooms(given_range) available_rooms = [] @@ -62,7 +68,7 @@ def find_availabile_rooms(given_range) status = true room.bookings.each do |item| if item.class == Hotel::Block - status = false if item.date_range.overlapping(given_range) && item.date_range.exactly_matching(given_range)== false #it is not an exact match #method + status = false if item.date_range.overlapping(given_range) && false == item.date_range.exactly_matching(given_range) #it is not an exact match #method elsif item.class == Hotel::Reservation status = false if item.date_range.overlapping(given_range) end @@ -72,26 +78,10 @@ def find_availabile_rooms(given_range) end raise NoAvailabilityError.new "No Availability. Please try another date range." if available_rooms == [] - return available_rooms end - def find_block_rooms(given_range) - available_rooms = @rooms.reject do |room| - room.bookings.any? do |reservation| #returns true if there are overlapping reservations - reservation.date_range.overlapping(given_range) == true - end - end - - return available_rooms - end - - def find_room(given_room_id) - room_found = @rooms.find{|room|room.room_id == given_room_id} - return room_found - end - - # yet: + def make_reservation(start_date, end_date) range_created = Hotel::DateRange.new(start_date,end_date) available_rooms = find_availabile_rooms(range_created) @@ -104,6 +94,40 @@ def make_reservation(start_date, end_date) return new_reservation end + + def find_block_rooms(given_range) + available_rooms = @rooms.reject do |room| + room.bookings.any? do |reservation| #returns true if there are overlapping reservations + reservation.date_range.overlapping(given_range) == true + end + end + return available_rooms + end + + + def make_specific_block(date_range, roomid_array, cost) + room_array = roomid_array.map{|id| find_room(id)} + raise ArgumentError.new "Maximum 5 rooms for a hotel block." if room_array.length > 5 || room_array.length == 0 + rooms_in_block = [] + + room_array.each do |room| + if room.is_available(date_range) == false + raise NoAvailabilityError.new "Room#{room.room_id} is not available for this given date range." + end + end + + room_array.each do |room| + room_block = Hotel::Block.new(date_range,room.room_id, cost, @@next_block) + room.add_booking_to_room(room_block) + rooms_in_block << room_block + end + + @@next_block += 1 + + return rooms_in_block + end + + def make_block(date_range, room_quantity, cost) raise ArgumentError.new "Maximum 5 rooms for a hotel block." if room_quantity > 5 available_rooms = find_block_rooms(date_range) @@ -119,11 +143,32 @@ def make_block(date_range, room_quantity, cost) rooms_in_block << room_block end - @@next_block += 1 - + @@next_block += 1 return rooms_in_block end + + def find_room(given_room_id) + room_found = @rooms.find{|room|room.room_id == given_room_id} + return room_found + end + + + def check_block_availability(block_id) + rooms_in_block = [] + blocks = [] + @rooms.each do |room| + room.bookings.each do |item| + if item.class == Hotel::Block && item.block == block_id + blocks << item + rooms_in_block << room + end + end + end + + date_range = blocks[0].date_range + rooms_in_block.any?{|room|room.is_available(date_range)} + end end end @@ -135,4 +180,20 @@ def make_block(date_range, room_quantity, cost) # I want an exception raised if I try to reserve a room during a date range when all rooms are reserved, # so that I cannot make two reservations for the same room that overlap by date # I want exception raised when an invalid date range is provided, - # so that I can't make a reservation for an invalid date range \ No newline at end of file + # so that I can't make a reservation for an invalid date range + + + # #################################### + # def rm_available(room, given_range) + # return true if room.bookings.empty? + + # room.bookings.each do |item| + # if item.class == Hotel::Block + # return false if item.date_range.overlapping(given_range) && item.date_range.exactly_matching(given_range)== false #it is not an exact match #method + # elsif item.class == Hotel::Reservation + # return false if item.date_range.overlapping(given_range) + # end + # end + + # return true + # end \ No newline at end of file diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 01a6cffe4..4741ab0bd 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -37,17 +37,10 @@ end describe "#build_rooms" do - it "returns an array" do - quantity = 5 - expect(@coordinator01.build_rooms(quantity)).must_be_instance_of Array - expect(@coordinator01.build_rooms(quantity).length).must_equal quantity - end - - it "stores Room instance in each element" do - built01 = @coordinator01.build_rooms(5) - built01.each do |room| - expect(room).must_be_instance_of Hotel::Room - end + it "increases the number of rooms" do + before = @coordinator01.rooms.length + @coordinator01.build_rooms(5) + expect(@coordinator01.rooms.length).must_equal before + 5 end end @@ -130,58 +123,68 @@ end end - # describe "#find_availabile_rooms" do - # before do - # @start_date = Date.today + 5 - # @end_date = Date.today + 10 - # @date_range = Hotel::DateRange.new(@start_date,@end_date) - # end + describe "#find_block_rooms" do + before do + @start_date = Date.today + 5 + @end_date = Date.today + 10 + @date_range = Hotel::DateRange.new(@start_date,@end_date) + end - # it "returns an array" do - # available_rooms = @coordinator01.find_availabile_rooms(@date_range) - # expect(available_rooms).must_be_instance_of Array - # end + it "returns an array" do + available_rooms = @coordinator01.find_block_rooms(@date_range) + expect(available_rooms).must_be_instance_of Array + end - # it "stores Room instances in the array" do - # available_rooms = @coordinator01.find_availabile_rooms(@date_range) - # available_rooms.each do |room| - # expect(room).must_be_instance_of Hotel::Room - # end - # end + it "stores Room instances in the array" do + available_rooms = @coordinator01.find_block_rooms(@date_range) + available_rooms.each do |room| + expect(room).must_be_instance_of Hotel::Room + end + end - # it "returns the correct number of available rooms when there are no reservations" do - # available_rooms = @coordinator01.find_availabile_rooms(@date_range) - # expect(available_rooms.length).must_equal 20 - # end + it "returns the correct number of available rooms when there are no reservations" do + available_rooms = @coordinator01.find_block_rooms(@date_range) + expect(available_rooms.length).must_equal 20 + end - # it "returns the correct number of available rooms when there are reservations" do - # @coordinator01.make_reservation(@start_date, @end_date) - # expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 19 - # @coordinator01.make_reservation(Date.today + 10, Date.today + 12) - # @coordinator01.make_reservation(Date.today + 1, Date.today + 2) - # expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 19 - # @coordinator01.make_reservation(@start_date, @end_date) - # expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 18 - # end + it "returns the correct number of available rooms when there are reservations" do + @coordinator01.make_reservation(@start_date, @end_date) + expect(@coordinator01.find_block_rooms(@date_range).length).must_equal 19 + @coordinator01.make_reservation(Date.today + 10, Date.today + 12) + @coordinator01.make_reservation(Date.today + 1, Date.today + 2) + expect(@coordinator01.find_block_rooms(@date_range).length).must_equal 19 + @coordinator01.make_reservation(@start_date, @end_date) + expect(@coordinator01.find_block_rooms(@date_range).length).must_equal 18 + end - # it "should not include rooms that have reservations in the given date_range" do - # @coordinator01.make_reservation(@start_date, @end_date) - # available_rooms = @coordinator01.find_availabile_rooms(@date_range) - # available_rooms.each do |room| - # room.bookings.each do |booking| - # expect(booking.date_range.overlapping(@date_range)).must_equal false - # end - # end - # end + it "returns the correct number of available rooms when there are blocks" do + @coordinator01.make_reservation(@start_date, @end_date) + expect(@coordinator01.find_block_rooms(@date_range).length).must_equal 19 + @coordinator01.make_block(@date_range, 5, 150) + expect(@coordinator01.find_block_rooms(@date_range).length).must_equal 14 + range02 = Hotel::DateRange.new(@start_date + 2, @end_date + 2) + @coordinator01.make_block(range02, 3, 180) + expect(@coordinator01.find_block_rooms(@date_range).length).must_equal 11 + end - # it "returns an empty array when there are no rooms available" do - # 20.times do - # @coordinator01.make_reservation(@start_date, @end_date) - # end - # available_rooms = @coordinator01.find_availabile_rooms(@date_range) - # expect(available_rooms).must_equal [] - # end - # end + it "should not include rooms that have reservations in the given date_range" do + @coordinator01.make_reservation(@start_date, @end_date) + available_rooms = @coordinator01.find_block_rooms(@date_range) + available_rooms.each do |room| + room.bookings.each do |booking| + expect(booking.date_range.overlapping(@date_range)).must_equal false + end + end + end + + it "returns an empty array when there are no rooms available" do + 20.times do + @coordinator01.make_reservation(@start_date, @end_date) + end + available_rooms = @coordinator01.find_block_rooms(@date_range) + expect(available_rooms).must_equal [] + end + end describe "#make_reservation" do before do @@ -219,6 +222,8 @@ end + + describe "#find_reservations_by_date" do before do start_date = Date.today + 5 @@ -343,9 +348,123 @@ expect(room01.bookings.length).must_equal 1 expect(room02.bookings.length).must_equal 1 end + end + + describe "#make_specific_block" do + before do + @start_date = Date.today + 50 + @end_date = Date.today + 60 + @date_range = Hotel::DateRange.new(@start_date, @end_date) + end + + it "returns an array" do + block10 = @coordinator01.make_specific_block(@date_range, [11,12], 100) + expect(block10).must_be_instance_of Array + end + + it "returns the correct number of room blocks" do + block10 = @coordinator01.make_specific_block(@date_range, [20], 180) + expect(block10.length).must_equal 1 + block20 = @coordinator01.make_specific_block(@date_range, [11,12,13,14,15], 100) + expect(block20.length).must_equal 5 + end + + it "returns an array of Block instances that match the date range and same block_id" do + block10 = @coordinator01.make_specific_block(@date_range, [11,12,13], 100) + block_id = block10[0].block + block10.each do |block| + expect(block).must_be_instance_of Hotel::Block + expect(block.date_range).must_equal @date_range + expect(block.block).must_equal block_id + end + end + + it "reflects the correct cost that was passed in" do + block10 = @coordinator01.make_specific_block(@date_range, [11,12,13,14,15], 100) + block10.each do |block| + expect(block.cost).must_equal 100.00 + expect(block.get_total_price).must_equal 1000.00 + end + end + it "raises an Exception when there is a room unavailalblie" do + reservation10 = @coordinator01.make_reservation(@start_date, @end_date) + id = reservation10.room_id + expect{@coordinator01.make_specific_block(@date_range, [id,12,13], 100)}.must_raise NoAvailabilityError + end end + + describe "#check_block_availability" do + before do + @start_date = Date.today + 50 + @end_date = Date.today + 60 + @date_range = Hotel::DateRange.new(@start_date, @end_date) + end + + it "returns true if the given block has any available rooms" do + block10 = @coordinator01.make_specific_block(@date_range, [1,2], 100) + block_id=block10[0].block + @coordinator01.make_reservation(@start_date,@end_date) + expect(@coordinator01.check_block_availability(block_id)).must_equal true + end + + it "returns false if there are no available rooms" do + block10 = @coordinator01.make_specific_block(@date_range, [1,2], 100) + block_id=block10[0].block + @coordinator01.make_reservation(@start_date,@end_date) + @coordinator01.make_reservation(@start_date,@end_date) + expect(@coordinator01.check_block_availability(block_id)).must_equal false + end + end end + + + # describe "rm_available" do + # before do + # @start_date = Date.today + 5 + # @end_date = Date.today + 10 + # @date_range = Hotel::DateRange.new(@start_date,@end_date) + # @room01 = @coordinator01.find_room(1) + # end + + # it "returns true if room is available with no reservations" do + # expect(@coordinator01.rm_available(@room01, @date_range)).must_equal true + # expect(@room01.bookings.length).must_equal 0 + # end + + # it "returns true if room is available with exact block match" do + # block10 = @coordinator01.make_block(@date_range, 1, 100) + # room_id = block10[0].room_id + # room = @coordinator01.find_room(room_id) + # expect(@coordinator01.rm_available(room, @date_range)).must_equal true + # expect(room.bookings.length).must_equal 1 + # end + + # it "returns true if room is available with no overlapping reservations" do + # reservation10 = @coordinator01.make_reservation(Date.today + 1, Date.today + 3) + # room_id = reservation10.room_id + # room = @coordinator01.find_room(room_id) + # expect(@coordinator01.rm_available(room, @date_range)).must_equal true + # expect(room.bookings.length).must_equal 1 + # end + + # it "returns false when room has overlapping block" do + # range20 = Hotel::DateRange.new(Date.today + 3, Date.today + 7) + # block20 = @coordinator01.make_block(range20, 1, 100) + # room_id = block20[0].room_id + # room = @coordinator01.find_room(room_id) + # expect(@coordinator01.rm_available(room, @date_range)).must_equal false + # expect(room.bookings.length).must_equal 1 + # end + + # it "returns false when room has overlapping reservation" do + # reservation20 = @coordinator01.make_reservation(Date.today + 8, Date.today + 13) + # room_id = reservation20.room_id + # room = @coordinator01.find_room(room_id) + # expect(@coordinator01.rm_available(room, @date_range)).must_equal false + # expect(room.bookings.length).must_equal 1 + # end + # end \ No newline at end of file From 434be2e15e75920c6bb8d4ddd701db2e1d395c89 Mon Sep 17 00:00:00 2001 From: cojenco Date: Fri, 6 Mar 2020 23:27:23 -0800 Subject: [PATCH 42/51] Cleaning up formatting and code. --- lib/date_range.rb | 1 - lib/reservation.rb | 33 ++------------------------------- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 0db4faaf0..55ed82ba1 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -48,6 +48,5 @@ def exactly_matching(other_range) return false end end - end end diff --git a/lib/reservation.rb b/lib/reservation.rb index ce94ad9c0..3fbeecd37 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -2,7 +2,7 @@ module Hotel class Reservation - attr_reader :id, :start_date, :end_date, :date_range, :room_id + attr_reader :id, :start_date, :end_date, :date_range, :room_id, :block attr_accessor :cost @@next_id = 1 @@ -17,41 +17,12 @@ def initialize(date_range, room_id, cost = 200.00) @id = @@next_id @@next_id += 1 - - # @block = -1 #another way is to give a hotel block attribute + @block = -1 end def get_total_price total_price = date_range.count_nights * cost return total_price end - end end - - - - - -# attr_reader :id, :start_date, :end_date, :date_range, :room_id - -# @@next_id = 1 - -# def initialize(start_date, end_date, room_id) -# raise ArgumentError.new("Please pass in Date class instances.") if !(start_date.is_a? Date) || !(end_date.is_a? Date) -# raise ArgumentError.new("Live in the present! Dates should not be prior to today.") if start_date < Date.today -# raise ArgumentError.new("End date should not be earlier than or the same day as start date.") if end_date <= start_date -# @start_date = start_date -# @end_date = end_date -# @date_range = DateRange.new(start_date, end_date) -# @room_id = room_id - -# @id = @@next_id -# @@next_id += 1 -# # @hotel_block_id -# end - -# def get_price -# price = date_range.count_nights * 200.00 #should require relative room and take room.cost -# return price -# end \ No newline at end of file From b67560ec44911ebccd2615b1745ff897da36658c Mon Sep 17 00:00:00 2001 From: cojenco Date: Sat, 7 Mar 2020 22:20:02 -0800 Subject: [PATCH 43/51] Added Room#change_rate method and tests. --- lib/room.rb | 9 +++++++-- test/room_test.rb | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 5dee534f1..9f40a05bf 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -26,14 +26,19 @@ def is_available(given_range) return true if bookings.empty? bookings.each do |item| - if item.class == Hotel::Block + if item.block >= 0 #item.class == Hotel::Block return false if item.date_range.overlapping(given_range) && item.date_range.exactly_matching(given_range)== false #it is not an exact match #method - elsif item.class == Hotel::Reservation + elsif item.block < 0 #item.class == Hotel::Reservation return false if item.date_range.overlapping(given_range) end end return true end + + def change_rate(new_rate) + raise ArgumentError if !new_rate.is_a?(Numeric) || new_rate.to_f < 0 + @cost = new_rate.to_f + end end end diff --git a/test/room_test.rb b/test/room_test.rb index feb09ab2a..7c50fb4dc 100644 --- a/test/room_test.rb +++ b/test/room_test.rb @@ -81,7 +81,7 @@ end end - describe "is_available" do + describe "#is_available" do before do @coordinator01 = Hotel::SystemCoordinator.new @start_date = Date.today + 5 @@ -125,4 +125,23 @@ expect(@room01.bookings.length).must_equal 1 end end + + describe "#change_rate" do + it "returns a float of the new rate" do + expect(@room01.change_rate(100)).must_be_instance_of Float + expect(@room01.change_rate(100)).must_equal 100.00 + end + + it "changes the room the correct new rate" do + expect(@room01.cost).must_equal 200.00 + new_rate = 100 + @room01.change_rate(new_rate) + expect(@room01.cost).must_equal new_rate + end + + it "raises an exception if the new rate is < 0" do + expect{@room01.change_rate(-99)}.must_raise ArgumentError + expect{@room01.change_rate("free")}.must_raise ArgumentError + end + end end From 8df9b3de79b440a514d2a992d2038575bc9db45c Mon Sep 17 00:00:00 2001 From: cojenco Date: Sun, 8 Mar 2020 00:31:20 -0800 Subject: [PATCH 44/51] Fixed spelling typo. Revised #list_rooms methods to accomodate CLI. --- lib/system_coordinator.rb | 55 ++++++------------- test/system_coordinator_test.rb | 95 +++++++-------------------------- 2 files changed, 35 insertions(+), 115 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index f3e1f7522..481d81e70 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -21,14 +21,17 @@ def build_rooms(room_quantity) end def list_rooms - return @rooms + rooms.each do |room| + puts "Room ID: #{room.room_id} | Rate: #{room.cost}" + end + return rooms end def find_reservations_by_date(date) reservations_by_date = [] - @rooms.each do |room| + rooms.each do |room| room.bookings.each do |reservation| reservations_by_date << reservation if reservation.date_range.include_date(date) end @@ -48,7 +51,7 @@ def find_reservations_room_date(room_id, date_range) def find_reservations_range(given_range) reservations_range = [] - @rooms.each do |room| + rooms.each do |room| room.bookings.each do |reservation| reservations_range << reservation if reservation.date_range.overlapping(given_range) end @@ -58,18 +61,18 @@ def find_reservations_range(given_range) end - def find_availabile_rooms(given_range) + def find_available_rooms(given_range) available_rooms = [] - @rooms.each do |room| + rooms.each do |room| if room.bookings.empty? available_rooms << room else status = true room.bookings.each do |item| - if item.class == Hotel::Block + if item.block >= 0 #item.class == Hotel::Block status = false if item.date_range.overlapping(given_range) && false == item.date_range.exactly_matching(given_range) #it is not an exact match #method - elsif item.class == Hotel::Reservation + elsif item.block < 0 #item.class == Hotel::Reservation status = false if item.date_range.overlapping(given_range) end end @@ -84,7 +87,7 @@ def find_availabile_rooms(given_range) def make_reservation(start_date, end_date) range_created = Hotel::DateRange.new(start_date,end_date) - available_rooms = find_availabile_rooms(range_created) + available_rooms = find_available_rooms(range_created) chosen_room = available_rooms.shift new_reservation = Hotel::Reservation.new(range_created, chosen_room.room_id) @@ -96,7 +99,7 @@ def make_reservation(start_date, end_date) def find_block_rooms(given_range) - available_rooms = @rooms.reject do |room| + available_rooms = rooms.reject do |room| room.bookings.any? do |reservation| #returns true if there are overlapping reservations reservation.date_range.overlapping(given_range) == true end @@ -149,7 +152,7 @@ def make_block(date_range, room_quantity, cost) def find_room(given_room_id) - room_found = @rooms.find{|room|room.room_id == given_room_id} + room_found = rooms.find{|room|room.room_id == given_room_id} return room_found end @@ -157,9 +160,9 @@ def find_room(given_room_id) def check_block_availability(block_id) rooms_in_block = [] blocks = [] - @rooms.each do |room| + rooms.each do |room| room.bookings.each do |item| - if item.class == Hotel::Block && item.block == block_id + if item.block > 0 && item.block == block_id blocks << item rooms_in_block << room end @@ -167,33 +170,7 @@ def check_block_availability(block_id) end date_range = blocks[0].date_range - rooms_in_block.any?{|room|room.is_available(date_range)} + rooms_in_block.any?{|room|room.is_available(date_range)} #returns true or false end end end - - - # handle/ rescue exceptions - # edge cases i.e. what happens if no match? - - # what returns if no match?!!!!! rescue an raised exception???????? - # I want an exception raised if I try to reserve a room during a date range when all rooms are reserved, - # so that I cannot make two reservations for the same room that overlap by date - # I want exception raised when an invalid date range is provided, - # so that I can't make a reservation for an invalid date range - - - # #################################### - # def rm_available(room, given_range) - # return true if room.bookings.empty? - - # room.bookings.each do |item| - # if item.class == Hotel::Block - # return false if item.date_range.overlapping(given_range) && item.date_range.exactly_matching(given_range)== false #it is not an exact match #method - # elsif item.class == Hotel::Reservation - # return false if item.date_range.overlapping(given_range) - # end - # end - - # return true - # end \ No newline at end of file diff --git a/test/system_coordinator_test.rb b/test/system_coordinator_test.rb index 4741ab0bd..65cf55f01 100644 --- a/test/system_coordinator_test.rb +++ b/test/system_coordinator_test.rb @@ -57,7 +57,7 @@ end end - describe "#find_availabile_rooms" do + describe "#find_available_rooms" do before do @start_date = Date.today + 5 @end_date = Date.today + 10 @@ -65,35 +65,35 @@ end it "returns an array" do - available_rooms = @coordinator01.find_availabile_rooms(@date_range) + available_rooms = @coordinator01.find_available_rooms(@date_range) expect(available_rooms).must_be_instance_of Array end it "stores Room instances or Block instances in the array" do - available_rooms = @coordinator01.find_availabile_rooms(@date_range) + available_rooms = @coordinator01.find_available_rooms(@date_range) available_rooms.each do |room| expect(room).must_be_instance_of Hotel::Room || Hotel::Block end end it "returns the correct number of available rooms when there are no reservations" do - available_rooms = @coordinator01.find_availabile_rooms(@date_range) + available_rooms = @coordinator01.find_available_rooms(@date_range) expect(available_rooms.length).must_equal 20 end it "returns the correct number of available rooms when there are reservations" do @coordinator01.make_reservation(@start_date, @end_date) - expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 19 + expect(@coordinator01.find_available_rooms(@date_range).length).must_equal 19 @coordinator01.make_reservation(Date.today + 10, Date.today + 12) @coordinator01.make_reservation(Date.today + 1, Date.today + 2) - expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 19 + expect(@coordinator01.find_available_rooms(@date_range).length).must_equal 19 @coordinator01.make_reservation(@start_date, @end_date) - expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 18 + expect(@coordinator01.find_available_rooms(@date_range).length).must_equal 18 end it "should not include rooms that have reservations in the given date_range" do @coordinator01.make_reservation(@start_date, @end_date) - available_rooms = @coordinator01.find_availabile_rooms(@date_range) + available_rooms = @coordinator01.find_available_rooms(@date_range) available_rooms.each do |room| room.bookings.each do |booking| expect(booking.date_range.overlapping(@date_range)).must_equal false @@ -103,23 +103,23 @@ it "returns the correct number of available rooms when there are blocks" do @coordinator01.make_block(@date_range, 3, 150) - expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 20 + expect(@coordinator01.find_available_rooms(@date_range).length).must_equal 20 range02 = Hotel::DateRange.new(Date.today + 5, Date.today + 7) - expect(@coordinator01.find_availabile_rooms(range02).length).must_equal 17 + expect(@coordinator01.find_available_rooms(range02).length).must_equal 17 range03 = Hotel::DateRange.new(Date.today + 5, Date.today + 15) - expect(@coordinator01.find_availabile_rooms(range03).length).must_equal 17 + expect(@coordinator01.find_available_rooms(range03).length).must_equal 17 range04 = Hotel::DateRange.new(Date.today + 3, Date.today + 12) - expect(@coordinator01.find_availabile_rooms(range04).length).must_equal 17 + expect(@coordinator01.find_available_rooms(range04).length).must_equal 17 @coordinator01.make_block(@date_range, 5, 100) - expect(@coordinator01.find_availabile_rooms(@date_range).length).must_equal 20 - expect(@coordinator01.find_availabile_rooms(range02).length).must_equal 12 + expect(@coordinator01.find_available_rooms(@date_range).length).must_equal 20 + expect(@coordinator01.find_available_rooms(range02).length).must_equal 12 end it "raises NoAvailabilityError when there are no rooms available" do 20.times do @coordinator01.make_reservation(@start_date, @end_date) end - expect{@coordinator01.make_reservation(@start_date, @end_date)}.must_raise NoAvailabilityError + expect{@coordinator01.find_available_rooms(@date_range)}.must_raise NoAvailabilityError end end @@ -202,15 +202,9 @@ new_reservation = @coordinator01.make_reservation(@start_date, @end_date) expect(new_reservation.room_id).must_equal 1 end - - # it "raises ArgumentError when there are no rooms available" do - # 20.times do - # @coordinator01.make_reservation(@start_date, @end_date) - # end - # expect{@coordinator01.make_reservation(@start_date, @end_date)}.must_raise ArgumentError - # end end + describe "#find_room" do it "returns an instance of Room" do expect(@coordinator01.find_room(10)).must_be_instance_of Hotel::Room @@ -222,8 +216,6 @@ end - - describe "#find_reservations_by_date" do before do start_date = Date.today + 5 @@ -350,6 +342,7 @@ end end + describe "#make_specific_block" do before do @start_date = Date.today + 50 @@ -387,7 +380,7 @@ end end - it "raises an Exception when there is a room unavailalblie" do + it "raises an Exception when there is a room unavailable" do reservation10 = @coordinator01.make_reservation(@start_date, @end_date) id = reservation10.room_id expect{@coordinator01.make_specific_block(@date_range, [id,12,13], 100)}.must_raise NoAvailabilityError @@ -417,54 +410,4 @@ expect(@coordinator01.check_block_availability(block_id)).must_equal false end end -end - - - - - # describe "rm_available" do - # before do - # @start_date = Date.today + 5 - # @end_date = Date.today + 10 - # @date_range = Hotel::DateRange.new(@start_date,@end_date) - # @room01 = @coordinator01.find_room(1) - # end - - # it "returns true if room is available with no reservations" do - # expect(@coordinator01.rm_available(@room01, @date_range)).must_equal true - # expect(@room01.bookings.length).must_equal 0 - # end - - # it "returns true if room is available with exact block match" do - # block10 = @coordinator01.make_block(@date_range, 1, 100) - # room_id = block10[0].room_id - # room = @coordinator01.find_room(room_id) - # expect(@coordinator01.rm_available(room, @date_range)).must_equal true - # expect(room.bookings.length).must_equal 1 - # end - - # it "returns true if room is available with no overlapping reservations" do - # reservation10 = @coordinator01.make_reservation(Date.today + 1, Date.today + 3) - # room_id = reservation10.room_id - # room = @coordinator01.find_room(room_id) - # expect(@coordinator01.rm_available(room, @date_range)).must_equal true - # expect(room.bookings.length).must_equal 1 - # end - - # it "returns false when room has overlapping block" do - # range20 = Hotel::DateRange.new(Date.today + 3, Date.today + 7) - # block20 = @coordinator01.make_block(range20, 1, 100) - # room_id = block20[0].room_id - # room = @coordinator01.find_room(room_id) - # expect(@coordinator01.rm_available(room, @date_range)).must_equal false - # expect(room.bookings.length).must_equal 1 - # end - - # it "returns false when room has overlapping reservation" do - # reservation20 = @coordinator01.make_reservation(Date.today + 8, Date.today + 13) - # room_id = reservation20.room_id - # room = @coordinator01.find_room(room_id) - # expect(@coordinator01.rm_available(room, @date_range)).must_equal false - # expect(room.bookings.length).must_equal 1 - # end - # end \ No newline at end of file +end \ No newline at end of file From ff0ac77398ca8da1ee96f0b46abbad003c45fac1 Mon Sep 17 00:00:00 2001 From: cojenco Date: Sun, 8 Mar 2020 00:31:47 -0800 Subject: [PATCH 45/51] Added main.rb --- main.rb | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 main.rb diff --git a/main.rb b/main.rb new file mode 100644 index 000000000..5abcf1ef8 --- /dev/null +++ b/main.rb @@ -0,0 +1,129 @@ +require_relative 'lib/system_coordinator' +require_relative 'lib/room' +require_relative 'lib/date_range' +require_relative 'lib/reservation' +require_relative 'lib/no_availability_error' + +def display_intro + puts "\nGood day! You are now logged in the hotel system." +end + +def display_options + puts "\nEnter 1, 2, 3, 4, 5, 6 ,7 , or 0 for the following options." + puts "1. list rooms" + puts "2. find reservations by date" + puts "3. find reservations by room and date range" + puts "4. find available rooms for date range" + puts "5. find available rooms for hotel block" + puts "6. make hotel block" + puts "7. make reservation" + puts "0. exit" +end + +def create_date + puts "Please enter a date in DD/MM/YYYY format" + stringdate = gets.chomp + new_date = Date.parse(stringdate) + return new_date +end + +def ask_room + puts "Please enter the Room ID" + room_id = gets.chomp + return room_id +end + +def ask_rate + puts "Please enter the rate" + rate = gets.chomp + return rate.to_f +end + +def list_reservations(reservations) + reservations.each do |rs| + puts "Reservation #{rs.id}: Room #{rs.room_id} from #{rs.start_date} to #{rs.end_date}" + end +end + +def list_rooms(rooms_array) + rooms_array.each do |room| + print "Room #{room.room_id} | " + end +end + +def list_blocks(blocks_array) + blocks_array.each do |rs| + puts "Block #{rs.block}: Room #{rs.room_id} from #{rs.start_date} to #{rs.end_date}" + end +end + +def main + coordinator = Hotel::SystemCoordinator.new + + display_intro + control_loop = true + + while control_loop + display_options + choice = gets.chomp + case choice + when "1", "1.", "list rooms" + coordinator.list_rooms + when "2", "2.", "find reservations by date" + date_given = create_date + bookings = coordinator.find_reservations_by_date(date_given) + list_reservations(bookings) + when "3", "3.", "find reservations by room and date range" + start_date = create_date + end_date = create_date + range_given = Hotel::DateRange.new(start_date, end_date) + room_id = ask_room + bookings = coordinator.find_reservations_room_date(room_id.to_i,range_given) + list_reservations(bookings) + when "4", "4.", "find available rooms for date range" + start_date = create_date + end_date = create_date + range_given = Hotel::DateRange.new(start_date, end_date) + rooms = coordinator.find_available_rooms(range_given) + puts "There are #{rooms.length} rooms available." + rooms.list_rooms + # rooms.each do |room| + # print "Room #{room.room_id} | " + # end + when "5", "5.", "find available rooms for hotel block" + start_date = create_date + end_date = create_date + range_given = Hotel::DateRange.new(start_date, end_date) + rooms = coordinator.find_block_rooms(range_given) + puts "There are #{rooms.length} rooms available." + rooms.list_rooms + when "6", "6.", "make specific hotel block" + start_date = create_date + end_date = create_date + range_given = Hotel::DateRange.new(start_date, end_date) + room_array = [] + 5.times do + room_id = ask_room + room_array << room_id + end + cost = ask_rate + block = coordinator.make_specific_block(range_given, room_array, cost) + block.list_blocks + when "7", "7.", "make reservation" + start_date = create_date + end_date = create_date + reservation = coordinator.make_reservation(start_date,end_date) + puts "Reservation is made. It is room #{reservation.room_id} from #{reservation.start_date} to #{reservation.end_date}" + when "0", "0.", "exit", "quit", "0. exit" + control_loop = false + end + end + +end + +# example = Date.parse("10/10/2020") +# puts example.class + +# puts example + +main \ No newline at end of file From b017ab5366114017c0ff93a8a6705114184aef0f Mon Sep 17 00:00:00 2001 From: cojenco Date: Sun, 8 Mar 2020 12:39:16 -0700 Subject: [PATCH 46/51] Added Require_Relative and revised syntax to accomodate CLI. --- lib/date_range.rb | 16 ++++++++-------- lib/system_coordinator.rb | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 55ed82ba1..4728f306e 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -20,14 +20,6 @@ def count_nights return nights end - def including(other_range) - if other_range.start_date >= @start_date && other_range.end_date <= @end_date - return true - else - return false - end - end - def include_date(date) return true if date >= @start_date && date < @end_date return false @@ -48,5 +40,13 @@ def exactly_matching(other_range) return false end end + + def including(other_range) + if other_range.start_date >= @start_date && other_range.end_date <= @end_date + return true + else + return false + end + end end end diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 481d81e70..fe9075242 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -1,6 +1,7 @@ require_relative 'room' require_relative 'date_range' require_relative 'reservation' +require_relative 'block' require_relative 'no_availability_error' module Hotel From def524f50caabdfeb5efb552d1628ed9e0764f6e Mon Sep 17 00:00:00 2001 From: cojenco Date: Sun, 8 Mar 2020 12:40:26 -0700 Subject: [PATCH 47/51] Added small driver methods to the main.rb file. --- main.rb | 82 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/main.rb b/main.rb index 5abcf1ef8..f528a21a7 100644 --- a/main.rb +++ b/main.rb @@ -27,18 +27,44 @@ def create_date return new_date end +def create_start_date + puts "Please enter start date in DD/MM/YYYY format" + stringdate = gets.chomp + new_date = Date.parse(stringdate) + return new_date +end + +def create_end_date + puts "Please enter end date in DD/MM/YYYY format" + stringdate = gets.chomp + new_date = Date.parse(stringdate) + return new_date +end + def ask_room puts "Please enter the Room ID" - room_id = gets.chomp + room_id = gets.chomp.to_i return room_id end +def ask_block + puts "Please enter the Block ID" + block_id = gets.chomp.to_i + return block_id +end + def ask_rate puts "Please enter the rate" rate = gets.chomp return rate.to_f end +def ask_quantity + puts "Please enter the quantity of rooms for the hotel block" + quantity = gets.chomp.to_i + return quantity +end + def list_reservations(reservations) reservations.each do |rs| puts "Reservation #{rs.id}: Room #{rs.room_id} from #{rs.start_date} to #{rs.end_date}" @@ -57,6 +83,7 @@ def list_blocks(blocks_array) end end + def main coordinator = Hotel::SystemCoordinator.new @@ -74,56 +101,49 @@ def main bookings = coordinator.find_reservations_by_date(date_given) list_reservations(bookings) when "3", "3.", "find reservations by room and date range" - start_date = create_date - end_date = create_date + start_date = create_start_date + end_date = create_end_date range_given = Hotel::DateRange.new(start_date, end_date) room_id = ask_room bookings = coordinator.find_reservations_room_date(room_id.to_i,range_given) list_reservations(bookings) when "4", "4.", "find available rooms for date range" - start_date = create_date - end_date = create_date + start_date = create_start_date + end_date = create_end_date range_given = Hotel::DateRange.new(start_date, end_date) - rooms = coordinator.find_available_rooms(range_given) - puts "There are #{rooms.length} rooms available." - rooms.list_rooms - # rooms.each do |room| - # print "Room #{room.room_id} | " - # end + rooms_found = coordinator.find_available_rooms(range_given) + puts "There are #{rooms_found.length} rooms available." + list_rooms(rooms_found) when "5", "5.", "find available rooms for hotel block" - start_date = create_date - end_date = create_date - range_given = Hotel::DateRange.new(start_date, end_date) - rooms = coordinator.find_block_rooms(range_given) - puts "There are #{rooms.length} rooms available." - rooms.list_rooms + block_given = ask_block + availability = coordinator.check_block_availability(block_given) + # puts availability + puts availability == true ? "Available rooms in this block" : "No vacant rooms in this block" when "6", "6.", "make specific hotel block" - start_date = create_date - end_date = create_date + start_date = create_start_date + end_date = create_end_date range_given = Hotel::DateRange.new(start_date, end_date) + quantity = ask_quantity + while quantity > 5 || quantity <= 0 + quantity = ask_quantity + end room_array = [] - 5.times do - room_id = ask_room + quantity.times do + room_id = ask_room.to_i room_array << room_id end cost = ask_rate block = coordinator.make_specific_block(range_given, room_array, cost) - block.list_blocks + list_blocks(block) when "7", "7.", "make reservation" - start_date = create_date - end_date = create_date + start_date = create_start_date + end_date = create_end_date reservation = coordinator.make_reservation(start_date,end_date) - puts "Reservation is made. It is room #{reservation.room_id} from #{reservation.start_date} to #{reservation.end_date}" + puts "Reservation is made. It is Room #{reservation.room_id} from #{reservation.start_date} to #{reservation.end_date}" when "0", "0.", "exit", "quit", "0. exit" control_loop = false end end - end -# example = Date.parse("10/10/2020") -# puts example.class - -# puts example - main \ No newline at end of file From 24a9b36d874ad3ea12811614800292e92904fb68 Mon Sep 17 00:00:00 2001 From: cojenco Date: Sun, 8 Mar 2020 22:25:29 -0700 Subject: [PATCH 48/51] Revised #list_rooms method for main and coordinator files. --- lib/system_coordinator.rb | 6 +++--- main.rb | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index fe9075242..127fd30d1 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -22,9 +22,9 @@ def build_rooms(room_quantity) end def list_rooms - rooms.each do |room| - puts "Room ID: #{room.room_id} | Rate: #{room.cost}" - end + # rooms.each do |room| + # puts "Room ID: #{room.room_id} | Rate: #{room.cost}" + # end return rooms end diff --git a/main.rb b/main.rb index f528a21a7..ef2c48e3d 100644 --- a/main.rb +++ b/main.rb @@ -73,7 +73,7 @@ def list_reservations(reservations) def list_rooms(rooms_array) rooms_array.each do |room| - print "Room #{room.room_id} | " + print "Room #{room.room_id}, Rate: $#{room.cost} | " end end @@ -95,7 +95,8 @@ def main choice = gets.chomp case choice when "1", "1.", "list rooms" - coordinator.list_rooms + all_rooms = coordinator.list_rooms + list_rooms(all_rooms) when "2", "2.", "find reservations by date" date_given = create_date bookings = coordinator.find_reservations_by_date(date_given) From 5047dc84ea0f34516b63d182c7e0c554c27ede97 Mon Sep 17 00:00:00 2001 From: cojenco Date: Sun, 8 Mar 2020 22:25:57 -0700 Subject: [PATCH 49/51] Added refactors.txt --- .DS_Store | Bin 8196 -> 8196 bytes refactors.txt | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 refactors.txt diff --git a/.DS_Store b/.DS_Store index d24a5b6301bd1bf8e9525d6c125c874dc3f365cc..50acc53f453835780edd787b4894d38fb27628a1 100644 GIT binary patch delta 115 zcmZp1XmOa}&&apF diff --git a/refactors.txt b/refactors.txt new file mode 100644 index 000000000..0c548ed09 --- /dev/null +++ b/refactors.txt @@ -0,0 +1,15 @@ +### Design Reconsiderations ### + +(1). The benefits of having everything in 1 container with shallow layers. +SystemCoordinator class knowing all @Reservations versus each Room knowing its own @[Reservations] +The down side of each Room having its own array of reservations is that methods will easily require at least one loop to iterate through each room and probably a second loop to loop through each reservation. + + +(2). Consider DateRange as a superclass. Reservation and block both inherit from DateRange. +It makes much sense after creating many methods for the DateRange class and fulfilling the user stories. +Ultimately, comparing date range was a crucial concept in our algorithm throughout all Reservations and Blocks. + +(3). View Block as an entire hotel block instead of splitting one hotel block hold into block per room. +Also, consider more elegant designs on how to handle blocks/reservations and mark room that is reserved from block. + + From 9f18e56bbd27aabb3f6aa3a1f8e78386167ce249 Mon Sep 17 00:00:00 2001 From: cojenco Date: Sun, 8 Mar 2020 22:26:48 -0700 Subject: [PATCH 50/51] Revised #list_rooms method. --- lib/system_coordinator.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/system_coordinator.rb b/lib/system_coordinator.rb index 127fd30d1..5302047ed 100644 --- a/lib/system_coordinator.rb +++ b/lib/system_coordinator.rb @@ -22,9 +22,6 @@ def build_rooms(room_quantity) end def list_rooms - # rooms.each do |room| - # puts "Room ID: #{room.room_id} | Rate: #{room.cost}" - # end return rooms end From 8c0c0cb33b73b0b62ccd58fa2ade1b3121d12139 Mon Sep 17 00:00:00 2001 From: cojenco Date: Sun, 8 Mar 2020 22:29:11 -0700 Subject: [PATCH 51/51] Clean up comments. --- lib/block.rb | 72 +--------------------------------------- test/reservation_test.rb | 45 +------------------------ 2 files changed, 2 insertions(+), 115 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 4bc85ac2d..b47796113 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -14,74 +14,4 @@ def initialize(date_range, room_id, cost = 200.00, block = 0) end end -end - - - - - - -# Scenario 1: -# Block < Reservation -# Coordinator#find_available_rooms: -# loop through each room -# status = true #room is available -# loop through each reservation per room -# if rs.class == Hotel::Block -# if date_range overlap && rs.date_range is not the exact given date_range -# status = false -# break -# end -# else -# if rs.date_range overlaps -# status = false -# end -# end -# unavailables << room if status == false - -# Scenario 2: -# Reservation Class add extra attribute @block -# Coordinator#find_available_rooms: -# loop through each room -# status = true #room is available -# if room.bookings.empty? == false -# loop through each reservation per room -# if rs.block < 0 -# if rs.date_range overlap && rs.date_range is not the exact given date_range -# status = false -# break -# end -# else -# if rs.date_range overlaps -# status = false -# end -# end -# unavailables << room if status == false -# end - - - - - ##method## I can check whether a given block has any rooms available - # def check_block_vacancy - - # A block can contain a maximum of 5 rooms - # date_range has to be exactly the same - - #I can create a Hotel Block if I give a date range, collection of rooms, and a discounted room rate - - # A block can contain a maximum of 5 rooms - # When a room is reserved from a block of rooms, the reservation dates will always match the date range of the block - # All of the availability checking logic from Wave 2 should now respect room blocks as well as individual reservations - - - - -# I can create a Hotel Block if I give a date range, collection of rooms, and a discounted room rate -# I want an exception raised if I try to create a Hotel Block and at least one of the rooms is unavailable for the given date range -# Given a specific date, and that a room is set aside in a hotel block for that specific date, I cannot reserve that specific room for that specific date, because it is unavailable -# Given a specific date, and that a room is set aside in a hotel block for that specific date, I cannot create another hotel block that includes that specific room for that specific date, because it is unavailable -# I can check whether a given block has any rooms available -# I can reserve a specific room from a hotel block -# I can only reserve that room from a hotel block for the full duration of the block -# I can see a reservation made from a hotel block from the list of reservations for that date (see wave 1 requirements) \ No newline at end of file +end \ No newline at end of file diff --git a/test/reservation_test.rb b/test/reservation_test.rb index 17305dc3b..285c6e333 100644 --- a/test/reservation_test.rb +++ b/test/reservation_test.rb @@ -37,47 +37,4 @@ expect(@reservation01.get_total_price).must_equal 1000.00 end end -end - - - - -# describe Hotel::Reservation do -# before do -# start_date = Date.today + 5 -# end_date = Date.today + 10 -# room_id = 10 -# @reservation01 = Hotel::Reservation.new(start_date, end_date, room_id) -# end - -# describe "#initialize" do -# it "is an instance of Reservation" do -# expect(@reservation01).must_be_instance_of Hotel::Reservation -# end - -# it "automatic generates an ID for the reservation" do -# expect(@reservation01.id).must_be_instance_of Integer -# end - -# it "stores a date_range that is an instance of DateRange" do -# expect(@reservation01.date_range).must_be_instance_of Hotel::DateRange -# end - -# it "stores start_date and end_date that are both an instance of Date" do -# expect(@reservation01.start_date).must_be_instance_of Date -# expect(@reservation01.end_date).must_be_instance_of Date -# end - -# it "stores a room_id that is passed in as an argument" do -# expect(@reservation01.room_id).must_equal 10 -# end -# end - -# describe "#get_price" do -# it "returns the total price for the reservation" do -# expect(@reservation01.get_price).must_be_instance_of Float -# expect(@reservation01.get_price).must_equal 1000 -# end - -# end -# end +end \ No newline at end of file