From 34e5bc0a1c123fd82a90b80c97c1ff6407866caf Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Tue, 6 Mar 2018 20:24:06 -0800 Subject: [PATCH 01/16] Added 2 classes, reservation and administrator. They are responsible for intantiating new instances and that's about it right now. --- .gitignore | 1 + Rakefile | 9 ++++++++ lib/admin.rb | 47 +++++++++++++++++++++++++++++++++++++++ lib/reservation.rb | 30 +++++++++++++++++++++++++ specs/admin_spec.rb | 43 +++++++++++++++++++++++++++++++++++ specs/reservation_spec.rb | 34 ++++++++++++++++++++++++++++ specs/spec_helper.rb | 10 +++++++++ 7 files changed, 174 insertions(+) create mode 100644 Rakefile create mode 100644 lib/admin.rb create mode 100644 lib/reservation.rb create mode 100644 specs/admin_spec.rb create mode 100644 specs/reservation_spec.rb create mode 100644 specs/spec_helper.rb diff --git a/.gitignore b/.gitignore index 5e1422c9c..ce17d1737 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +coverage *.gem *.rbc /.config diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..deb52f2cd --- /dev/null +++ b/Rakefile @@ -0,0 +1,9 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs = ["lib"] + t.warning = true + t.test_files = FileList['specs/*_spec.rb'] +end + +task default: :test diff --git a/lib/admin.rb b/lib/admin.rb new file mode 100644 index 000000000..ebb85d9f6 --- /dev/null +++ b/lib/admin.rb @@ -0,0 +1,47 @@ +# access the list of all of the rooms in the hotel +# reserve a room for a given date range + # raise an error (StandardError) when an invalid date range is provided + # raise exception when asked to reserve room that isn't available (WAVE2) +# access the list of reservations for a specific date +# get the total cost for a given reservation + +### Constraints +# The last day of a reservation is the checkout day, so the guest should not be charged for that night + +require "date" + +module Hotel + class Administrator + + attr_reader :reservations + + COST = 200 + + def initialize() + @reservations = [] + end + + def select_room() + return rand(1..20) + end + + def make_reservation(check_in, check_out) + room_num = select_room + + new_reservation = Reservation.new(check_in, check_out) + + @reservations << new_reservation + + return new_reservation + end + + # def duration + # return (check_out - check_in) + # end + + # def total_cost + # COST * duration + # end + + end # class +end # module diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..5aab2e541 --- /dev/null +++ b/lib/reservation.rb @@ -0,0 +1,30 @@ +# time available for reservation (date range?) + + +module Hotel + class Reservation + # room is available if someone has not chosen that date + # change to occupied after date is chosen + attr_reader :check_in, :check_out + + def initialize(check_in, check_out) + @check_in = parse_date(check_in) + @check_out = parse_date(check_out) + end + + def parse_date(date) + return Date.parse(date) + end + + def check_dates + if @check_in > @check_out + raise ArgumentError.new("End date should be after the start date") + end + end + + + end # class + +end # module + +# customer1 = Hotel::Reservation.new(1,13, "12/2/2018", "12/3/2018") diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb new file mode 100644 index 000000000..40dfca5fa --- /dev/null +++ b/specs/admin_spec.rb @@ -0,0 +1,43 @@ +require_relative 'spec_helper' +require 'minitest/pride' +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/skip_dsl' + +require_relative '../lib/admin' + +describe "Admin" do + before do + @admin = Hotel::Administrator.new() + end + + it "initializes an Administrator" do + @admin.must_be_instance_of Hotel::Administrator + end + + it "can make a reservation" do + @admin.make_reservation("24/12/2018","25/12/2018") + + result = @admin.reservations + + result.first.check_in.must_equal("2018-12-24") + result.first.check_out.must_equal("2018-12-25") + + end + + it "can see the reservations" do + # Arrange + @admin.make_reservation("24/12/2018","01/01/2019") + # Act + result = @admin.reservations + # Assert + result.first.check_in.must_equal("24/12/2018") + + end + + # it "calculates the duration of the trip" do + # end + + # it "doesn't charge guest for last night" do + # end +end diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb new file mode 100644 index 000000000..a79e8f034 --- /dev/null +++ b/specs/reservation_spec.rb @@ -0,0 +1,34 @@ +require_relative 'spec_helper' +require 'minitest/pride' +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/skip_dsl' + +require_relative '../lib/admin' + +describe "Reservation" do + before do + @reserve1 = Hotel::Reservation.new("2019/10/30","2018/10/30") + end + + it "creates an instance of a reservation" do + @reserve1.must_be_instance_of Hotel::Reservation + end + + it "raises an error if an invalid date range provided" do + today = Time.now + check_out = today.strftime("%Y/%m/%d") + check_in = Date.parse("2019/10/29") + + puts "THIS IS CHECK IN DATE #{check_in}" + puts "THIS IS CHECK OUT DATE #{check_out}" + proc {@reserve1.check_dates}.must_raise ArgumentError + end + + # it "creates rooms array, numbered 1-20, on initialization" do + # admin = Hotel::Administrator.new + # admin.must_be_instance_of Hotel::Administrator + # end + + +end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 000000000..28b35ff0f --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,10 @@ +# require 'simplecov' +# SimpleCov.start + +require 'minitest/autorun' +require 'minitest/reporters' +require_relative '../lib/admin' +require_relative '../lib/reservation' + + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From fff4eb68f5c3924f8c3ca92509167c94f1be0240 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Wed, 7 Mar 2018 16:51:56 -0800 Subject: [PATCH 02/16] Fixed call_reservation method to receive two parameters and passing tests --- lib/admin.rb | 35 +++++++++++++-------- lib/reservation.rb | 16 +++++----- specs/admin_spec.rb | 64 ++++++++++++++++++++++++++------------- specs/reservation_spec.rb | 8 ++--- 4 files changed, 77 insertions(+), 46 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index ebb85d9f6..97c5a8d35 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -1,13 +1,6 @@ -# access the list of all of the rooms in the hotel -# reserve a room for a given date range - # raise an error (StandardError) when an invalid date range is provided - # raise exception when asked to reserve room that isn't available (WAVE2) -# access the list of reservations for a specific date # get the total cost for a given reservation -### Constraints -# The last day of a reservation is the checkout day, so the guest should not be charged for that night - +require "pry" require "date" module Hotel @@ -26,7 +19,7 @@ def select_room() end def make_reservation(check_in, check_out) - room_num = select_room + room_num = select_room # not actually stored in new_reservation new_reservation = Reservation.new(check_in, check_out) @@ -35,13 +28,31 @@ def make_reservation(check_in, check_out) return new_reservation end - # def duration - # return (check_out - check_in) + def call_reservation(start_date, end_date) + + start_parsed = Hotel::Reservation.parse_date(start_date) + end_parsed = Hotel::Reservation.parse_date(end_date) + + @reservations.each do |reservation| + if reservation.check_in == start_parsed && reservation.check_out == end_parsed + # return reservation + end + + return reservation + end + + end + + # def get_duration + # @reservations + # + # puts "THIS IS CHECK IN DATE #{call_reservation.check_in}" # end # def total_cost - # COST * duration + # get_reserved_dates.check_in...get_reserved_dates.check_out # end + # range of dates should end at second to last place (-2) end # class end # module diff --git a/lib/reservation.rb b/lib/reservation.rb index 5aab2e541..a88c97f30 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,19 +1,20 @@ # time available for reservation (date range?) - +require "pry" module Hotel + class Reservation # room is available if someone has not chosen that date # change to occupied after date is chosen - attr_reader :check_in, :check_out + attr_reader :check_in, :check_out, :parse_date def initialize(check_in, check_out) - @check_in = parse_date(check_in) - @check_out = parse_date(check_out) + @check_in = Reservation.parse_date(check_in) + @check_out = Reservation.parse_date(check_out) end - def parse_date(date) - return Date.parse(date) + def self.parse_date(date) # self necessary for calling class + return DateTime.strptime(date, "%d/%m/%Y") end def check_dates @@ -25,6 +26,5 @@ def check_dates end # class -end # module -# customer1 = Hotel::Reservation.new(1,13, "12/2/2018", "12/3/2018") +end # module diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 40dfca5fa..7d623ed29 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -7,37 +7,59 @@ require_relative '../lib/admin' describe "Admin" do - before do - @admin = Hotel::Administrator.new() - end + describe "Initialize" do + before do + @admin = Hotel::Administrator.new() + end - it "initializes an Administrator" do - @admin.must_be_instance_of Hotel::Administrator + it "initializes an Administrator" do + @admin.must_be_instance_of Hotel::Administrator + end end - it "can make a reservation" do - @admin.make_reservation("24/12/2018","25/12/2018") + describe "make reservations" do + before do + @admin = Hotel::Administrator.new() + end + + it "can make a reservation" do + @admin.make_reservation("24/12/2018", "25/12/2018") - result = @admin.reservations + result = @admin.reservations - result.first.check_in.must_equal("2018-12-24") - result.first.check_out.must_equal("2018-12-25") + result.first.check_in.must_be_instance_of DateTime + result.first.check_out.must_be_instance_of DateTime + end + it "can retrieve all reservations" do + # Arrange + @admin.make_reservation("24/12/2018", "25/12/2018") + # Act + result = @admin.reservations + # Assert + result.first.check_in.must_be_instance_of DateTime + end end - it "can see the reservations" do - # Arrange - @admin.make_reservation("24/12/2018","01/01/2019") - # Act - result = @admin.reservations - # Assert - result.first.check_in.must_equal("24/12/2018") + describe "return reservations" do + before do + @admin = Hotel::Administrator.new() + end + + it "can call all reservation on a given date" do + @admin.make_reservation("24/12/2018", "25/12/2018") + + result = @admin.call_reservation("24/12/2018", "25/12/2018") + # expected_checkin = DateTime("24/12/2018") + # expected_checkout = DateTime("25/12/2018") + result.must_be_instance_of Hotel::Reservation + end end - # it "calculates the duration of the trip" do - # end + describe "something valuable" do + it "checks the duration of the reservation" do - # it "doesn't charge guest for last night" do - # end + end + end end diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index a79e8f034..d134bf9a2 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -8,7 +8,7 @@ describe "Reservation" do before do - @reserve1 = Hotel::Reservation.new("2019/10/30","2018/10/30") + @reserve1 = Hotel::Reservation.new("30/10/2019","30/10/2018") end it "creates an instance of a reservation" do @@ -17,11 +17,9 @@ it "raises an error if an invalid date range provided" do today = Time.now - check_out = today.strftime("%Y/%m/%d") - check_in = Date.parse("2019/10/29") + check_out = today.strftime("%d/%m/%Y") + check_in = Date.parse("29/10/2019") - puts "THIS IS CHECK IN DATE #{check_in}" - puts "THIS IS CHECK OUT DATE #{check_out}" proc {@reserve1.check_dates}.must_raise ArgumentError end From 5ba4dd4192fb7eb67d7282135dc9b5e1ecdb29fd Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Thu, 8 Mar 2018 09:32:29 -0800 Subject: [PATCH 03/16] Checking if on branch master --- lib/admin.rb | 10 ---------- lib/reservation.rb | 16 ++++++++++++++++ specs/admin_spec.rb | 10 ++++------ specs/reservation_spec.rb | 23 ++++++++++++++++++++--- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 97c5a8d35..7afe56dbf 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -8,7 +8,6 @@ class Administrator attr_reader :reservations - COST = 200 def initialize() @reservations = [] @@ -43,15 +42,6 @@ def call_reservation(start_date, end_date) end - # def get_duration - # @reservations - # - # puts "THIS IS CHECK IN DATE #{call_reservation.check_in}" - # end - - # def total_cost - # get_reserved_dates.check_in...get_reserved_dates.check_out - # end # range of dates should end at second to last place (-2) end # class diff --git a/lib/reservation.rb b/lib/reservation.rb index a88c97f30..f1469d585 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -6,6 +6,8 @@ module Hotel class Reservation # room is available if someone has not chosen that date # change to occupied after date is chosen + COST = 200 + attr_reader :check_in, :check_out, :parse_date def initialize(check_in, check_out) @@ -23,6 +25,20 @@ def check_dates end end + def get_duration(check_in, check_out) + (@check_out - @check_in).to_i + # puts "THIS IS CHECK IN DATE #{call_reservation.check_in}" + end + + def total_cost + #get_reserved_dates.check_in...get_reserved_dates.check_out + stay_length = @reservations.get_duration(check_in, check_out) + + return COST * stay_length + + end + + end # class diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 7d623ed29..6fdaaeb68 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -49,17 +49,15 @@ it "can call all reservation on a given date" do @admin.make_reservation("24/12/2018", "25/12/2018") - result = @admin.call_reservation("24/12/2018", "25/12/2018") + get_reservation = @admin.call_reservation("24/12/2018", "25/12/2018") # expected_checkin = DateTime("24/12/2018") # expected_checkout = DateTime("25/12/2018") - result.must_be_instance_of Hotel::Reservation + get_reservation.must_be_instance_of Hotel::Reservation end end - describe "something valuable" do - it "checks the duration of the reservation" do + describe "calculates the cost of a stay" do - end - end + end end diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index d134bf9a2..190964384 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -22,10 +22,27 @@ proc {@reserve1.check_dates}.must_raise ArgumentError end +end + +describe "checks the lenth of stay" do + before do + @admin = Hotel::Administrator.new() + # @reserve1 = Hotel::Reservation.new("24/12/2018","25/12/2018") + end + + it "checks the duration of the reservation" do + reserve1 = @admin.make_reservation("24/12/2018", "25/12/2018") + + check_in = Date.parse("24/12/2018") + check_out = Date.parse("25/12/2018") + + stay_length = reserve1.get_duration(check_in, check_out) + + stay_length.must_equal(1) + end - # it "creates rooms array, numbered 1-20, on initialization" do - # admin = Hotel::Administrator.new - # admin.must_be_instance_of Hotel::Administrator + # it "gets the total cost of a stay " do + # # end From 4c20aa9ddf4b559bf0fde16d3d822b38be5d73b1 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Thu, 8 Mar 2018 15:26:05 -0800 Subject: [PATCH 04/16] added behavior to reservation class to calculate total cost of a reservation --- lib/admin.rb | 8 +++++--- lib/reservation.rb | 16 +++------------- specs/admin_spec.rb | 12 +++++++----- specs/reservation_spec.rb | 22 +++++++++------------- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 7afe56dbf..4eaefeb50 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -1,4 +1,4 @@ -# get the total cost for a given reservation +# An administrator can view a list of rooms not reserved for a given date range require "pry" require "date" @@ -17,13 +17,15 @@ def select_room() return rand(1..20) end - def make_reservation(check_in, check_out) + def make_reservation(check_in, check_out, room_num) room_num = select_room # not actually stored in new_reservation new_reservation = Reservation.new(check_in, check_out) @reservations << new_reservation + # binding.pry + return new_reservation end @@ -40,7 +42,7 @@ def call_reservation(start_date, end_date) return reservation end - end + end # call reservation # range of dates should end at second to last place (-2) diff --git a/lib/reservation.rb b/lib/reservation.rb index f1469d585..54f9c7868 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,17 +1,14 @@ -# time available for reservation (date range?) require "pry" module Hotel class Reservation - # room is available if someone has not chosen that date - # change to occupied after date is chosen COST = 200 attr_reader :check_in, :check_out, :parse_date def initialize(check_in, check_out) - @check_in = Reservation.parse_date(check_in) + @check_in = Reservation.parse\_date(check_in) @check_out = Reservation.parse_date(check_out) end @@ -25,22 +22,15 @@ def check_dates end end - def get_duration(check_in, check_out) + def get_stay_length (@check_out - @check_in).to_i - # puts "THIS IS CHECK IN DATE #{call_reservation.check_in}" end def total_cost - #get_reserved_dates.check_in...get_reserved_dates.check_out - stay_length = @reservations.get_duration(check_in, check_out) - - return COST * stay_length - + return (COST * (get_stay_length - 1)) end - end # class - end # module diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 6fdaaeb68..d5b85e7a8 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -44,20 +44,22 @@ describe "return reservations" do before do @admin = Hotel::Administrator.new() + @admin.make_reservation("24/12/2018", "25/12/2018") end it "can call all reservation on a given date" do - @admin.make_reservation("24/12/2018", "25/12/2018") - get_reservation = @admin.call_reservation("24/12/2018", "25/12/2018") - # expected_checkin = DateTime("24/12/2018") - # expected_checkout = DateTime("25/12/2018") get_reservation.must_be_instance_of Hotel::Reservation end end - describe "calculates the cost of a stay" do + describe "admin viewing available rooms" do + it "view rooms not reserved for a given date range" + # Arrange need instance of admin, not date + + # Act + # Assert end end diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 190964384..29d6cc172 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -25,25 +25,21 @@ end describe "checks the lenth of stay" do - before do - @admin = Hotel::Administrator.new() - # @reserve1 = Hotel::Reservation.new("24/12/2018","25/12/2018") - end it "checks the duration of the reservation" do - reserve1 = @admin.make_reservation("24/12/2018", "25/12/2018") + reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018") + + reserve1.get_stay_length.must_equal(2) + end +end - check_in = Date.parse("24/12/2018") - check_out = Date.parse("25/12/2018") +describe "returns the cost of the reservation" do - stay_length = reserve1.get_duration(check_in, check_out) + it "gets the total cost of a stay " do + reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018") - stay_length.must_equal(1) + reserve1.total_cost.must_equal(200) end - # it "gets the total cost of a stay " do - # - # end - end From 5925a4a86b14142834707d6c64a166f411c64694 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Thu, 8 Mar 2018 17:36:56 -0800 Subject: [PATCH 05/16] added room number back into both classes --- lib/admin.rb | 31 +++++++++++++++++++++++++------ lib/reservation.rb | 5 +++-- specs/admin_spec.rb | 24 +++++++++++++++--------- specs/reservation_spec.rb | 6 +++--- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 4eaefeb50..8dda592d2 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -14,13 +14,13 @@ def initialize() end def select_room() - return rand(1..20) + # return rand(1..20) end def make_reservation(check_in, check_out, room_num) - room_num = select_room # not actually stored in new_reservation + # room_num = select_room - new_reservation = Reservation.new(check_in, check_out) + new_reservation = Reservation.new(check_in, check_out, room_num) @reservations << new_reservation @@ -29,14 +29,15 @@ def make_reservation(check_in, check_out, room_num) return new_reservation end - def call_reservation(start_date, end_date) + def call_reservation(start_date, end_date) #calls reservation + + # call only if dates don't overlap, assign any room # start_parsed = Hotel::Reservation.parse_date(start_date) end_parsed = Hotel::Reservation.parse_date(end_date) @reservations.each do |reservation| if reservation.check_in == start_parsed && reservation.check_out == end_parsed - # return reservation end return reservation @@ -44,7 +45,25 @@ def call_reservation(start_date, end_date) end # call reservation + def see_available (start_date, end_date) #calls reservation + + # call only if dates don't overlap, assign any room # + + start_parsed = Hotel::Reservation.parse_date(start_date) + end_parsed = Hotel::Reservation.parse_date(end_date) + + # if reservation in array has check in date, then don't + # return that room + # else return rooms that are available + + @reservations.each do |reservation| + if reservation.check_in == start_parsed && reservation.check_out == end_parsed + end + + return reservation + end + + end # see_available - # range of dates should end at second to last place (-2) end # class end # module diff --git a/lib/reservation.rb b/lib/reservation.rb index 54f9c7868..1fa86a53d 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -7,9 +7,10 @@ class Reservation attr_reader :check_in, :check_out, :parse_date - def initialize(check_in, check_out) - @check_in = Reservation.parse\_date(check_in) + def initialize(check_in, check_out, room_num) + @check_in = Reservation.parse_date(check_in) @check_out = Reservation.parse_date(check_out) + @room_num = room_num end def self.parse_date(date) # self necessary for calling class diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index d5b85e7a8..629613b3c 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -23,7 +23,7 @@ end it "can make a reservation" do - @admin.make_reservation("24/12/2018", "25/12/2018") + @admin.make_reservation("24/12/2018", "25/12/2018", 1) result = @admin.reservations @@ -33,7 +33,7 @@ it "can retrieve all reservations" do # Arrange - @admin.make_reservation("24/12/2018", "25/12/2018") + @admin.make_reservation("24/12/2018", "25/12/2018", 1) # Act result = @admin.reservations # Assert @@ -44,7 +44,7 @@ describe "return reservations" do before do @admin = Hotel::Administrator.new() - @admin.make_reservation("24/12/2018", "25/12/2018") + @admin.make_reservation("24/12/2018", "25/12/2018", 1) end it "can call all reservation on a given date" do @@ -55,11 +55,17 @@ end describe "admin viewing available rooms" do - it "view rooms not reserved for a given date range" - # Arrange need instance of admin, not date + before do + @admin = Hotel::Administrator.new() + @admin.make_reservation("24/12/2018", "30/12/2018", 1) + end - # Act + it "view rooms not available for a given date range" do + @admin.see_reservation("24/12/2018", "30/12/2018") - # Assert - end -end + # return room if the dates aren't overlapping + # room numbers associated with that reservation are thus unavailable + # there are no pre-set available rooms + end + end # admin viewing +end # Admin diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 29d6cc172..a15f29b20 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -8,7 +8,7 @@ describe "Reservation" do before do - @reserve1 = Hotel::Reservation.new("30/10/2019","30/10/2018") + @reserve1 = Hotel::Reservation.new("30/10/2019","30/10/2018", 1) end it "creates an instance of a reservation" do @@ -27,7 +27,7 @@ describe "checks the lenth of stay" do it "checks the duration of the reservation" do - reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018") + reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018", 1) reserve1.get_stay_length.must_equal(2) end @@ -36,7 +36,7 @@ describe "returns the cost of the reservation" do it "gets the total cost of a stay " do - reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018") + reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018", 1) reserve1.total_cost.must_equal(200) end From 129c7ed89c8955d4a48d0402aa3408901f7068b1 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Fri, 9 Mar 2018 11:19:15 -0800 Subject: [PATCH 06/16] added functionality to turn dates into a range in the admin class. --- lib/admin.rb | 38 +++++++++++++++++++++----------------- specs/admin_spec.rb | 16 +++++++++++++++- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 8dda592d2..9841bbf97 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -13,9 +13,9 @@ def initialize() @reservations = [] end - def select_room() - # return rand(1..20) - end + # def select_room() + # return rand(1..20) + # end def make_reservation(check_in, check_out, room_num) # room_num = select_room @@ -29,9 +29,7 @@ def make_reservation(check_in, check_out, room_num) return new_reservation end - def call_reservation(start_date, end_date) #calls reservation - - # call only if dates don't overlap, assign any room # + def call_reservation(start_date, end_date) #is this class doing what you think/want start_parsed = Hotel::Reservation.parse_date(start_date) end_parsed = Hotel::Reservation.parse_date(end_date) @@ -45,24 +43,30 @@ def call_reservation(start_date, end_date) #calls reservation end # call reservation - def see_available (start_date, end_date) #calls reservation - - # call only if dates don't overlap, assign any room # - - start_parsed = Hotel::Reservation.parse_date(start_date) - end_parsed = Hotel::Reservation.parse_date(end_date) + def see_available(requested_date) + # call only if dates don't overlap, assign any room # + # if reservation in array has check in date, then don't + # return that room + # else return rooms that are available + # + # start_parsed = Hotel::Reservation.parse_date(start_date) + # end_parsed = Hotel::Reservation.parse_date(end_date) - # if reservation in array has check in date, then don't - # return that room - # else return rooms that are available + # upto(max){|date| ...} @reservations.each do |reservation| - if reservation.check_in == start_parsed && reservation.check_out == end_parsed + date_range = reservation.check_in.upto(reservation.check_out - 1) + + date_range.each do |individual_day| + until individual_day != requested_date + return room_num + end end - return reservation end + + end # see_available end # class diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 629613b3c..82fd6e6da 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -61,11 +61,25 @@ end it "view rooms not available for a given date range" do - @admin.see_reservation("24/12/2018", "30/12/2018") + # @admin.see_available("24/12/2018", "30/12/2018") + # return room if the dates aren't overlapping # room numbers associated with that reservation are thus unavailable # there are no pre-set available rooms end + + it "return all rooms if the array is empty" do + + end + + it "if check_out day falls on first day of new request then make reservation" do + + end + + it "if requested reservation dates fall in between another reservation, then unavailable (not including last day)" do + + end + end # admin viewing end # Admin From df18a06b00e4f68375bffba0c57c2f14fb6d9f3e Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Fri, 9 Mar 2018 14:51:02 -0800 Subject: [PATCH 07/16] added functionality to see the list of rooms available --- lib/admin.rb | 31 ++++++++++++++++++------------- lib/reservation.rb | 2 +- specs/admin_spec.rb | 29 +++++++++++++---------------- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 9841bbf97..2913176a7 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -11,6 +11,7 @@ class Administrator def initialize() @reservations = [] + @rooms = (1..20).to_a end # def select_room() @@ -24,8 +25,6 @@ def make_reservation(check_in, check_out, room_num) @reservations << new_reservation - # binding.pry - return new_reservation end @@ -43,29 +42,35 @@ def call_reservation(start_date, end_date) #is this class doing what you think/w end # call reservation - def see_available(requested_date) - # call only if dates don't overlap, assign any room # + def see_available(requested_date) # eventually turn to range also? # if reservation in array has check in date, then don't - # return that room - # else return rooms that are available - # - # start_parsed = Hotel::Reservation.parse_date(start_date) + # push that reservation into an unvailable array + # the unavail array can be compared against complete list of rooms + requested_date = Hotel::Reservation.parse_date(requested_date) # end_parsed = Hotel::Reservation.parse_date(end_date) - # upto(max){|date| ...} + + unavailable_rooms = [] @reservations.each do |reservation| date_range = reservation.check_in.upto(reservation.check_out - 1) - date_range.each do |individual_day| - until individual_day != requested_date - return room_num + date_range.each do |reserved_day| + if reserved_day == requested_date + # pushing the unavail room here + unavailable_rooms << reservation.room_num + break end + puts "THIS IS RESERVED DATE #{reserved_day}" end - end + end # outside each loop + return @rooms.find_all do |room_no| #looks at each room + !unavailable_rooms.include? room_no + end + end # see_available diff --git a/lib/reservation.rb b/lib/reservation.rb index 1fa86a53d..f15808f5c 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -5,7 +5,7 @@ module Hotel class Reservation COST = 200 - attr_reader :check_in, :check_out, :parse_date + attr_reader :check_in, :check_out, :parse_date, :room_num def initialize(check_in, check_out, room_num) @check_in = Reservation.parse_date(check_in) diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 82fd6e6da..dfa20acfa 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -61,25 +61,22 @@ end it "view rooms not available for a given date range" do - # @admin.see_available("24/12/2018", "30/12/2018") + available_rooms = @admin.see_available("24/12/2018") - - # return room if the dates aren't overlapping - # room numbers associated with that reservation are thus unavailable - # there are no pre-set available rooms + available_rooms.must_equal (2..20).to_a end - it "return all rooms if the array is empty" do - - end - - it "if check_out day falls on first day of new request then make reservation" do - - end - - it "if requested reservation dates fall in between another reservation, then unavailable (not including last day)" do - - end + # it "return all rooms if the array is empty" do + # + # end + # + # it "if check_out day falls on first day of new request then make reservation" do + # + # end + # + # it "if requested reservation dates fall in between another reservation, then unavailable (not including last day)" do + # + # end end # admin viewing end # Admin From 850e10170963db2bb1ed11288c90ff1c856f30e0 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Fri, 9 Mar 2018 16:54:30 -0800 Subject: [PATCH 08/16] re-wrote tests to check that reservations don't conflict --- lib/admin.rb | 2 +- specs/admin_spec.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 2913176a7..96e7b284d 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -53,7 +53,7 @@ def see_available(requested_date) # eventually turn to range also? unavailable_rooms = [] @reservations.each do |reservation| - date_range = reservation.check_in.upto(reservation.check_out - 1) + date_range = reservation.check_in.upto(reservation.check_out) date_range.each do |reserved_day| if reserved_day == requested_date diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index dfa20acfa..2ecab834b 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -60,23 +60,23 @@ @admin.make_reservation("24/12/2018", "30/12/2018", 1) end - it "view rooms not available for a given date range" do + it "view rooms not reserved for a given date range" do available_rooms = @admin.see_available("24/12/2018") available_rooms.must_equal (2..20).to_a end - # it "return all rooms if the array is empty" do + it "returns an error if requested reservation check in date is before another reservation's end date" do + + end + + # it "returns a reservation request if the check in date is on or after another reservation's check out date" do # # end - # - # it "if check_out day falls on first day of new request then make reservation" do + + # it "return all rooms if the array is empty" do # # end # - # it "if requested reservation dates fall in between another reservation, then unavailable (not including last day)" do - # - # end - end # admin viewing end # Admin From 6aa18cfab8c1864258d749d890d682c42267844d Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Sat, 10 Mar 2018 00:09:46 -0800 Subject: [PATCH 09/16] Included conditionals in the make reservation method of the admin class. Tests have not been updated. --- lib/admin.rb | 37 +++++++++++++++++++++++-------------- lib/reservation.rb | 3 ++- specs/admin_spec.rb | 29 ++++++++++++++++++++++++----- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 96e7b284d..0218e6680 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -14,21 +14,34 @@ def initialize() @rooms = (1..20).to_a end - # def select_room() - # return rand(1..20) - # end + def select_room() + # return rand(1..20) + # grab a room from @rooms + end - def make_reservation(check_in, check_out, room_num) + def make_reservation(requested_check_in, requested_check_out, room_num) # room_num = select_room - new_reservation = Reservation.new(check_in, check_out, room_num) + # def check_dates + @reservation.each do |reservation| + if reservation.check_in == requested_check_in || reservation.check_out == requested_check_out + raise ArgumentError.new("Date unavailable") + elsif requested_check_in < reservation.check_out + raise ArgumentError.new("Date unavailable") + elsif requested_check_in >= reservation.check_in && requested_check_out >= reservation.check_out + raise ArgumentError.new("Date unavailable") + end # conditional + end + # end + + new_reservation = Reservation.new(requested_check_in, requested_check_out, room_num) @reservations << new_reservation return new_reservation end - def call_reservation(start_date, end_date) #is this class doing what you think/want + def call_reservation(start_date, end_date) start_parsed = Hotel::Reservation.parse_date(start_date) end_parsed = Hotel::Reservation.parse_date(end_date) @@ -42,13 +55,9 @@ def call_reservation(start_date, end_date) #is this class doing what you think/w end # call reservation - def see_available(requested_date) # eventually turn to range also? - # if reservation in array has check in date, then don't - # push that reservation into an unvailable array - # the unavail array can be compared against complete list of rooms - requested_date = Hotel::Reservation.parse_date(requested_date) - # end_parsed = Hotel::Reservation.parse_date(end_date) + def see_available(requested_date) + requested_date = Hotel::Reservation.parse_date(requested_date) unavailable_rooms = [] @@ -61,13 +70,13 @@ def see_available(requested_date) # eventually turn to range also? unavailable_rooms << reservation.room_num break end - puts "THIS IS RESERVED DATE #{reserved_day}" + # puts "THIS IS RESERVED DATE #{reserved_day}" end end # outside each loop - return @rooms.find_all do |room_no| #looks at each room + return @rooms.find_all do |room_no| !unavailable_rooms.include? room_no end diff --git a/lib/reservation.rb b/lib/reservation.rb index f15808f5c..8fbb1ad97 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -19,10 +19,11 @@ def self.parse_date(date) # self necessary for calling class def check_dates if @check_in > @check_out - raise ArgumentError.new("End date should be after the start date") + raise ArgumentError.new("Dates unavailable") end end + def get_stay_length (@check_out - @check_in).to_i end diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 2ecab834b..c3d342dfd 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -66,17 +66,36 @@ available_rooms.must_equal (2..20).to_a end - it "returns an error if requested reservation check in date is before another reservation's end date" do + it "returns an error if requested reservation has same date as an existing reservation" do + @admin.make_reservation("24/12/2018", "30/12/2018", 0) + # assign room_num from the rooms instance variable? + + end - # it "returns a reservation request if the check in date is on or after another reservation's check out date" do - # - # end + it "returns an error if requested reservation overlaps in the back" do + @admin.make_reservation("30/12/2018", "02/01/2019", 0) + # have one appt, try to make another + end + + it "returns an error if requested reservation overlaps in the front" do + @admin.make_reservation("20/12/2018", "24/12/2018", 0) + # have one appt, try to make another + end + + it "returns an error if requested reservation is completely contained" do + @admin.make_reservation("26/12/2018", "27/12/2018", 0) + # have one appt, try to make another + end + it "returns an error if requested reservation is completely containing an existing reservation" do + @admin.make_reservation("23/12/2018", "01/01/2019", 0) + # have one appt, try to make another + end # it "return all rooms if the array is empty" do # # end - # + end # admin viewing end # Admin From 2642f1edff653166cba33228bdbbe43407574955 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Sat, 10 Mar 2018 12:39:25 -0800 Subject: [PATCH 10/16] added test code for see availability function in admin class --- lib/admin.rb | 116 ++++++++++++++++++++++++++++++++------------ lib/reservation.rb | 3 +- specs/admin_spec.rb | 19 ++++---- 3 files changed, 96 insertions(+), 42 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 0218e6680..825f1b13a 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -10,20 +10,49 @@ class Administrator def initialize() - @reservations = [] - @rooms = (1..20).to_a + @rooms = {} + + (1..20).each do | room_num | + @rooms[room_num] = [] + end + end - def select_room() - # return rand(1..20) - # grab a room from @rooms + + + + + def make_reservation(requested_check_in, requested_check_out) + available_rooms = see_available(requested_check_in, requested_check_out) + if(available_rooms.length == 0 ) do + raise 'No room Available' + end + + #Many cases + # (1..requested_rooms).each do | res_num | do + # @rooms[available_rooms[res_num]] << Reservation.new .... + + + #Single Case Below + @rooms[available_rooms[0]] << Reservation.new .... + + if (is_room_available) do + #make new reservations + #add it it to this rooms reservations + new_reservation = Reservation.new(requested_check_in, requested_check_out, room_num) + + return + end end - def make_reservation(requested_check_in, requested_check_out, room_num) - # room_num = select_room + end - # def check_dates - @reservation.each do |reservation| + def make_reservation(requested_check_in, requested_check_out) + see_available + + @rooms.each do |room_num, reservations| + is_room_available = true + reservations.each do | reservation | if reservation.check_in == requested_check_in || reservation.check_out == requested_check_out raise ArgumentError.new("Date unavailable") elsif requested_check_in < reservation.check_out @@ -31,14 +60,19 @@ def make_reservation(requested_check_in, requested_check_out, room_num) elsif requested_check_in >= reservation.check_in && requested_check_out >= reservation.check_out raise ArgumentError.new("Date unavailable") end # conditional + end - # end + if (is_room_available) do + #make new reservations + #add it it to this rooms reservations + new_reservation = Reservation.new(requested_check_in, requested_check_out, room_num) + + return + end + end - new_reservation = Reservation.new(requested_check_in, requested_check_out, room_num) - @reservations << new_reservation - return new_reservation end def call_reservation(start_date, end_date) @@ -55,33 +89,53 @@ def call_reservation(start_date, end_date) end # call reservation - def see_available(requested_date) + def see_available(requested_check_in, requested_check_out) - requested_date = Hotel::Reservation.parse_date(requested_date) + available_rooms = [] - unavailable_rooms = [] + @rooms.each do |room_num, reservations| + reservations.each do |reservation| - @reservations.each do |reservation| - date_range = reservation.check_in.upto(reservation.check_out) + if requested_check_in >= reservation.check_in + && requested_check_out <= reservation.check_out + next + + elsif requested_check_in < reservation.check_in && requested_check_out <= reservation.check_out + next - date_range.each do |reserved_day| - if reserved_day == requested_date - # pushing the unavail room here - unavailable_rooms << reservation.room_num - break + elsif requested_check_in >= reservation.check_in && requested_check_out >= reservation.check_out end - # puts "THIS IS RESERVED DATE #{reserved_day}" end + available_rooms << room_num + end + return available_rooms + end - end # outside each loop - - - return @rooms.find_all do |room_no| - !unavailable_rooms.include? room_no + # requested_date = Hotel::Reservation.parse_date(requested_date) + # + # unavailable_rooms = [] + # + @reservations.each do |reservation| + date_range = reservation.check_in.upto(reservation.check_out) + + date_range.each do |reserved_day| + if reserved_day == requested_date + # pushing the unavail room here + unavailable_rooms << reservation.room_num + break + end + # puts "THIS IS RESERVED DATE #{reserved_day}" end + end # outside each loop + # + # + # return @rooms.find_all do |room_no| + # !unavailable_rooms.include? room_no + # end + - end # see_available + end # see_available - end # class +end # class end # module diff --git a/lib/reservation.rb b/lib/reservation.rb index 8fbb1ad97..f13eeddc3 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -13,6 +13,7 @@ def initialize(check_in, check_out, room_num) @room_num = room_num end + def self.parse_date(date) # self necessary for calling class return DateTime.strptime(date, "%d/%m/%Y") end @@ -23,7 +24,7 @@ def check_dates end end - + def get_stay_length (@check_out - @check_in).to_i end diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index c3d342dfd..ce6323a76 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -23,7 +23,7 @@ end it "can make a reservation" do - @admin.make_reservation("24/12/2018", "25/12/2018", 1) + @admin.make_reservation("24/12/2018", "25/12/2018") result = @admin.reservations @@ -33,7 +33,7 @@ it "can retrieve all reservations" do # Arrange - @admin.make_reservation("24/12/2018", "25/12/2018", 1) + @admin.make_reservation("24/12/2018", "25/12/2018") # Act result = @admin.reservations # Assert @@ -44,7 +44,7 @@ describe "return reservations" do before do @admin = Hotel::Administrator.new() - @admin.make_reservation("24/12/2018", "25/12/2018", 1) + @admin.make_reservation("24/12/2018", "25/12/2018") end it "can call all reservation on a given date" do @@ -57,7 +57,7 @@ describe "admin viewing available rooms" do before do @admin = Hotel::Administrator.new() - @admin.make_reservation("24/12/2018", "30/12/2018", 1) + @admin.make_reservation("24/12/2018", "30/12/2018") end it "view rooms not reserved for a given date range" do @@ -67,30 +67,29 @@ end it "returns an error if requested reservation has same date as an existing reservation" do - @admin.make_reservation("24/12/2018", "30/12/2018", 0) + @admin.make_reservation("24/12/2018", "30/12/2018") # assign room_num from the rooms instance variable? - end it "returns an error if requested reservation overlaps in the back" do - @admin.make_reservation("30/12/2018", "02/01/2019", 0) + @admin.make_reservation("30/12/2018", "02/01/2019") # have one appt, try to make another end it "returns an error if requested reservation overlaps in the front" do - @admin.make_reservation("20/12/2018", "24/12/2018", 0) + @admin.make_reservation("20/12/2018", "24/12/2018") # have one appt, try to make another end it "returns an error if requested reservation is completely contained" do - @admin.make_reservation("26/12/2018", "27/12/2018", 0) + @admin.make_reservation("26/12/2018", "27/12/2018") # have one appt, try to make another end it "returns an error if requested reservation is completely containing an existing reservation" do - @admin.make_reservation("23/12/2018", "01/01/2019", 0) + @admin.make_reservation("23/12/2018", "01/01/2019") # have one appt, try to make another end # it "return all rooms if the array is empty" do From b1eb10b331d91d5b53ec7eccd8afe1aab8e47729 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Sat, 10 Mar 2018 16:08:07 -0800 Subject: [PATCH 11/16] refactoring code; cleaning up, but broken tests --- lib/admin.rb | 102 ++++++-------------------------------------- specs/admin_spec.rb | 6 +-- 2 files changed, 15 insertions(+), 93 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 825f1b13a..f0c465e83 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -1,5 +1,3 @@ -# An administrator can view a list of rooms not reserved for a given date range - require "pry" require "date" @@ -12,82 +10,29 @@ class Administrator def initialize() @rooms = {} - (1..20).each do | room_num | + (1..20).each do | room_num | #creates arrays where room_num is key @rooms[room_num] = [] end - - end - - - - - - def make_reservation(requested_check_in, requested_check_out) - available_rooms = see_available(requested_check_in, requested_check_out) - if(available_rooms.length == 0 ) do - raise 'No room Available' - end - - #Many cases - # (1..requested_rooms).each do | res_num | do - # @rooms[available_rooms[res_num]] << Reservation.new .... - - - #Single Case Below - @rooms[available_rooms[0]] << Reservation.new .... - - if (is_room_available) do - #make new reservations - #add it it to this rooms reservations - new_reservation = Reservation.new(requested_check_in, requested_check_out, room_num) - - return - end + binding.pry end - end def make_reservation(requested_check_in, requested_check_out) - see_available - - @rooms.each do |room_num, reservations| - is_room_available = true - reservations.each do | reservation | - if reservation.check_in == requested_check_in || reservation.check_out == requested_check_out - raise ArgumentError.new("Date unavailable") - elsif requested_check_in < reservation.check_out - raise ArgumentError.new("Date unavailable") - elsif requested_check_in >= reservation.check_in && requested_check_out >= reservation.check_out - raise ArgumentError.new("Date unavailable") - end # conditional + available_rooms = see_available(requested_check_in, requested_check_out) #calls available rooms based on given dates - end - if (is_room_available) do - #make new reservations - #add it it to this rooms reservations - new_reservation = Reservation.new(requested_check_in, requested_check_out, room_num) - - return - end + if available_rooms.length == 0 + raise ArgumentError.new('No rooms available') end + #Many cases (block rooms) + # (1..requested_rooms).each do | res_num | do + # @rooms[available_rooms[res_num]] << Reservation.new .... + #Single Case Below + @rooms[available_rooms[0]] << Reservation.new(requested_check_in, requested_check_out,) #the first available room is chosen and pushed to @rooms array for that room end - def call_reservation(start_date, end_date) - - start_parsed = Hotel::Reservation.parse_date(start_date) - end_parsed = Hotel::Reservation.parse_date(end_date) - - @reservations.each do |reservation| - if reservation.check_in == start_parsed && reservation.check_out == end_parsed - end - - return reservation - end - - end # call reservation def see_available(requested_check_in, requested_check_out) @@ -104,37 +49,14 @@ def see_available(requested_check_in, requested_check_out) next elsif requested_check_in >= reservation.check_in && requested_check_out >= reservation.check_out - end + + end # if conditional end available_rooms << room_num end return available_rooms end - # requested_date = Hotel::Reservation.parse_date(requested_date) - # - # unavailable_rooms = [] - # - @reservations.each do |reservation| - date_range = reservation.check_in.upto(reservation.check_out) - - date_range.each do |reserved_day| - if reserved_day == requested_date - # pushing the unavail room here - unavailable_rooms << reservation.room_num - break - end - # puts "THIS IS RESERVED DATE #{reserved_day}" - end - - end # outside each loop - # - # - # return @rooms.find_all do |room_no| - # !unavailable_rooms.include? room_no - # end - - end # see_available end # class diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index ce6323a76..bda46f697 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -48,7 +48,7 @@ end it "can call all reservation on a given date" do - get_reservation = @admin.call_reservation("24/12/2018", "25/12/2018") + get_reservation = @admin.see_available("24/12/2018", "25/12/2018") get_reservation.must_be_instance_of Hotel::Reservation end @@ -61,9 +61,9 @@ end it "view rooms not reserved for a given date range" do - available_rooms = @admin.see_available("24/12/2018") + available_rooms = @admin.see_available("24/12/2018", "30/12/2018") - available_rooms.must_equal (2..20).to_a + # available_rooms.must_equal (2..20).to_a end it "returns an error if requested reservation has same date as an existing reservation" do From 1784fe8e41753f6d7e73942a30e7a7eff136dfbe Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Sun, 11 Mar 2018 18:31:54 -0700 Subject: [PATCH 12/16] adjusted end statement causing errors --- lib/admin.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index f0c465e83..1fa73fbc8 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -10,10 +10,10 @@ class Administrator def initialize() @rooms = {} - (1..20).each do | room_num | #creates arrays where room_num is key + (1..20).each do |room_num| #creates arrays where room_num is key @rooms[room_num] = [] end - binding.pry + # binding.pry end @@ -41,23 +41,20 @@ def see_available(requested_check_in, requested_check_out) @rooms.each do |room_num, reservations| reservations.each do |reservation| - if requested_check_in >= reservation.check_in - && requested_check_out <= reservation.check_out + if requested_check_in >= reservation.check_in && requested_check_out <= reservation.check_out next elsif requested_check_in < reservation.check_in && requested_check_out <= reservation.check_out next elsif requested_check_in >= reservation.check_in && requested_check_out >= reservation.check_out - end # if conditional + end available_rooms << room_num end return available_rooms - end - - end # see_available + end # see_available -end # class + end # class end # module From e10b3138780edecda4de2ebb81c28dbddce145d4 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Mon, 12 Mar 2018 21:06:11 -0700 Subject: [PATCH 13/16] making progress on updating tests given new room structure --- lib/admin.rb | 7 +++--- lib/reservation.rb | 6 ++--- specs/admin_spec.rb | 46 +++++++++++++-------------------------- specs/reservation_spec.rb | 6 ++--- specs/spec_helper.rb | 4 ++-- 5 files changed, 26 insertions(+), 43 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 1fa73fbc8..2f86bac0a 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -4,8 +4,7 @@ module Hotel class Administrator - attr_reader :reservations - + attr_reader :rooms def initialize() @rooms = {} @@ -28,8 +27,8 @@ def make_reservation(requested_check_in, requested_check_out) # (1..requested_rooms).each do | res_num | do # @rooms[available_rooms[res_num]] << Reservation.new .... - #Single Case Below - @rooms[available_rooms[0]] << Reservation.new(requested_check_in, requested_check_out,) #the first available room is chosen and pushed to @rooms array for that room + #Single case below + @rooms[available_rooms[0]] << Reservation.new(requested_check_in, requested_check_out) #first available room is chosen and pushed to @rooms array for that room end diff --git a/lib/reservation.rb b/lib/reservation.rb index f13eeddc3..a6eae6957 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -5,12 +5,12 @@ module Hotel class Reservation COST = 200 - attr_reader :check_in, :check_out, :parse_date, :room_num + attr_reader :check_in, :check_out, :parse_date #, :room_num - def initialize(check_in, check_out, room_num) + def initialize(check_in, check_out) @check_in = Reservation.parse_date(check_in) @check_out = Reservation.parse_date(check_out) - @room_num = room_num + # @room_num = room_num end diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index bda46f697..2912ae9c8 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -25,54 +25,39 @@ it "can make a reservation" do @admin.make_reservation("24/12/2018", "25/12/2018") - result = @admin.reservations + result = @admin.rooms[1] result.first.check_in.must_be_instance_of DateTime result.first.check_out.must_be_instance_of DateTime end - it "can retrieve all reservations" do - # Arrange - @admin.make_reservation("24/12/2018", "25/12/2018") - # Act - result = @admin.reservations - # Assert - result.first.check_in.must_be_instance_of DateTime - end end - describe "return reservations" do + describe "establishes room structure on instantiation" do before do @admin = Hotel::Administrator.new() - @admin.make_reservation("24/12/2018", "25/12/2018") end + it "establishes the base room structure" do + room_array = @rooms - it "can call all reservation on a given date" do - get_reservation = @admin.see_available("24/12/2018", "25/12/2018") + room_array.must_be_kind_of NilClass + # room_array.count.must_equal 20 + end - get_reservation.must_be_instance_of Hotel::Reservation + it "has empty arrays upon instantiation" do + result = @admin.rooms[1] + result.must_be_kind_of Array end end - describe "admin viewing available rooms" do - before do - @admin = Hotel::Administrator.new() - @admin.make_reservation("24/12/2018", "30/12/2018") - end + + xdescribe "more tests" do it "view rooms not reserved for a given date range" do available_rooms = @admin.see_available("24/12/2018", "30/12/2018") - # available_rooms.must_equal (2..20).to_a end - it "returns an error if requested reservation has same date as an existing reservation" do - @admin.make_reservation("24/12/2018", "30/12/2018") - # assign room_num from the rooms instance variable? - - - end - it "returns an error if requested reservation overlaps in the back" do @admin.make_reservation("30/12/2018", "02/01/2019") # have one appt, try to make another @@ -92,9 +77,8 @@ @admin.make_reservation("23/12/2018", "01/01/2019") # have one appt, try to make another end - # it "return all rooms if the array is empty" do - # - # end - end # admin viewing + it "return all rooms if the array is empty" do + end + end end # Admin diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index a15f29b20..29d6cc172 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -8,7 +8,7 @@ describe "Reservation" do before do - @reserve1 = Hotel::Reservation.new("30/10/2019","30/10/2018", 1) + @reserve1 = Hotel::Reservation.new("30/10/2019","30/10/2018") end it "creates an instance of a reservation" do @@ -27,7 +27,7 @@ describe "checks the lenth of stay" do it "checks the duration of the reservation" do - reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018", 1) + reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018") reserve1.get_stay_length.must_equal(2) end @@ -36,7 +36,7 @@ describe "returns the cost of the reservation" do it "gets the total cost of a stay " do - reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018", 1) + reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018") reserve1.total_cost.must_equal(200) end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 28b35ff0f..d66e3cc56 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -1,5 +1,5 @@ -# require 'simplecov' -# SimpleCov.start +require 'simplecov' +SimpleCov.start require 'minitest/autorun' require 'minitest/reporters' From 1a7adad4789b49dfa2609315a4705c2a8d49c1a1 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Mon, 12 Mar 2018 21:39:12 -0700 Subject: [PATCH 14/16] passing tests in admin spec file --- lib/admin.rb | 10 ++++---- specs/admin_spec.rb | 58 ++++++++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 2f86bac0a..c6e020ca2 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -9,7 +9,7 @@ class Administrator def initialize() @rooms = {} - (1..20).each do |room_num| #creates arrays where room_num is key + (1..20).each do |room_num| @rooms[room_num] = [] end # binding.pry @@ -34,19 +34,21 @@ def make_reservation(requested_check_in, requested_check_out) def see_available(requested_check_in, requested_check_out) + parsed_req_in = DateTime.strptime(requested_check_in, "%d/%m/%Y") + parsed_req_out = DateTime.strptime(requested_check_out, "%d/%m/%Y") available_rooms = [] @rooms.each do |room_num, reservations| reservations.each do |reservation| - if requested_check_in >= reservation.check_in && requested_check_out <= reservation.check_out + if parsed_req_in >= reservation.check_in && parsed_req_out <= reservation.check_out next - elsif requested_check_in < reservation.check_in && requested_check_out <= reservation.check_out + elsif parsed_req_in < reservation.check_in && parsed_req_out <= reservation.check_out next - elsif requested_check_in >= reservation.check_in && requested_check_out >= reservation.check_out + elsif parsed_req_in >= reservation.check_in && parsed_req_out >= reservation.check_out end # if conditional end diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 2912ae9c8..c1f8140b6 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -51,34 +51,42 @@ end - xdescribe "more tests" do - - it "view rooms not reserved for a given date range" do - available_rooms = @admin.see_available("24/12/2018", "30/12/2018") - # available_rooms.must_equal (2..20).to_a - end - - it "returns an error if requested reservation overlaps in the back" do - @admin.make_reservation("30/12/2018", "02/01/2019") - # have one appt, try to make another - end - - it "returns an error if requested reservation overlaps in the front" do - @admin.make_reservation("20/12/2018", "24/12/2018") - # have one appt, try to make another - end - - it "returns an error if requested reservation is completely contained" do - @admin.make_reservation("26/12/2018", "27/12/2018") - # have one appt, try to make another + describe "creates reservation if dates are valid" do + before do + @admin = Hotel::Administrator.new() end - it "returns an error if requested reservation is completely containing an existing reservation" do - @admin.make_reservation("23/12/2018", "01/01/2019") - # have one appt, try to make another + it "view available rooms for a given date range" do + available_room = @admin.see_available("24/12/2018", "30/12/2018") + available_room.must_equal (1..20).to_a end - it "return all rooms if the array is empty" do + it "returns an error if no rooms are available" do + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + @admin.make_reservation("01/01/2018", "15/01/2018") + + proc { @admin.see_available}.must_raise ArgumentError end - end + end # describe + end # Admin From 58179fb394852bd2624b12fa9875b27d7b294284 Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Tue, 13 Mar 2018 20:40:44 -0700 Subject: [PATCH 15/16] Created new branch...still no blocked rooms available --- lib/admin.rb | 11 ++++++++--- lib/reservation.rb | 11 +++++------ specs/admin_spec.rb | 5 +++-- specs/reservation_spec.rb | 6 +++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index c6e020ca2..7cb1af7a1 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -1,3 +1,5 @@ +## would have to put number of rooms to be instantiated in the reservation parameters and adjust from there? + require "pry" require "date" @@ -13,10 +15,13 @@ def initialize() @rooms[room_num] = [] end # binding.pry + end def make_reservation(requested_check_in, requested_check_out) + # def make_reservation(requested_check_in, requested_check_out, number_of_rooms = 1) + available_rooms = see_available(requested_check_in, requested_check_out) #calls available rooms based on given dates if available_rooms.length == 0 @@ -24,11 +29,11 @@ def make_reservation(requested_check_in, requested_check_out) end #Many cases (block rooms) - # (1..requested_rooms).each do | res_num | do - # @rooms[available_rooms[res_num]] << Reservation.new .... + (1..requested_rooms).each do | res_num | do + @rooms[available_rooms[res_num]] << Reservation.new .... #Single case below - @rooms[available_rooms[0]] << Reservation.new(requested_check_in, requested_check_out) #first available room is chosen and pushed to @rooms array for that room + @rooms[available_rooms[0]] << Reservation.new({check_in: requested_check_in, check_out: requested_check_out}) #first available room is chosen and pushed to @rooms array for that room end diff --git a/lib/reservation.rb b/lib/reservation.rb index a6eae6957..5d8a00d1b 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,3 +1,4 @@ + require "pry" module Hotel @@ -5,15 +6,13 @@ module Hotel class Reservation COST = 200 - attr_reader :check_in, :check_out, :parse_date #, :room_num + attr_reader :check_in, :check_out #, :room_num - def initialize(check_in, check_out) - @check_in = Reservation.parse_date(check_in) - @check_out = Reservation.parse_date(check_out) - # @room_num = room_num + def initialize(input) + @check_in = Reservation.parse_date(input[:check_in]) + @check_out = Reservation.parse_date(input[:check_out]) end - def self.parse_date(date) # self necessary for calling class return DateTime.strptime(date, "%d/%m/%Y") end diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index c1f8140b6..3b493de20 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -57,11 +57,12 @@ end it "view available rooms for a given date range" do - available_room = @admin.see_available("24/12/2018", "30/12/2018") + available_room = @admin.see_available("24/12/2018", "25/12/2018") available_room.must_equal (1..20).to_a end it "returns an error if no rooms are available" do + @admin.make_reservation("01/01/2018", "15/01/2018") @admin.make_reservation("01/01/2018", "15/01/2018") @admin.make_reservation("01/01/2018", "15/01/2018") @@ -88,5 +89,5 @@ proc { @admin.see_available}.must_raise ArgumentError end end # describe - + end # Admin diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 29d6cc172..92b62a9c5 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -8,7 +8,7 @@ describe "Reservation" do before do - @reserve1 = Hotel::Reservation.new("30/10/2019","30/10/2018") + @reserve1 = Hotel::Reservation.new({check_in: "30/10/2019", check_out: "30/10/2018"}) end it "creates an instance of a reservation" do @@ -27,7 +27,7 @@ describe "checks the lenth of stay" do it "checks the duration of the reservation" do - reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018") + reserve1 = Hotel::Reservation.new({check_in: "24/12/2018", check_out: "26/12/2018"}) reserve1.get_stay_length.must_equal(2) end @@ -36,7 +36,7 @@ describe "returns the cost of the reservation" do it "gets the total cost of a stay " do - reserve1 = Hotel::Reservation.new("24/12/2018", "26/12/2018") + reserve1 = Hotel::Reservation.new({check_in: "24/12/2018", check_out: "26/12/2018"}) reserve1.total_cost.must_equal(200) end From 40d9ecf3b6e12432e6fda5af9c2ccc1f2c3c9e0c Mon Sep 17 00:00:00 2001 From: emilcecarlisa Date: Wed, 28 Mar 2018 18:47:23 -0700 Subject: [PATCH 16/16] Added block sub-class --- lib/admin.rb | 76 +++++++++++++++++++++++++++------------ lib/reservation.rb | 3 -- lib/reservation_block.rb | 19 ++++++++++ specs/admin_spec.rb | 18 ++++++++++ specs/reservation_spec.rb | 3 +- specs/spec_helper.rb | 1 + 6 files changed, 93 insertions(+), 27 deletions(-) create mode 100644 lib/reservation_block.rb diff --git a/lib/admin.rb b/lib/admin.rb index 7cb1af7a1..ec5237c85 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -10,6 +10,7 @@ class Administrator def initialize() @rooms = {} + @blocks = [] (1..20).each do |room_num| @rooms[room_num] = [] @@ -28,39 +29,70 @@ def make_reservation(requested_check_in, requested_check_out) raise ArgumentError.new('No rooms available') end - #Many cases (block rooms) - (1..requested_rooms).each do | res_num | do - @rooms[available_rooms[res_num]] << Reservation.new .... + # #Many cases (block rooms) + # (1..requested_rooms).each do | res_num | do + # @rooms[available_rooms[res_num]] << Reservation.new .... #Single case below - @rooms[available_rooms[0]] << Reservation.new({check_in: requested_check_in, check_out: requested_check_out}) #first available room is chosen and pushed to @rooms array for that room + room = Hotel::Reservation.new({check_in: requested_check_in, check_out: requested_check_out}) #first available room is chosen and pushed to @rooms array for that room + @rooms[available_rooms[0]] << room + + return room end + def block_room(requested_check_in, requested_check_out, room_amt) + available_rooms = see_available(requested_check_in, requested_check_out) + + if available_rooms.length < room_amt + raise ArgumentError.new('No rooms available') + end + + blocked_rooms = available_rooms[0, room_amt] + + block = Hotel::ReservationBlock.new({ + check_in: requested_check_in, + check_out: requested_check_out, + blocked_rooms: blocked_rooms + }) + + @blocks << block + + return block + end + - def see_available(requested_check_in, requested_check_out) - parsed_req_in = DateTime.strptime(requested_check_in, "%d/%m/%Y") - parsed_req_out = DateTime.strptime(requested_check_out, "%d/%m/%Y") + def see_available(requested_check_in, requested_check_out) + parsed_req_in = DateTime.strptime(requested_check_in, "%d/%m/%Y") + parsed_req_out = DateTime.strptime(requested_check_out, "%d/%m/%Y") - available_rooms = [] + available_rooms = [] - @rooms.each do |room_num, reservations| - reservations.each do |reservation| + @rooms.each do |room_num, reservations| + reservations.each do |reservation| - if parsed_req_in >= reservation.check_in && parsed_req_out <= reservation.check_out - next + if parsed_req_in >= reservation.check_in && parsed_req_out <= reservation.check_out + next - elsif parsed_req_in < reservation.check_in && parsed_req_out <= reservation.check_out - next + elsif parsed_req_in < reservation.check_in && parsed_req_out <= reservation.check_out + next - elsif parsed_req_in >= reservation.check_in && parsed_req_out >= reservation.check_out - end # if conditional + elsif parsed_req_in >= reservation.check_in && parsed_req_out >= reservation.check_out + end # if conditional + end + available_rooms << room_num end - available_rooms << room_num - end - return available_rooms - end # see_available - end # class -end # module + @block_room.each do | + + + return available_rooms + end # see_available + + end # class + end # module + + + # mayo = Hotel::Administrator.new() + # mayo.make_reservation("05/05/2018", "05/10/2018") diff --git a/lib/reservation.rb b/lib/reservation.rb index 5d8a00d1b..7b861dd87 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -31,8 +31,5 @@ def get_stay_length def total_cost return (COST * (get_stay_length - 1)) end - - end # class - end # module diff --git a/lib/reservation_block.rb b/lib/reservation_block.rb new file mode 100644 index 000000000..bc974f6b9 --- /dev/null +++ b/lib/reservation_block.rb @@ -0,0 +1,19 @@ + +module Hotel + + class ReservationBlock < Reservation + + attr_reader :blocked_rooms + + DISCOUNT_RATE = 0.2 + + def initialize(input) + super(input) + @blocked_rooms = input[:blocked_rooms] + end + + def total_cost + return super * (1 - DISCOUNT_RATE) + end + end +end diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 3b493de20..f9502f645 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -90,4 +90,22 @@ end end # describe + describe "block_room" do + before do + @admin = Hotel::Administrator.new + @admin.block_room("05/05/2018", "05/10/2018", 20) + end + + it "raise error if rooms are blocked within date range" do + proc { + @admin.make_reservation("05/05/2018", "05/10/2018") + }.must_raise ArgumentError + end + + it "won't throw error if the range is available" do + r = @admin.make_reservation("20/05/2018", "29/05/2018") + r.must_be_kind_of Hotel::Reservation + end + end + end # Admin diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 92b62a9c5..d1c08a4be 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -40,6 +40,5 @@ reserve1.total_cost.must_equal(200) end - - + end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index d66e3cc56..003c76b0f 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -5,6 +5,7 @@ require 'minitest/reporters' require_relative '../lib/admin' require_relative '../lib/reservation' +require_relative '../lib/reservation_block' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new