From fefe4062975075ae41a3f86c7ccc99f5e1639a84 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Tue, 5 Sep 2017 13:57:28 -0700 Subject: [PATCH 01/28] set up initial code files, spec files and rakefile --- Rakefile | 9 +++++++++ lib/hotel.rb | 0 lib/reservations.rb | 0 lib/rooms.rb | 0 specs/hotel_spec.rb | 0 specs/reservations_spec.rb | 0 specs/rooms_spec.rb | 0 specs/spec_helper.rb | 13 +++++++++++++ 8 files changed, 22 insertions(+) create mode 100644 Rakefile create mode 100644 lib/hotel.rb create mode 100644 lib/reservations.rb create mode 100644 lib/rooms.rb create mode 100644 specs/hotel_spec.rb create mode 100644 specs/reservations_spec.rb create mode 100644 specs/rooms_spec.rb create mode 100644 specs/spec_helper.rb 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/hotel.rb b/lib/hotel.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/reservations.rb b/lib/reservations.rb new file mode 100644 index 000000000..e69de29bb diff --git a/lib/rooms.rb b/lib/rooms.rb new file mode 100644 index 000000000..e69de29bb diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/specs/rooms_spec.rb b/specs/rooms_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb new file mode 100644 index 000000000..946059142 --- /dev/null +++ b/specs/spec_helper.rb @@ -0,0 +1,13 @@ +require 'simplecov' +SimpleCov.start + +require 'minitest' +require 'minitest/autorun' +require 'minitest/reporters' +require 'minitest/pride' + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new + +require_relative '../lib/hotel.rb' +require_relative '../lib/reservations.rb' +require_relative '../lib/rooms.rb' From d843cbf65bcc3fd481237c812de9f7dcfdd06df1 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Tue, 5 Sep 2017 14:41:21 -0700 Subject: [PATCH 02/28] initialize room specs and code complete --- lib/rooms.rb | 24 ++++++++++++++++++++++++ specs/rooms_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/rooms.rb b/lib/rooms.rb index e69de29bb..4b679e767 100644 --- a/lib/rooms.rb +++ b/lib/rooms.rb @@ -0,0 +1,24 @@ +module Hotel + class Room + # attr_reader :room_number + + def initialize(room_number) + @room_number = check_room_number(room_number) + end + + + + + private + + # Raises ArgumentError if room number supplied is already taken by a room or if number supplied is not an Integer. Otherwise, sets the room number. + def check_room_number(room_number) + if room_number.is_a?(Integer) == false + raise ArgumentError.new "room number must be an integer" + else + @room_number = room_number + end + end + + end # end of Rooms class +end # end of Hotel module diff --git a/specs/rooms_spec.rb b/specs/rooms_spec.rb index e69de29bb..37675da71 100644 --- a/specs/rooms_spec.rb +++ b/specs/rooms_spec.rb @@ -0,0 +1,20 @@ +require_relative 'spec_helper' + +describe Hotel::Room do + describe "You can create a Room instance" do + it "Can be created" do + room = Hotel::Room.new(1) + room.must_be_instance_of Hotel::Room + end + it "raises an ArgumentError for invalid parameters" do + proc{Hotel::Room.new("A15")}.must_raise ArgumentError + end + it "raies an ArgumentError if the room number already exists" do + + end + end + + describe "atribute_readers" do + it "" + end +end From bc40fe8f06b7b736f329a6bee146d5ea2c09102c Mon Sep 17 00:00:00 2001 From: Shaunna Date: Wed, 6 Sep 2017 11:10:37 -0700 Subject: [PATCH 03/28] initialize reservation code and specs complete --- lib/reservations.rb | 43 ++++++++++++++++++++++++++++++++++++++ lib/rooms.rb | 12 +++++------ specs/reservations_spec.rb | 40 +++++++++++++++++++++++++++++++++++ specs/rooms_spec.rb | 5 ++++- specs/spec_helper.rb | 1 + 5 files changed, 94 insertions(+), 7 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index e69de29bb..3fff7978c 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -0,0 +1,43 @@ +module Hotel + class Reservation + + def initialize(guest, check_in, check_out) + @guest = guest + @check_in = check_in_date(check_in) + @check_out = check_out_date(check_out) + @total_nights = calculate_res_length + + end + + + + private + + def check_in_date(check_in) + if check_in.is_a? (Date) + @check_in = check_in + else + raise ArgumentError.new "check_in must be a Date" + end + end + + def check_out_date(check_out) + if check_out.is_a? (Date) + @check_out = check_out + else + raise ArgumentError.new "check_out must be a date" + end + end + + def calculate_res_length + + if @check_in >= @check_out || @check_in < Date.today + raise ArgumentError.new "invalid dates" + else + length = @check_out - @check_in + return length + end + end + + end #end of Reservation class +end #end of Hotel module diff --git a/lib/rooms.rb b/lib/rooms.rb index 4b679e767..7a8813a9c 100644 --- a/lib/rooms.rb +++ b/lib/rooms.rb @@ -1,9 +1,9 @@ module Hotel class Room - # attr_reader :room_number + attr_reader :number - def initialize(room_number) - @room_number = check_room_number(room_number) + def initialize(number) + @number = check_room_number(number) end @@ -12,11 +12,11 @@ def initialize(room_number) private # Raises ArgumentError if room number supplied is already taken by a room or if number supplied is not an Integer. Otherwise, sets the room number. - def check_room_number(room_number) - if room_number.is_a?(Integer) == false + def check_room_number(number) + if number.is_a?(Integer) == false raise ArgumentError.new "room number must be an integer" else - @room_number = room_number + @number = number end end diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index e69de29bb..d1735cea1 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -0,0 +1,40 @@ +require_relative 'spec_helper' + +describe Hotel::Reservation do + before do + @guest = "Ada Lovelace" + end + + describe "you can create a reservation instance" do + it "can be created" do + check_in = Date.new(2017, 11, 14) + check_out = Date.new(2017, 11, 17) + reservation = Hotel::Reservation.new(@guest, check_in, check_out) + reservation.must_be_instance_of Hotel::Reservation + end + + it "raises an ArgumentError for invalid check_in and check_out arguments" do + check_in = [2017, 11, 14] + check_out = [2017, 11, 16] + proc{Hotel::Reservation.new(@guest, check_in, check_out)}.must_raise ArgumentError + end + + it "raises an ArgumentError if the check_out date is before or on the same day as the check_in date" do + check_in = Date.new(2017, 11, 15) + check_out = Date.new(2017, 11, 15) + proc {Hotel::Reservation.new(@guest, check_in, check_out)}.must_raise ArgumentError + + check_in = Date.new(2017, 11, 15) + check_out = Date.new(2017, 11, 14) + proc {Hotel::Reservation.new(@guest, check_in, check_out)}.must_raise ArgumentError + end + + it "raises an ArgumentError if the check_in date is before today when initializing" do + check_in = Date.new(2017, 8, 30) + check_out = Date.new(2017, 11, 15) + proc {Hotel::Reservation.new(@guest, check_in, check_out)}.must_raise ArgumentError + end + end + + +end diff --git a/specs/rooms_spec.rb b/specs/rooms_spec.rb index 37675da71..37147b8f1 100644 --- a/specs/rooms_spec.rb +++ b/specs/rooms_spec.rb @@ -15,6 +15,9 @@ end describe "atribute_readers" do - it "" + it "can retrieve the room number using .number" do + room = Hotel::Room.new(5) + room.number.must_equal 5 + end end end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 946059142..23dfe598e 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -5,6 +5,7 @@ require 'minitest/autorun' require 'minitest/reporters' require 'minitest/pride' +require 'minitest/skip_dsl' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 25c53b009ba755a84a635eb27a60c030242dcdb7 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Wed, 6 Sep 2017 11:30:17 -0700 Subject: [PATCH 04/28] reader method code and specs for reservation added --- lib/reservations.rb | 4 ++-- specs/reservations_spec.rb | 47 +++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 3fff7978c..4e739696f 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,12 +1,13 @@ module Hotel class Reservation + attr_reader :total_nights, :check_in, :check_out + def initialize(guest, check_in, check_out) @guest = guest @check_in = check_in_date(check_in) @check_out = check_out_date(check_out) @total_nights = calculate_res_length - end @@ -30,7 +31,6 @@ def check_out_date(check_out) end def calculate_res_length - if @check_in >= @check_out || @check_in < Date.today raise ArgumentError.new "invalid dates" else diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index d1735cea1..525ed2e66 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -19,22 +19,47 @@ proc{Hotel::Reservation.new(@guest, check_in, check_out)}.must_raise ArgumentError end - it "raises an ArgumentError if the check_out date is before or on the same day as the check_in date" do - check_in = Date.new(2017, 11, 15) - check_out = Date.new(2017, 11, 15) - proc {Hotel::Reservation.new(@guest, check_in, check_out)}.must_raise ArgumentError + it "accurately calculates the length of a stay of 1 night" do + check_in = Date.new(2017, 11, 14) + check_out = Date.new(2017, 11, 17) + reservation = Hotel::Reservation.new(@guest, check_in, check_out) + reservation.total_nights.must_equal 3 + end + + it "accurately calculates the length of a stay of 1 year" do + check_in = Date.new(2017, 11, 14) + check_out = Date.new(2018, 11, 14) + reservation = Hotel::Reservation.new(@guest, check_in, check_out) + reservation.total_nights.must_equal 365 + end + end - check_in = Date.new(2017, 11, 15) - check_out = Date.new(2017, 11, 14) - proc {Hotel::Reservation.new(@guest, check_in, check_out)}.must_raise ArgumentError + describe "Reader Methods" do + before do + check_in = Date.new(2018, 4, 1) + check_out = Date.new(2018, 4, 22) + @reservation = Hotel::Reservation.new(@guest, check_in, check_out) end - it "raises an ArgumentError if the check_in date is before today when initializing" do - check_in = Date.new(2017, 8, 30) - check_out = Date.new(2017, 11, 15) - proc {Hotel::Reservation.new(@guest, check_in, check_out)}.must_raise ArgumentError + it "can retrieve the total_nights" do + @reservation.total_nights.must_equal 21 end + + it "can retrieve the check_in date" do + @reservation.check_in.must_equal Date.new(2018, 4, 1) + end + + it "can retrieve the check_out date" do + @reservation.check_out.must_equal Date.new(2018, 4, 22) + end + + # it "can retrieve the room" do + # + # end end + + + end From 478e62b8e25b7457bb31640f3da85ad032f94992 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Wed, 6 Sep 2017 13:04:16 -0700 Subject: [PATCH 05/28] initialize hotel and specs finished' --- lib/hotel.rb | 25 +++++++++++++++++++++++++ lib/reservations.rb | 2 -- specs/hotel_spec.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index e69de29bb..a46f0a513 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -0,0 +1,25 @@ +require_relative 'reservations' +require_relative 'rooms' + + +module Hotel + class Hotel + + attr_reader :rooms, :reservations + + def initialize + @rooms = [] + @reservations = [] + create_rooms + end + + + + def create_rooms + (1..20).each do |num| + @rooms << Room.new(num) + end + end + + end #end of class +end #end of module diff --git a/lib/reservations.rb b/lib/reservations.rb index 4e739696f..8283e0f0c 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -10,8 +10,6 @@ def initialize(guest, check_in, check_out) @total_nights = calculate_res_length end - - private def check_in_date(check_in) diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index e69de29bb..70c21f4c9 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -0,0 +1,30 @@ +require_relative 'spec_helper' + +describe Hotel::Hotel do + describe "a hotel instance can be created" do + it "can be created" do + marriott = Hotel::Hotel.new + marriott.must_be_instance_of Hotel::Hotel + end + + it "creates 20 rooms upon initializing" do + marriott = Hotel::Hotel.new + marriott.rooms.length.must_equal 20 + end + + it "creates 20 rooms that are room objects" do + marriott = Hotel::Hotel.new + marriott.rooms.each do |room| + room.must_be_instance_of Hotel::Room + end + + end + + end + + + + + + +end From 853379b9ab346cd0c6fcda2d9c5eb3b3f17d8c45 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Wed, 6 Sep 2017 15:25:44 -0700 Subject: [PATCH 06/28] date_include? code and specs written --- lib/reservations.rb | 5 +++++ specs/reservations_spec.rb | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/reservations.rb b/lib/reservations.rb index 8283e0f0c..566e771cb 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -10,6 +10,11 @@ def initialize(guest, check_in, check_out) @total_nights = calculate_res_length end + # Reservations that are checking out on that date will return false since they are not staying that night at the hotel + def include_date?(date) + date.between?(@check_in, @check_out - 1) + end + private def check_in_date(check_in) diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index 525ed2e66..233e1be4f 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -56,7 +56,34 @@ # it "can retrieve the room" do # # end - end + end # end of reader Methods + + describe "method include_date?" do + before do + @reservation = Hotel::Reservation.new("guest", Date.new(2018, 2, 15), Date.new(2018, 2, 23)) + end + + it "returns true if the reservation includes that date" do + @reservation = Hotel::Reservation.new("guest", Date.new(2018, 2, 15), Date.new(2018, 2, 23)) + @reservation.include_date?(Date.new(2018, 2, 20)).must_equal true + end + + it "returns false if the reservation doesn't include that date" do + @reservation.include_date?(Date.new(2018, 2, 25)).must_equal false + @reservation.include_date?(Date.new(2018, 2, 2)).must_equal false + end + + it "returns true if the check_in date is that date" do + @reservation.include_date?(Date.new(2018, 2, 15)).must_equal true + end + + it "returns false if the check_out date is that date" do + @reservation.include_date?(Date.new(2018, 2, 23)).must_equal false + end + + end #end of method include_date? + + From 1a8635b4932b868fc8be8510fe574a15873c499f Mon Sep 17 00:00:00 2001 From: Shaunna Date: Wed, 6 Sep 2017 15:33:46 -0700 Subject: [PATCH 07/28] hotel/spec get_res_by_date code and specs added --- lib/hotel.rb | 17 ++++++++++ specs/hotel_spec.rb | 79 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index a46f0a513..0d1408270 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -13,7 +13,24 @@ def initialize create_rooms end + def make_reservation(guest, check_in, check_out) + reservations << Reservation.new(guest, check_in, check_out) + end + + def get_res_by_date(date) + res_by_date = [] + i = 0 + @reservations.each do |res| + if res.include_date?(date) + res_by_date << res + puts i + end + i += 1 + end + return res_by_date + end + private def create_rooms (1..20).each do |num| diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 70c21f4c9..978d970da 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -7,9 +7,10 @@ marriott.must_be_instance_of Hotel::Hotel end - it "creates 20 rooms upon initializing" do + it "creates 20 rooms upon initializing stored in an Array" do marriott = Hotel::Hotel.new marriott.rooms.length.must_equal 20 + marriott.rooms.must_be_kind_of Array end it "creates 20 rooms that are room objects" do @@ -17,13 +18,87 @@ marriott.rooms.each do |room| room.must_be_instance_of Hotel::Room end + end + + it "creates 20 hotels that can identify their room numbers" do + marriott = Hotel::Hotel.new + i = 1 + marriott.rooms.each do |room| + room.number.must_equal i + i += 1 + end end + end #end of initailize Hotel::Hotel tests + - end + describe "can make and retrieve reservations" do + before do + @hilton = Hotel::Hotel.new + + @hilton.make_reservation('Shaunna', Date.new(2018, 5, 7), Date.new(2018, 5, 10)) + @hilton.make_reservation('Shaunna', Date.new(2018, 4, 26), Date.new(2018, 4, 28)) + @hilton.make_reservation('Nathan', Date.new(2019, 12, 4), Date.new(2019, 12, 24)) + end + + it "can make a reservation from inside the hotel class" do + @hilton.reservations.each do |res| + res.must_be_instance_of Hotel::Reservation + end + end + + it "can retrieve an Array of all the reservations made" do + @hilton.reservations.length.must_equal 3 + @hilton.reservations.must_be_kind_of Array + end + + it "returns an Array of length zero if no reservations have been made" do + davenport = Hotel::Hotel.new + davenport.reservations.length.must_equal 0 + davenport.reservations.must_be_kind_of Array + end + end # end of make and retrieve reservations + describe "get_res_by_date" do + before do + check_in_day = [2, 2, 6, 4, 8, 6, 12, 23, 17, 2, 3, 5, 22, 29, 10, 10, 1] + check_out_day =[3, 10, 7, 8, 11, 7, 14, 30, 19, 4, 4, 6, 25, 30, 12, 20, 15] + + i = 0 + @carlisle = Hotel::Hotel.new + check_in_day.length.times do + @carlisle.make_reservation("guest", Date.new(2018, 4, check_in_day[i]), Date.new(2018, 4, check_out_day[i])) + i += 1 + end + end + + it "returns an Array of Reservations" do + @carlisle.get_res_by_date(Date.new(2018,4,10)).must_be_kind_of Array + @carlisle.get_res_by_date(Date.new(2018,4,8)).each do |res| + res.must_be_kind_of Hotel::Reservation + end + end + + #[] ##########COME BACK TO THIS!! ############## + it "returns a list of unique Reservations that are occupying rooms that night" do + reservations_4th = @carlisle.get_res_by_date(Date.new(2018,4,4)) + reservations_10th = @carlisle.get_res_by_date(Date.new(2018,4,10)) + reservations_30th = @carlisle.get_res_by_date(Date.new(2018,4,30)) + reservations_may = @carlisle.get_res_by_date(Date.new(2018,5,10)) + + reservations_4th.length.must_equal 3 + reservations_10th.length.must_equal 4 + reservations_may.length.must_equal 0 + reservations_30th.length.must_equal 0 + + + + + + end + end # end get_res_by_date From 9bfad5aaf9a7d9cf6efc8da6402aa3b2e58cbafb Mon Sep 17 00:00:00 2001 From: Shaunna Date: Wed, 6 Sep 2017 16:06:40 -0700 Subject: [PATCH 08/28] created pricing class and spec --- lib/hotel.rb | 4 ++++ lib/pricing.rb | 11 +++++++++++ lib/reservations.rb | 2 +- specs/hotel_spec.rb | 1 - specs/pricing_spec.rb | 31 +++++++++++++++++++++++++++++++ specs/reservations_spec.rb | 6 ++++++ specs/spec_helper.rb | 1 + 7 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 lib/pricing.rb create mode 100644 specs/pricing_spec.rb diff --git a/lib/hotel.rb b/lib/hotel.rb index 0d1408270..5711bd8cc 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -30,6 +30,10 @@ def get_res_by_date(date) return res_by_date end + def calc_cost(reservation) + + end + private def create_rooms diff --git a/lib/pricing.rb b/lib/pricing.rb new file mode 100644 index 000000000..b9ab8d4d7 --- /dev/null +++ b/lib/pricing.rb @@ -0,0 +1,11 @@ +module Hotel + class Pricing + + def self.calc_cost(reservation) + total_nights = reservation.total_nights + cost = total_nights * 200.0 + return cost + end + + end +end diff --git a/lib/reservations.rb b/lib/reservations.rb index 566e771cb..d87cac97a 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -38,7 +38,7 @@ def calculate_res_length raise ArgumentError.new "invalid dates" else length = @check_out - @check_in - return length + return length.to_i end end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 978d970da..1688703f1 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -79,7 +79,6 @@ end end - #[] ##########COME BACK TO THIS!! ############## it "returns a list of unique Reservations that are occupying rooms that night" do reservations_4th = @carlisle.get_res_by_date(Date.new(2018,4,4)) reservations_10th = @carlisle.get_res_by_date(Date.new(2018,4,10)) diff --git a/specs/pricing_spec.rb b/specs/pricing_spec.rb new file mode 100644 index 000000000..265e66ee6 --- /dev/null +++ b/specs/pricing_spec.rb @@ -0,0 +1,31 @@ +require_relative 'spec_helper' + +describe Hotel::Pricing do + describe "method self.calc_cost(reservation)" do + it "returns a float value" do + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 13)) + Hotel::Pricing.calc_cost(reservation).must_be_kind_of Float + end + + it "calculates the cost of one night to be 200" do + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 13)) + + Hotel::Pricing.calc_cost(reservation).must_equal 200 + end + + it "accurately calculates the cost of multiple night reservations" do + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 14)) + + res2 = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 20) ) + + + Hotel::Pricing.calc_cost(reservation).must_equal 400 + + Hotel::Pricing.calc_cost(res2).must_equal 1600 + end + + + end + + +end diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index 233e1be4f..4b9479219 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -32,6 +32,12 @@ reservation = Hotel::Reservation.new(@guest, check_in, check_out) reservation.total_nights.must_equal 365 end + + it "accurately calculates the length of stay of 7 days" do + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 19)) + + reservation.total_nights.must_equal 7 + end end describe "Reader Methods" do diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 23dfe598e..6d10cc2ef 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -12,3 +12,4 @@ require_relative '../lib/hotel.rb' require_relative '../lib/reservations.rb' require_relative '../lib/rooms.rb' +require_relative '../lib/pricing.rb' From 688ea84b272b0958ea320718ae31afb49f987efc Mon Sep 17 00:00:00 2001 From: Shaunna Date: Wed, 6 Sep 2017 21:22:23 -0700 Subject: [PATCH 09/28] get_available_rooms in hotel class and ability for user to request room by room number --- lib/hotel.rb | 34 ++++++++++++++++++++------ lib/reservations.rb | 5 ++-- lib/rooms.rb | 3 --- specs/hotel_spec.rb | 50 +++++++++++++++++++++++++++++++++++--- specs/pricing_spec.rb | 8 +++--- specs/reservations_spec.rb | 22 +++++++++++------ 6 files changed, 94 insertions(+), 28 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 5711bd8cc..30325a426 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,5 +1,6 @@ require_relative 'reservations' require_relative 'rooms' +require 'awesome_print' module Hotel @@ -9,29 +10,46 @@ class Hotel def initialize @rooms = [] - @reservations = [] create_rooms + @reservations = [] end - def make_reservation(guest, check_in, check_out) - reservations << Reservation.new(guest, check_in, check_out) + def make_reservation(guest, check_in, check_out, room_requested = nil) + if room.is_a? (Integer) + @rooms.each do |room| + if room.number = room_number + room_requested = room + end + end + else + available_rooms = get_available_rooms(check_in, check_out) + room_requested = available_rooms[0] + end + reservations << Reservation.new(guest, check_in, check_out, room_requested) end def get_res_by_date(date) res_by_date = [] - i = 0 @reservations.each do |res| if res.include_date?(date) res_by_date << res - puts i end - i += 1 end return res_by_date end - def calc_cost(reservation) - + def get_available_rooms(date_begin, date_end) + available_rooms = @rooms.clone + + @reservations.each do |res| + overlap = (res.check_in..res.check_out).to_a & (date_begin..date_end).to_a + + if overlap[0] != nil + available_rooms.delete(res.room) + end + end + + return available_rooms end private diff --git a/lib/reservations.rb b/lib/reservations.rb index d87cac97a..bfc3adbd6 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,12 +1,13 @@ module Hotel class Reservation - attr_reader :total_nights, :check_in, :check_out + attr_reader :total_nights, :check_in, :check_out, :room - def initialize(guest, check_in, check_out) + def initialize(guest, check_in, check_out, room) @guest = guest @check_in = check_in_date(check_in) @check_out = check_out_date(check_out) + @room = room @total_nights = calculate_res_length end diff --git a/lib/rooms.rb b/lib/rooms.rb index 7a8813a9c..435b71331 100644 --- a/lib/rooms.rb +++ b/lib/rooms.rb @@ -6,9 +6,6 @@ def initialize(number) @number = check_room_number(number) end - - - private # Raises ArgumentError if room number supplied is already taken by a room or if number supplied is not an Integer. Otherwise, sets the room number. diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 1688703f1..13828d1a7 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -31,7 +31,6 @@ end end #end of initailize Hotel::Hotel tests - describe "can make and retrieve reservations" do before do @hilton = Hotel::Hotel.new @@ -57,6 +56,21 @@ davenport.reservations.length.must_equal 0 davenport.reservations.must_be_kind_of Array end + + it "can make a reservation with room object by inputing the room number" do + hotel = Hotel::Hotel.new + hotel.make_reservation("guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), 13 ) + end + + it "raises an ArgumentError when trying to make a reservation for a room that is already reserved" do + victoria = Hotel::Hotel.new + victoria.make_reservation(" + guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), ) + vi + + + + end end # end of make and retrieve reservations describe "get_res_by_date" do @@ -89,16 +103,46 @@ reservations_10th.length.must_equal 4 reservations_may.length.must_equal 0 reservations_30th.length.must_equal 0 + end + + end # end get_res_by_date + ########### HOW TO TEST THIS METHOD?? ######### + ## CURRENTLY TESTING FOR LENGTH ## + describe "get_available_rooms method" do + it "returns an Array of Rooms" do + hotel = Hotel::Hotel.new + check_in = Date.new(2018, 4, 12) + check_out = Date.new(2018, 4, 25) + hotel.get_available_rooms(check_in, check_out).must_be_kind_of Array end + it "returns 17 rooms when there are three room conflicts" do + hotel = Hotel::Hotel.new + hotel.make_reservation("guest", Date.new(2018, 9, 10), Date.new(2018, 9, 17)) + hotel.make_reservation("guest", Date.new(2018, 9, 15), Date.new(2018, 9, 23)) + hotel.make_reservation("guest", Date.new(2018, 9, 16), Date.new(2018, 9, 28)) + hotel.make_reservation("guest", Date.new(2018, 4, 16), Date.new(2018, 4, 18)) - end # end get_res_by_date - + hotel.get_available_rooms(Date.new(2018, 9, 14), Date.new(2018, 9, 20)).length.must_equal 17 + end + end end + + + + + + + + + + + +#This is a comment to stop the blinking diff --git a/specs/pricing_spec.rb b/specs/pricing_spec.rb index 265e66ee6..f5b854904 100644 --- a/specs/pricing_spec.rb +++ b/specs/pricing_spec.rb @@ -3,20 +3,20 @@ describe Hotel::Pricing do describe "method self.calc_cost(reservation)" do it "returns a float value" do - reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 13)) + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 13), Hotel::Room.new(2)) Hotel::Pricing.calc_cost(reservation).must_be_kind_of Float end it "calculates the cost of one night to be 200" do - reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 13)) + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 13), Hotel::Room.new(5)) Hotel::Pricing.calc_cost(reservation).must_equal 200 end it "accurately calculates the cost of multiple night reservations" do - reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 14)) + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 14), Hotel::Room.new(18)) - res2 = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 20) ) + res2 = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 20), Hotel::Room.new(8) ) Hotel::Pricing.calc_cost(reservation).must_equal 400 diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index 4b9479219..14599e8ab 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -9,32 +9,32 @@ it "can be created" do check_in = Date.new(2017, 11, 14) check_out = Date.new(2017, 11, 17) - reservation = Hotel::Reservation.new(@guest, check_in, check_out) + reservation = Hotel::Reservation.new(@guest, check_in, check_out, Hotel::Room.new(1)) reservation.must_be_instance_of Hotel::Reservation end it "raises an ArgumentError for invalid check_in and check_out arguments" do check_in = [2017, 11, 14] check_out = [2017, 11, 16] - proc{Hotel::Reservation.new(@guest, check_in, check_out)}.must_raise ArgumentError + proc{Hotel::Reservation.new(@guest, check_in, check_out, Hotel::Room.new(5))}.must_raise ArgumentError end it "accurately calculates the length of a stay of 1 night" do check_in = Date.new(2017, 11, 14) check_out = Date.new(2017, 11, 17) - reservation = Hotel::Reservation.new(@guest, check_in, check_out) + reservation = Hotel::Reservation.new(@guest, check_in, check_out, Hotel::Room.new(3)) reservation.total_nights.must_equal 3 end it "accurately calculates the length of a stay of 1 year" do check_in = Date.new(2017, 11, 14) check_out = Date.new(2018, 11, 14) - reservation = Hotel::Reservation.new(@guest, check_in, check_out) + reservation = Hotel::Reservation.new(@guest, check_in, check_out, Hotel::Room.new(9)) reservation.total_nights.must_equal 365 end it "accurately calculates the length of stay of 7 days" do - reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 19)) + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 19), Hotel::Room.new(12)) reservation.total_nights.must_equal 7 end @@ -44,7 +44,7 @@ before do check_in = Date.new(2018, 4, 1) check_out = Date.new(2018, 4, 22) - @reservation = Hotel::Reservation.new(@guest, check_in, check_out) + @reservation = Hotel::Reservation.new(@guest, check_in, check_out, Hotel::Room.new(17)) end it "can retrieve the total_nights" do @@ -59,6 +59,11 @@ @reservation.check_out.must_equal Date.new(2018, 4, 22) end + it "can retreive the room and room number" do + @reservation.room.must_be_kind_of Hotel::Room + @reservation.room.number.must_equal 17 + end + # it "can retrieve the room" do # # end @@ -66,11 +71,12 @@ describe "method include_date?" do before do - @reservation = Hotel::Reservation.new("guest", Date.new(2018, 2, 15), Date.new(2018, 2, 23)) + @reservation = Hotel::Reservation.new("guest", Date.new(2018, 2, 15), Date.new(2018, 2, 23), Hotel::Room.new(15)) end it "returns true if the reservation includes that date" do - @reservation = Hotel::Reservation.new("guest", Date.new(2018, 2, 15), Date.new(2018, 2, 23)) + @reservation = Hotel::Reservation.new("guest", Date.new(2018, 2, 15), Date.new(2018, 2, 23), Hotel::Room.new(9)) + @reservation.include_date?(Date.new(2018, 2, 20)).must_equal true end From ba7788f6596534fdc153ab7552ed803a8940e9d6 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Wed, 6 Sep 2017 22:03:23 -0700 Subject: [PATCH 10/28] make list of available room, still bugs on edge cases --- lib/hotel.rb | 27 ++++++++++++++++++--------- specs/hotel_spec.rb | 15 +++++++++++---- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 30325a426..849628a6b 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -15,19 +15,28 @@ def initialize end def make_reservation(guest, check_in, check_out, room_requested = nil) - if room.is_a? (Integer) - @rooms.each do |room| - if room.number = room_number - room_requested = room + room = assign_room(check_in, check_out, room_requested) + reservations << Reservation.new(guest, check_in, check_out, room) + end + + def assign_room(check_in, check_out, room_requested) + available_rooms = get_available_rooms(check_in, check_out) + + if room_requested.is_a? (Integer) + available_rooms.each do |free_room| + if free_room.number == room_requested + return free_room end end - else - available_rooms = get_available_rooms(check_in, check_out) - room_requested = available_rooms[0] + raise StandardError.new "This room in unavailable" + else + room = available_rooms[0] + return room end - reservations << Reservation.new(guest, check_in, check_out, room_requested) + end + def get_res_by_date(date) res_by_date = [] @reservations.each do |res| @@ -42,7 +51,7 @@ def get_available_rooms(date_begin, date_end) available_rooms = @rooms.clone @reservations.each do |res| - overlap = (res.check_in..res.check_out).to_a & (date_begin..date_end).to_a + overlap = (res.check_in..res.check_out - 1).to_a & (date_begin..date_end).to_a if overlap[0] != nil available_rooms.delete(res.room) diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 13828d1a7..1a5b098a6 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -59,16 +59,23 @@ it "can make a reservation with room object by inputing the room number" do hotel = Hotel::Hotel.new - hotel.make_reservation("guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), 13 ) + hotel.make_reservation("guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), 13) end - it "raises an ArgumentError when trying to make a reservation for a room that is already reserved" do + it "raises a StnadardError when trying to make a reservation for a room that is already reserved" do victoria = Hotel::Hotel.new victoria.make_reservation(" - guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), ) - vi + guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), 11) + proc{victoria.make_reservation("guest", Date.new(2018, 6, 6), Date.new(2018, 6, 20), 11)}.must_raise StandardError + end + + it "will not raise an exception when trying to make a reservation for a room that starts on the same day another reservation ends" do + korpela = Hotel::Hotel.new + korpela.make_reservation(" + guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), 11) + korpela.make_reservation("guest", Date.new(2018, 6, 15), Date.new(2018, 6, 20), 11).must_be_instance_of Hotel::Reservation end end # end of make and retrieve reservations From 611a824e9ad590d2fd80e2402a2f6b5fdbfeeb96 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Thu, 7 Sep 2017 10:13:48 -0700 Subject: [PATCH 11/28] wave 2 requirements complete --- lib/hotel.rb | 3 +-- specs/hotel_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 849628a6b..f7c8c3cf1 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,6 +1,5 @@ require_relative 'reservations' require_relative 'rooms' -require 'awesome_print' module Hotel @@ -51,7 +50,7 @@ def get_available_rooms(date_begin, date_end) available_rooms = @rooms.clone @reservations.each do |res| - overlap = (res.check_in..res.check_out - 1).to_a & (date_begin..date_end).to_a + overlap = (res.check_in...res.check_out).to_a & (date_begin...date_end).to_a if overlap[0] != nil available_rooms.delete(res.room) diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 1a5b098a6..9228b2a42 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -1,4 +1,5 @@ require_relative 'spec_helper' +require 'pry' describe Hotel::Hotel do describe "a hotel instance can be created" do @@ -74,9 +75,10 @@ korpela = Hotel::Hotel.new korpela.make_reservation(" guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), 11) + + korpela.make_reservation("guest", Date.new(2018, 6, 15), Date.new(2018, 6, 20), 11) - korpela.make_reservation("guest", Date.new(2018, 6, 15), Date.new(2018, 6, 20), 11).must_be_instance_of Hotel::Reservation - + korpela.reservations.length.must_equal 2 end end # end of make and retrieve reservations From cbbed4c871685b0b28c570307580f35ff52372d4 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Thu, 7 Sep 2017 15:21:05 -0700 Subject: [PATCH 12/28] block file and spec initialize created --- lib/block.rb | 24 ++++++++++++++++++++++++ lib/hotel.rb | 1 - specs/block_spec.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ specs/spec_helper.rb | 1 + 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 lib/block.rb create mode 100644 specs/block_spec.rb diff --git a/lib/block.rb b/lib/block.rb new file mode 100644 index 000000000..5926f2343 --- /dev/null +++ b/lib/block.rb @@ -0,0 +1,24 @@ +module Hotel + class Block + + attr_reader :rooms_in_block, :discount, :check_in, :check_out + + def initialize(check_in, check_out, rooms, name) + @name = name + @rooms_in_block = check_room_validity(rooms) + @discount = 0.1 + @check_in = check_in + @check_out = check_out + end + + private + + def check_room_validity(rooms) + raise ArgumentError.new "wrong number of rooms " if rooms.length.between?(1, 5) == false + rooms.each do |room| + raise ArgumentError.new "room must be a Room object" if room.is_a?(Room) == false + end + end + + end # end of block class +end # end of Hotel module diff --git a/lib/hotel.rb b/lib/hotel.rb index f7c8c3cf1..4543f261d 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -35,7 +35,6 @@ def assign_room(check_in, check_out, room_requested) end - def get_res_by_date(date) res_by_date = [] @reservations.each do |res| diff --git a/specs/block_spec.rb b/specs/block_spec.rb new file mode 100644 index 000000000..ca41a68de --- /dev/null +++ b/specs/block_spec.rb @@ -0,0 +1,43 @@ +require_relative 'spec_helper' + +describe Hotel::Block do + describe "a block instance can be created" do + it "initializes with a number of rooms and a name" do + Hotel::Block.new(Date.new(2018, 5, 12), Date.new(2018, 5, 18),[Hotel::Room.new(5)], "guest") + end + + it "raises an ArgumentError if less than 1 or more than 5 rooms are passed" do + rooms = [] + + (1..6).each do |num| + rooms << Hotel::Room.new(num) + end + + proc{Hotel::Block.new(Date.new(2018, 5, 12), Date.new(2018, 5, 18),[], "guest")}.must_raise ArgumentError + + proc{Hotel::Block.new(Date.new(2018, 5, 12), Date.new(2018, 5, 18), rooms, "guest")}.must_raise ArgumentError + end + + it "raises an ArgumentError if the variable rooms that is passed in is not an Array of Rooms" do + rooms = [] + + (1..4).each do |num| + rooms << Hotel::Room.new(num) + end + + block = Hotel::Block.new(Date.new(2018, 5, 12), Date.new(2018, 5, 18),rooms, "guest") + + block.rooms_in_block.must_be_kind_of Array + block.rooms_in_block.each do |room| + room.must_be_instance_of Hotel::Room + end + + end + + end + + + + + +end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 6d10cc2ef..fd0600b0b 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -13,3 +13,4 @@ require_relative '../lib/reservations.rb' require_relative '../lib/rooms.rb' require_relative '../lib/pricing.rb' +require_relative '../lib/block.rb' From 52bba64b8b65033b6519922734479548ddae3ecb Mon Sep 17 00:00:00 2001 From: Shaunna Date: Thu, 7 Sep 2017 22:00:38 -0700 Subject: [PATCH 13/28] make a block added to hotel file and spec --- lib/hotel.rb | 24 ++++++++++++++++-- specs/hotel_spec.rb | 59 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 4543f261d..579987cbc 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -5,12 +5,13 @@ module Hotel class Hotel - attr_reader :rooms, :reservations + attr_reader :rooms, :reservations, :blocks def initialize @rooms = [] create_rooms @reservations = [] + @blocks = [] end def make_reservation(guest, check_in, check_out, room_requested = nil) @@ -18,7 +19,16 @@ def make_reservation(guest, check_in, check_out, room_requested = nil) reservations << Reservation.new(guest, check_in, check_out, room) end - def assign_room(check_in, check_out, room_requested) + def make_block(check_in, check_out, num_rooms, name) + rooms = [] + num_rooms.times do + rooms << assign_room(check_in, check_out) + end + block = Block.new(check_in, check_out, rooms, name) + blocks << block + end + + def assign_room(check_in, check_out, room_requested = nil) available_rooms = get_available_rooms(check_in, check_out) if room_requested.is_a? (Integer) @@ -56,6 +66,16 @@ def get_available_rooms(date_begin, date_end) end end + @blocks.each do |block| + overlap = (block.check_in...block.check_out).to_a & (date_begin...date_end).to_a + + if overlap[0] != nil + block.rooms_in_block.each do |room| + available_rooms.delete(room) + end + end + end + return available_rooms end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 9228b2a42..420c7eb19 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -75,13 +75,70 @@ korpela = Hotel::Hotel.new korpela.make_reservation(" guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), 11) - + korpela.make_reservation("guest", Date.new(2018, 6, 15), Date.new(2018, 6, 20), 11) korpela.reservations.length.must_equal 2 end end # end of make and retrieve reservations + describe "can make a block of rooms" do + it "can make a block that is passed into an Array" do + + motel8 = Hotel::Hotel.new + + motel8.make_block(Date.new(2018, 5, 5), Date.new(2018, 5, 8), 4, "Chris") + + motel8.blocks.must_be_kind_of Array + + motel8.blocks.last.must_be_instance_of Hotel::Block + end + + it "won't assign rooms to the block that aren't available during that date range" do + holidayinn = Hotel::Hotel.new + + check_in = Date.new(2018, 7, 6) + check_out = Date.new(2018, 7, 8) + + (1..15).each do |num| + holidayinn.make_reservation("guest", check_in, check_out, num) + end + + holidayinn.make_block(check_in, check_out, 5, "guest") + + holidayinn.blocks.each do |block| + block.rooms_in_block.each do |room| + room.number.between?(1, 15).must_equal false + end + end + end + + it "will make the rooms assigned to the block unavailable for reservation to the general public" do + + parador = Hotel::Hotel.new + + check_in = Date.new(2018, 7, 6) + check_out = Date.new(2018, 7, 8) + + parador.make_block(check_in, check_out, 4, "guest") + + room_numbers = [] + + parador.blocks.each do |block| + block.rooms_in_block.each do |room| + room_numbers << room.number + end + end + # + # binding.pry + + + proc{parador.make_reservation("guest", check_in, check_out, room_numbers[0])}.must_raise StandardError + + end + end + + describe "get_res_by_date" do before do check_in_day = [2, 2, 6, 4, 8, 6, 12, 23, 17, 2, 3, 5, 22, 29, 10, 10, 1] From 62265bfadf472d48a64232700ed307413c57c1be Mon Sep 17 00:00:00 2001 From: Shaunna Date: Thu, 7 Sep 2017 23:23:29 -0700 Subject: [PATCH 14/28] make_block method changed and block code changed to add rooms to the block one at a time --- lib/block.rb | 20 +++++++------------- lib/hotel.rb | 35 ++++++++++++++++++++++++++++++----- specs/block_spec.rb | 44 ++++++++++++++++++++++---------------------- specs/hotel_spec.rb | 28 ++++++++++++++++++++++------ 4 files changed, 81 insertions(+), 46 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 5926f2343..16eb8c7bd 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -1,24 +1,18 @@ module Hotel class Block - attr_reader :rooms_in_block, :discount, :check_in, :check_out + attr_reader :check_in, :check_out, :id, :rooms_in_block, :discount - def initialize(check_in, check_out, rooms, name) - @name = name - @rooms_in_block = check_room_validity(rooms) - @discount = 0.1 + def initialize(check_in, check_out, id) @check_in = check_in @check_out = check_out + @id = id + @discount = 0.1 + @rooms_in_block = [] end - private - - def check_room_validity(rooms) - raise ArgumentError.new "wrong number of rooms " if rooms.length.between?(1, 5) == false - rooms.each do |room| - raise ArgumentError.new "room must be a Room object" if room.is_a?(Room) == false - end + def add_room(room) + @rooms_in_block << room end - end # end of block class end # end of Hotel module diff --git a/lib/hotel.rb b/lib/hotel.rb index 579987cbc..44a298b52 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -19,13 +19,26 @@ def make_reservation(guest, check_in, check_out, room_requested = nil) reservations << Reservation.new(guest, check_in, check_out, room) end - def make_block(check_in, check_out, num_rooms, name) - rooms = [] + def make_block(check_in, check_out, num_rooms) + id = assign_id + + block = Block.new(check_in, check_out, id) + + blocks << block + + if num_rooms.between?(1, 5) == false + raise StandardError.new "only possible to book 5 rooms in a block" + end + num_rooms.times do - rooms << assign_room(check_in, check_out) + room = assign_room(check_in, check_out) + @blocks.each do |block_in_array| + if block.id == id + block.add_room(room) + end + end end - block = Block.new(check_in, check_out, rooms, name) - blocks << block + end def assign_room(check_in, check_out, room_requested = nil) @@ -81,6 +94,18 @@ def get_available_rooms(date_begin, date_end) private + + def assign_id + id = 111111 + + blocks.each do |block| + while block.id == id + id = rand(899999) + 100000 + end + end + return id + end + def create_rooms (1..20).each do |num| @rooms << Room.new(num) diff --git a/specs/block_spec.rb b/specs/block_spec.rb index ca41a68de..5be8ef1f8 100644 --- a/specs/block_spec.rb +++ b/specs/block_spec.rb @@ -1,43 +1,43 @@ require_relative 'spec_helper' +require 'pry' describe Hotel::Block do describe "a block instance can be created" do - it "initializes with a number of rooms and a name" do - Hotel::Block.new(Date.new(2018, 5, 12), Date.new(2018, 5, 18),[Hotel::Room.new(5)], "guest") + it "creates an instance of a block" do + Hotel::Block.new(Date.new(2018, 5, 12), Date.new(2018, 5, 18), 111123).must_be_instance_of Hotel::Block + end - it "raises an ArgumentError if less than 1 or more than 5 rooms are passed" do - rooms = [] + ########## NEEDS MORE TESTS ########### - (1..6).each do |num| - rooms << Hotel::Room.new(num) - end + it "initializes with an id number between 111111 and 999999" do - proc{Hotel::Block.new(Date.new(2018, 5, 12), Date.new(2018, 5, 18),[], "guest")}.must_raise ArgumentError - proc{Hotel::Block.new(Date.new(2018, 5, 12), Date.new(2018, 5, 18), rooms, "guest")}.must_raise ArgumentError end + end - it "raises an ArgumentError if the variable rooms that is passed in is not an Array of Rooms" do - rooms = [] + describe "attr_readers" do + before do + @check_in = Date.new(2018, 1, 12) + @check_out = Date.new(2018, 1, 14) + @block = Hotel::Block.new(@check_in, @check_out, 111123) - (1..4).each do |num| - rooms << Hotel::Room.new(num) - end + @block.add_room(Hotel::Room.new(5)) + @block.add_room(Hotel::Room.new(13)) + end - block = Hotel::Block.new(Date.new(2018, 5, 12), Date.new(2018, 5, 18),rooms, "guest") + it "can read the check_in date, check_out date, id, rooms_in_block, and the discount" do + @block.check_in.must_equal @check_in + @block.check_out.must_equal @check_out + @block.id.must_equal 111123 + @block.rooms_in_block.length.must_equal 2 - block.rooms_in_block.must_be_kind_of Array - block.rooms_in_block.each do |room| + @block.rooms_in_block.each do |room| room.must_be_instance_of Hotel::Room end - end - end - - - + end end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 420c7eb19..19163a178 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -87,13 +87,20 @@ motel8 = Hotel::Hotel.new - motel8.make_block(Date.new(2018, 5, 5), Date.new(2018, 5, 8), 4, "Chris") + motel8.make_block(Date.new(2018, 5, 5), Date.new(2018, 5, 8), 4) motel8.blocks.must_be_kind_of Array motel8.blocks.last.must_be_instance_of Hotel::Block end + it "will generate a unique id for the block booking" do + + ############ HOW??? ############ + + + end + it "won't assign rooms to the block that aren't available during that date range" do holidayinn = Hotel::Hotel.new @@ -104,7 +111,7 @@ holidayinn.make_reservation("guest", check_in, check_out, num) end - holidayinn.make_block(check_in, check_out, 5, "guest") + holidayinn.make_block(check_in, check_out, 5) holidayinn.blocks.each do |block| block.rooms_in_block.each do |room| @@ -113,6 +120,18 @@ end end + it "will only allow a block to reserve a maximum of five rooms" do + hotel = Hotel::Hotel.new + + check_in = Date.new(2018, 7, 6) + check_out = Date.new(2018, 7, 8) + + proc{hotel.make_block(check_in, check_out, 6)}.must_raise StandardError + + proc{hotel.make_block(check_in, check_out, 0)}.must_raise StandardError + + end + it "will make the rooms assigned to the block unavailable for reservation to the general public" do parador = Hotel::Hotel.new @@ -120,7 +139,7 @@ check_in = Date.new(2018, 7, 6) check_out = Date.new(2018, 7, 8) - parador.make_block(check_in, check_out, 4, "guest") + parador.make_block(check_in, check_out, 4) room_numbers = [] @@ -129,9 +148,6 @@ room_numbers << room.number end end - # - # binding.pry - proc{parador.make_reservation("guest", check_in, check_out, room_numbers[0])}.must_raise StandardError From ab8cb656547f127c92ab7b94176b8106ade5adde Mon Sep 17 00:00:00 2001 From: Shaunna Date: Fri, 8 Sep 2017 00:38:52 -0700 Subject: [PATCH 15/28] make reservation from a block update specs to account for requirements and constraints --- lib/hotel.rb | 27 +++++++++++++++++++++++++-- lib/reservations.rb | 3 ++- specs/hotel_spec.rb | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 44a298b52..408b36731 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -16,7 +16,31 @@ def initialize def make_reservation(guest, check_in, check_out, room_requested = nil) room = assign_room(check_in, check_out, room_requested) - reservations << Reservation.new(guest, check_in, check_out, room) + reservations << Reservation.new(guest, check_in, check_out, room, false) + end + + def make_reservation_from_block(guest, block_id) + available_rooms = nil + block_for_res = nil + + blocks.each do |block| + if block.id == block_id + available_rooms = block.rooms_in_block + block_for_res = block + end + end + + reservations.each do |res| + if res.block_id == block_id + available_rooms.each do |room| + available_rooms.delete(res.room) + end + end + end + + room = available_rooms.first + + reservations << Reservation.new(guest, block_for_res.check_in, block_for_res.check_out, room, block_id) end def make_block(check_in, check_out, num_rooms) @@ -38,7 +62,6 @@ def make_block(check_in, check_out, num_rooms) end end end - end def assign_room(check_in, check_out, room_requested = nil) diff --git a/lib/reservations.rb b/lib/reservations.rb index bfc3adbd6..63d910434 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -3,12 +3,13 @@ class Reservation attr_reader :total_nights, :check_in, :check_out, :room - def initialize(guest, check_in, check_out, room) + def initialize(guest, check_in, check_out, room, block_id = nil) @guest = guest @check_in = check_in_date(check_in) @check_out = check_out_date(check_out) @room = room @total_nights = calculate_res_length + @block_id = block_id end # Reservations that are checking out on that date will return false since they are not staying that night at the hotel diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 19163a178..fc50a5e22 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -82,6 +82,39 @@ end end # end of make and retrieve reservations + describe "make_reservation_from_block" do + before do + @hotel = Hotel::Hotel.new + @check_in = Date.new(2018, 9, 7) + @check_out = Date.new(2018, 9, 13) + @hotel.make_block(@check_in, @check_out, 5) + @id = @hotel.blocks[0].id + @hotel.make_reservation_from_block("guest", @id) + end + + it "can make a reservation from a block" do + @hotel.reservations.length.must_equal 1 + @hotel.reservations[0].must_be_instance_of Hotel::Reservation + end + + it "will make a reservation with a room that is reserved for the block" do + block_rooms = [] + @hotel.blocks[0].rooms_in_block.each do |room| + block_rooms << room + end + + block_rooms.include?(@hotel.reservations[0].room).must_equal true + end + + it "will make a reservation with the same date range as the block" do + @hotel.reservations[0].check_in.must_equal @check_in + + @hotel.reservations[0].check_out.must_equal @check_out + + end + end + + describe "can make a block of rooms" do it "can make a block that is passed into an Array" do @@ -129,7 +162,6 @@ proc{hotel.make_block(check_in, check_out, 6)}.must_raise StandardError proc{hotel.make_block(check_in, check_out, 0)}.must_raise StandardError - end it "will make the rooms assigned to the block unavailable for reservation to the general public" do From f82db1f92b06f75b8a4a32a647fc90f39935abb0 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Fri, 8 Sep 2017 11:11:18 -0700 Subject: [PATCH 16/28] all initial requirements met, now can make reservations from a block and get available rooms from a block --- lib/hotel.rb | 45 +++++++++++++++------------ lib/reservations.rb | 2 +- specs/hotel_spec.rb | 74 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 95 insertions(+), 26 deletions(-) diff --git a/lib/hotel.rb b/lib/hotel.rb index 408b36731..d394b4e7a 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -20,27 +20,11 @@ def make_reservation(guest, check_in, check_out, room_requested = nil) end def make_reservation_from_block(guest, block_id) - available_rooms = nil - block_for_res = nil + block = find_block_by_id(block_id) - blocks.each do |block| - if block.id == block_id - available_rooms = block.rooms_in_block - block_for_res = block - end - end + room = get_available_rooms_from_block(block)[0] - reservations.each do |res| - if res.block_id == block_id - available_rooms.each do |room| - available_rooms.delete(res.room) - end - end - end - - room = available_rooms.first - - reservations << Reservation.new(guest, block_for_res.check_in, block_for_res.check_out, room, block_id) + reservations << Reservation.new(guest, block.check_in, block.check_out, room, block_id) end def make_block(check_in, check_out, num_rooms) @@ -115,8 +99,29 @@ def get_available_rooms(date_begin, date_end) return available_rooms end + def get_available_rooms_from_block(block) + + available_rooms = block.rooms_in_block + + reservations.each do |res| + if res.block_id == block.id + available_rooms.delete(res.room) + end + end + + return available_rooms + end + private + def find_block_by_id(block_id) + blocks.each do |block| + if block.id == block_id + return block + end + end + raise StandardError.new "this id doesn't exit" + end def assign_id id = 111111 @@ -126,7 +131,7 @@ def assign_id id = rand(899999) + 100000 end end - return id + return id end def create_rooms diff --git a/lib/reservations.rb b/lib/reservations.rb index 63d910434..3593fe0ee 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,7 +1,7 @@ module Hotel class Reservation - attr_reader :total_nights, :check_in, :check_out, :room + attr_reader :total_nights, :check_in, :check_out, :room, :block_id def initialize(guest, check_in, check_out, room, block_id = nil) @guest = guest diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index fc50a5e22..7bc6fcba7 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -28,7 +28,12 @@ room.number.must_equal i i += 1 end + end + it "initializes an empty Array to store blocks of rooms" do + fairmont = Hotel::Hotel.new + fairmont.blocks.must_be_kind_of Array + fairmont.blocks.length.must_equal 0 end end #end of initailize Hotel::Hotel tests @@ -82,6 +87,70 @@ end end # end of make and retrieve reservations + describe "get_available_rooms_from_block" do + before do + @hotel = Hotel::Hotel.new + @check_in = Date.new(2018, 9, 7) + @check_out = Date.new(2018, 9, 13) + @hotel.make_block(@check_in, @check_out, 5) + @block = @hotel.blocks[0] + @id = @hotel.blocks[0].id + @hotel.make_reservation_from_block("guest", @id) + end + + it "returns an Array of Rooms" do + rooms_in_block = @hotel.get_available_rooms_from_block(@block) + + rooms_in_block.must_be_kind_of Array + + rooms_in_block.each do |room| + room.must_be_instance_of Hotel::Room + end + + end + + it "only returns available Rooms" do + rooms_avail_before = @hotel.get_available_rooms_from_block(@block).clone + + 2.times do + @hotel.make_reservation_from_block("guest", @id) + end + + rooms_avail_after = @hotel.get_available_rooms_from_block(@block) + + rooms_avail_after.length.must_equal (rooms_avail_before.length - 2) + + rooms_left_in_block = @block.rooms_in_block + @hotel.reservations.each do |res| + rooms_left_in_block.delete(res.room) + end + + rooms_avail_after.must_equal rooms_left_in_block + + end + + it "returns an empty Array if no rooms are left" do + hotel = Hotel::Hotel.new + + check_in = Date.new(2018, 9, 15) + check_out = Date.new(2018, 9, 16) + hotel.make_block(check_in, check_out, 3) + block = hotel.blocks[0] + + binding.pry + + 3.times do + hotel.make_reservation_from_block("guest", block.id) + end + + + + hotel.get_available_rooms_from_block(hotel.blocks[0]).length.must_equal 0 + + end + + end + describe "make_reservation_from_block" do before do @hotel = Hotel::Hotel.new @@ -110,11 +179,9 @@ @hotel.reservations[0].check_in.must_equal @check_in @hotel.reservations[0].check_out.must_equal @check_out - end end - describe "can make a block of rooms" do it "can make a block that is passed into an Array" do @@ -186,7 +253,6 @@ end end - describe "get_res_by_date" do before do check_in_day = [2, 2, 6, 4, 8, 6, 12, 23, 17, 2, 3, 5, 22, 29, 10, 10, 1] @@ -221,8 +287,6 @@ end # end get_res_by_date - - ########### HOW TO TEST THIS METHOD?? ######### ## CURRENTLY TESTING FOR LENGTH ## describe "get_available_rooms method" do From 1e4a7a6d84773b54e44a948c4b55fda8430f01d9 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Fri, 8 Sep 2017 12:40:25 -0700 Subject: [PATCH 17/28] adjusted pricing method, tests for unique block id --- lib/block.rb | 1 - lib/hotel.rb | 22 +++++++++++++++++----- lib/pricing.rb | 13 ++++++++++++- specs/block_spec.rb | 20 ++++++++++++++++---- specs/hotel_spec.rb | 17 ++++++++++++++--- specs/pricing_spec.rb | 6 ++++++ 6 files changed, 65 insertions(+), 14 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 16eb8c7bd..412d50f43 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -7,7 +7,6 @@ def initialize(check_in, check_out, id) @check_in = check_in @check_out = check_out @id = id - @discount = 0.1 @rooms_in_block = [] end diff --git a/lib/hotel.rb b/lib/hotel.rb index d394b4e7a..173fddd8e 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -48,21 +48,24 @@ def make_block(check_in, check_out, num_rooms) end end + + #THERE HAS TO BE A BETTER WAY TO DO THIS. def assign_room(check_in, check_out, room_requested = nil) available_rooms = get_available_rooms(check_in, check_out) + raise StandardError.new "no more rooms available for that date" if available_rooms.empty? + if room_requested.is_a? (Integer) - available_rooms.each do |free_room| - if free_room.number == room_requested - return free_room + available_rooms.each do |empty_room| + if empty_room.number == room_requested + return empty_room end end - raise StandardError.new "This room in unavailable" + raise StandardError.new "This room is unavailable" else room = available_rooms[0] return room end - end def get_res_by_date(date) @@ -123,6 +126,15 @@ def find_block_by_id(block_id) raise StandardError.new "this id doesn't exit" end + def find_room_by_number(room_number) + rooms.each do |room| + if room.number == room_number + return room + end + end + raise StandardError.new "this room doesn't exist" + end + def assign_id id = 111111 diff --git a/lib/pricing.rb b/lib/pricing.rb index b9ab8d4d7..9e6045b27 100644 --- a/lib/pricing.rb +++ b/lib/pricing.rb @@ -3,7 +3,18 @@ class Pricing def self.calc_cost(reservation) total_nights = reservation.total_nights - cost = total_nights * 200.0 + + if reservation.block_id != nil + discount = 0.1 + end + + cost = (total_nights * 200.0) + + if reservation.block_id != nil + discount = 0.1 + cost -= cost*0.1 + end + return cost end diff --git a/specs/block_spec.rb b/specs/block_spec.rb index 5be8ef1f8..f73bdb044 100644 --- a/specs/block_spec.rb +++ b/specs/block_spec.rb @@ -8,11 +8,25 @@ end - ########## NEEDS MORE TESTS ########### - it "initializes with an id number between 111111 and 999999" do + hotel = Hotel::Hotel.new + 100.times do + check_in = rand(Date.new(2018, 1, 1)..Date.new(2019, 1, 1)) + hotel.make_block(check_in, check_in + 5, rand(1..5) ) + end + + ids = [] + + hotel.blocks.each do |block| + ids << block.id + end + ids.each do |id| + id.between?(111111, 999999).must_equal true + end + ids.uniq! + ids.length.must_equal 100 end end @@ -36,8 +50,6 @@ room.must_be_instance_of Hotel::Room end end - - end end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 7bc6fcba7..fc9cf554d 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -68,7 +68,7 @@ hotel.make_reservation("guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), 13) end - it "raises a StnadardError when trying to make a reservation for a room that is already reserved" do + it "raises a StandardError when trying to make a reservation for a room that is already reserved" do victoria = Hotel::Hotel.new victoria.make_reservation(" guest", Date.new(2018, 6, 2), Date.new(2018, 6, 15), 11) @@ -76,6 +76,19 @@ proc{victoria.make_reservation("guest", Date.new(2018, 6, 6), Date.new(2018, 6, 20), 11)}.must_raise StandardError end + it "raises a StandardError when there are no available rooms left " do + sheraton = Hotel::Hotel.new + + check_in = Date.new(2018, 7, 12) + check_out = Date.new(2018, 7, 15) + + 20.times do + sheraton.make_reservation("guest", check_in, check_out) + end + + proc{sheraton.make_reservation("guest", check_in, check_out)}.must_raise StandardError + end + it "will not raise an exception when trying to make a reservation for a room that starts on the same day another reservation ends" do korpela = Hotel::Hotel.new korpela.make_reservation(" @@ -137,8 +150,6 @@ hotel.make_block(check_in, check_out, 3) block = hotel.blocks[0] - binding.pry - 3.times do hotel.make_reservation_from_block("guest", block.id) end diff --git a/specs/pricing_spec.rb b/specs/pricing_spec.rb index f5b854904..68d7c65fe 100644 --- a/specs/pricing_spec.rb +++ b/specs/pricing_spec.rb @@ -24,6 +24,12 @@ Hotel::Pricing.calc_cost(res2).must_equal 1600 end + it "returns a discounted value if room is reserved in a block" do + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 14), Hotel::Room.new(18), 123456) + + Hotel::Pricing.calc_cost(reservation).must_equal 360 + end + end From a14672958d53f26e328b0b7787cd27cf627a8376 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Fri, 8 Sep 2017 14:52:57 -0700 Subject: [PATCH 18/28] created CLI ruby file and spec --- lib/cli.rb | 28 ++++++++++++++++++++++++++++ specs/block_spec.rb | 7 ++++--- specs/cli_spec.rb | 21 +++++++++++++++++++++ specs/hotel_spec.rb | 3 +-- specs/spec_helper.rb | 1 + 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 lib/cli.rb create mode 100644 specs/cli_spec.rb diff --git a/lib/cli.rb b/lib/cli.rb new file mode 100644 index 000000000..c851c6564 --- /dev/null +++ b/lib/cli.rb @@ -0,0 +1,28 @@ +module Hotel + class Cli + + attr_reader :hotel + + def initialize + @hotel = Hotel.new + end + + def display_user_menu + puts "\nWhat would you like to do?\n + A. Book a room + B. Reserve a block of rooms + C. View reservations + D. View available rooms + E. View available rooms in a block + F. Change the price of a room + G. View all rooms in the hotel\n" + end + + def get_option + + end + + end +end # end of hotel module +# +# interface = Hotel::Cli.new diff --git a/specs/block_spec.rb b/specs/block_spec.rb index f73bdb044..b148781f4 100644 --- a/specs/block_spec.rb +++ b/specs/block_spec.rb @@ -8,11 +8,12 @@ end - it "initializes with an id number between 111111 and 999999" do + it "initializes with an id number between 100000 and 999999" do hotel = Hotel::Hotel.new + check_in = Date.new(2018, 1, 1) 100.times do - check_in = rand(Date.new(2018, 1, 1)..Date.new(2019, 1, 1)) hotel.make_block(check_in, check_in + 5, rand(1..5) ) + check_in += 3 end ids = [] @@ -22,7 +23,7 @@ end ids.each do |id| - id.between?(111111, 999999).must_equal true + id.between?(100000, 999999).must_equal true end ids.uniq! diff --git a/specs/cli_spec.rb b/specs/cli_spec.rb new file mode 100644 index 000000000..d62896178 --- /dev/null +++ b/specs/cli_spec.rb @@ -0,0 +1,21 @@ +require_relative 'spec_helper' + +describe "Command Line Interface" do + before do + @interface = Hotel::Cli.new + end + + it " can create an instance" do + @interface.must_be_instance_of Hotel::Cli + end + + it "initializes with a hotel" do + @interface.hotel.must_be_instance_of Hotel::Hotel + end + + it "displays_user_menu" do + @interface.must_respond_to :display_user_menu + end + + +end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index fc9cf554d..df878c8d9 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -1,5 +1,4 @@ require_relative 'spec_helper' -require 'pry' describe Hotel::Hotel do describe "a hotel instance can be created" do @@ -85,7 +84,7 @@ 20.times do sheraton.make_reservation("guest", check_in, check_out) end - + proc{sheraton.make_reservation("guest", check_in, check_out)}.must_raise StandardError end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index fd0600b0b..d276afdaa 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -14,3 +14,4 @@ require_relative '../lib/rooms.rb' require_relative '../lib/pricing.rb' require_relative '../lib/block.rb' +require_relative '../lib/cli.rb' From f6b098057f3c4f2afbdcadbe5650332ad557ce6a Mon Sep 17 00:00:00 2001 From: Shaunna Date: Sat, 9 Sep 2017 16:26:49 -0700 Subject: [PATCH 19/28] get_room method added to cli --- lib/cli.rb | 106 +++++++++++++++++++++++++++++++++++++++++--- lib/rooms.rb | 2 + specs/cli_spec.rb | 5 +++ specs/rooms_spec.rb | 15 +++++-- 4 files changed, 120 insertions(+), 8 deletions(-) diff --git a/lib/cli.rb b/lib/cli.rb index c851c6564..329dec92e 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -1,3 +1,6 @@ +require_relative 'hotel' +require 'terminal-table' + module Hotel class Cli @@ -7,22 +10,115 @@ def initialize @hotel = Hotel.new end + def begin + display_user_menu + choice = get_menu_option + + case choice + when "A" + reserve_room + when "B" + make_block_of_rooms + when "C" + view_reservations + when "D" + view_available_rooms + when "E" + view_available_rooms_in_block + when "F" + change_room_cost + when "G" + view_rooms + else + raise ArgumentError.new "not a valid choice" + end + end + + def reserve_room + end + + def make_block_of_rooms + end + + def view_reservations + end + + def view_available_rooms + end + + def view_available_rooms_in_block + + end + + #############!##!!###!!!! DOESN'T WORK!!!!!!!!!! + + def change_room_cost + room_number = get_room_number + ### + + cost = "cost" + until cost =~ (/\d/) + print "\n\tNew Cost: " + cost = gets.chomp + end + p cost + + new_cost = nil + hotel.rooms.each do |room| + if room.number == room_number + hotel.room.cost_per_night = cost + new_cost = room.cost_per_night + end + end + + view_rooms + end + + def view_rooms + puts "The hotel has the following rooms: " + table = Terminal::Table.new do |t| + t << ["Room", "Cost per night"] + hotel.rooms.each do |room| + t << :separator + t << [room.number, room.cost_per_night] + end + end + puts table + end + def display_user_menu - puts "\nWhat would you like to do?\n + puts "\nMenu Options:\n A. Book a room B. Reserve a block of rooms C. View reservations D. View available rooms E. View available rooms in a block - F. Change the price of a room + F. Change the cost of a room G. View all rooms in the hotel\n" end - def get_option + def get_menu_option + choice = nil + until choice =~ (/^[A-Ga-g]$/) + print "\nPlease choose an option: " + choice = $stdin.gets.chomp + end + return choice + end + def get_room_number + print "\n\tRoom Number: " + room_number = gets.chomp + until room_number =~ (/^([1-9]|1[0123456789]|20)$/) + puts "Invalid Room Number." + puts "Room Number: " + room_number = gets.chomp + end + return room_number end end end # end of hotel module -# -# interface = Hotel::Cli.new +# +interface = Hotel::Cli.new +interface.begin diff --git a/lib/rooms.rb b/lib/rooms.rb index 435b71331..04b0e92af 100644 --- a/lib/rooms.rb +++ b/lib/rooms.rb @@ -1,9 +1,11 @@ module Hotel class Room attr_reader :number + attr_accessor :cost_per_night def initialize(number) @number = check_room_number(number) + @cost_per_night = 200 end private diff --git a/specs/cli_spec.rb b/specs/cli_spec.rb index d62896178..3e959f89b 100644 --- a/specs/cli_spec.rb +++ b/specs/cli_spec.rb @@ -18,4 +18,9 @@ end + + + + + end diff --git a/specs/rooms_spec.rb b/specs/rooms_spec.rb index 37147b8f1..b0e110fe9 100644 --- a/specs/rooms_spec.rb +++ b/specs/rooms_spec.rb @@ -9,15 +9,24 @@ it "raises an ArgumentError for invalid parameters" do proc{Hotel::Room.new("A15")}.must_raise ArgumentError end - it "raies an ArgumentError if the room number already exists" do - + it "initializes wiht a cost of 200 per night" do + room = Hotel::Room.new(5) + room.cost_per_night.must_equal 200 end end - describe "atribute_readers" do + describe "attr accessors" do it "can retrieve the room number using .number" do room = Hotel::Room.new(5) room.number.must_equal 5 end + it "can retrieve and change the cost of a room per night" do + room = Hotel::Room.new(3) + room.cost_per_night.must_equal 200 + + room.cost_per_night = 150 + + room.cost_per_night.must_equal 150 + end end end From 6a72a201c332fdd573b03e7d6634623772d30ec4 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Sat, 9 Sep 2017 18:18:49 -0700 Subject: [PATCH 20/28] cli - change price of room per night --- lib/cli.rb | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/cli.rb b/lib/cli.rb index 329dec92e..f4ae9fac2 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -54,20 +54,12 @@ def view_available_rooms_in_block def change_room_cost room_number = get_room_number - ### + new_cost = get_value - cost = "cost" - until cost =~ (/\d/) - print "\n\tNew Cost: " - cost = gets.chomp - end - p cost - new_cost = nil hotel.rooms.each do |room| if room.number == room_number - hotel.room.cost_per_night = cost - new_cost = room.cost_per_night + room.cost_per_night = new_cost end end @@ -106,15 +98,26 @@ def get_menu_option return choice end + def get_value + print "\n\tNew Cost: " + value = gets.chomp + until value =~ (/\d/) + puts "Invalid Cost." + print "New Cost: " + value = gets.chomp + end + return value.to_i + end + def get_room_number print "\n\tRoom Number: " room_number = gets.chomp until room_number =~ (/^([1-9]|1[0123456789]|20)$/) puts "Invalid Room Number." - puts "Room Number: " + print "Room Number: " room_number = gets.chomp end - return room_number + return room_number.to_i end end From e2ccb9623a45dec02867cc64a4086bcd6dd939fd Mon Sep 17 00:00:00 2001 From: Shaunna Date: Sat, 9 Sep 2017 19:28:55 -0700 Subject: [PATCH 21/28] view available rooms in block cli added --- lib/cli.rb | 84 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 20 deletions(-) diff --git a/lib/cli.rb b/lib/cli.rb index f4ae9fac2..1ea145e82 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -44,38 +44,44 @@ def view_reservations end def view_available_rooms + beginning_date = get_date_for( + "begin") + + end_date = get_date_for("end") + + available_rooms = hotel.get_available_rooms(beginning_date, end_date) + + show_table_of_rooms(available_rooms) end + + ####### COME BACK TO THIS TO SEE IF IT WORKS ########## def view_available_rooms_in_block + block = get_block - end + puts "Rooms still available for block ID:#{block.id} :" - #############!##!!###!!!! DOESN'T WORK!!!!!!!!!! + rooms_available_in_block = hotel.get_available_rooms_from_block(bblock) + + show_table_of_rooms(rooms_available_in_block) + + end def change_room_cost - room_number = get_room_number + room = get_room new_cost = get_value + room.cost_per_night = new_cost - hotel.rooms.each do |room| - if room.number == room_number - room.cost_per_night = new_cost - end - end + puts "\nRoom #{room.number} has been changed to $#{room.cost_per_night} per night." view_rooms end def view_rooms - puts "The hotel has the following rooms: " - table = Terminal::Table.new do |t| - t << ["Room", "Cost per night"] - hotel.rooms.each do |room| - t << :separator - t << [room.number, room.cost_per_night] - end - end - puts table + puts "\nHere is a current list of the rooms and their prices: " + + show_table_of_rooms(hotel.rooms) end def display_user_menu @@ -89,6 +95,12 @@ def display_user_menu G. View all rooms in the hotel\n" end + def get_date_for(action) + puts "What date would you like to #{action}?" + + + end + def get_menu_option choice = nil until choice =~ (/^[A-Ga-g]$/) @@ -98,6 +110,21 @@ def get_menu_option return choice end + def get_block + while true + print "Block ID: " + block_id = gets.chomp + + hotel.blocks.each do |block| + if block.id = block_id + return block + end + end + puts "I'm sorry, that ID doesn't exit." + end + end + + ########## WRITE TESTS ########### def get_value print "\n\tNew Cost: " value = gets.chomp @@ -109,17 +136,34 @@ def get_value return value.to_i end - def get_room_number + ########## WRITE TESTS ############## + def get_room print "\n\tRoom Number: " room_number = gets.chomp - until room_number =~ (/^([1-9]|1[0123456789]|20)$/) + until room_number =~ (/^([1-9]|1[0-9]|20)$/) puts "Invalid Room Number." print "Room Number: " room_number = gets.chomp end - return room_number.to_i + + hotel.rooms.each do |room| + if room.number == room_number.to_i + return room + end + end + raise StandardError.new "No room found" end + def show_table_of_rooms(rooms_arry) + table = Terminal::Table.new do |t| + t << ["Room", "Cost per night"] + rooms.each do |room| + t << :separator + t << [room.number, room.cost_per_night] + end + end + puts table + end end end # end of hotel module # From 2cabb585c8bf45726de9e0921a279e170d095c0d Mon Sep 17 00:00:00 2001 From: Shaunna Date: Sun, 10 Sep 2017 11:14:53 -0700 Subject: [PATCH 22/28] basic user interface works with multiple bugs --- lib/cli.rb | 197 +++++++++++++++++++++++++++++++++----------- lib/hotel.rb | 5 ++ lib/reservations.rb | 2 +- specs/cli_spec.rb | 36 ++++---- 4 files changed, 175 insertions(+), 65 deletions(-) diff --git a/lib/cli.rb b/lib/cli.rb index 1ea145e82..9eea841ad 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -1,5 +1,6 @@ require_relative 'hotel' require 'terminal-table' +require 'chronic' module Hotel class Cli @@ -11,51 +12,130 @@ def initialize end def begin - display_user_menu - choice = get_menu_option - - case choice - when "A" - reserve_room - when "B" - make_block_of_rooms - when "C" - view_reservations - when "D" - view_available_rooms - when "E" - view_available_rooms_in_block - when "F" - change_room_cost - when "G" - view_rooms - else - raise ArgumentError.new "not a valid choice" + while true + display_user_menu + choice = get_menu_option + + case choice + when "A" + reserve_room + when "B" + reserve_room_from_block + when "C" + make_block_of_rooms + when "D" + view_reservations + when "E" + view_all_reservations + when "F" + view_available_rooms + when "G" + view_available_rooms_in_block + when "H" + change_room_cost + when "I" + view_rooms + when "X" + abort("Thank you! Have a nice day!") + else + raise ArgumentError.new "not a valid choice" + end + + end + end + + def display_user_menu + puts "\nMenu Options:\n + A. Book a room + B. Book a room from a block + C. Reserve a block of rooms + D. View reservations by date + E. View all reservations + F. View available rooms + G. View available rooms in a block + H. Change the cost of a room + I. View all rooms in the hotel\n + X. Exit the program" + end + + def get_menu_option + choice = nil + until choice =~ (/^[A-Ia-i]|[Xx]$/) + print "\nPlease choose an option: " + choice = $stdin.gets.chomp end + return choice.upcase end + ### Write in option of no room preference + # choice A def reserve_room + + check_in= get_date_for("check in", Date.today) + + check_out = get_date_for("check out", check_in + 1) + + print "Guest Name: " + guest = gets.chomp + + print "Preferred Room: " + room = get_room + + hotel.make_reservation(guest, check_in, check_out, room.number) end + # choice B + def reserve_room_from_block + block = get_block + + print "Guest Name: " + guest = gets.chomp + + hotel.make_reservation_from_block(guest, block.id) + end + + # choice C def make_block_of_rooms + check_in = get_date_for("check in", Date.today) + + check_out = get_date_for("check out", check_in + 1) + + num_rooms = get_num_rooms + + block = hotel.make_block(check_in, check_out, num_rooms) + + puts "Here are the rooms reserved for block ID: #{block.id}" + + show_table_of_rooms(block.rooms_in_block) end + # choice D def view_reservations + date = get_date_for("see reservations for") + hotel.get_res_by_date(date) + + + show_table_of_rooms(block.rooms_in_block) + end + + # choice E + def view_all_reservations + show_table_of_reservations(hotel.reservations) end + # choice F def view_available_rooms - beginning_date = get_date_for( - "begin") - end_date = get_date_for("end") + begin_date = get_date_for("begin", Date.today) + + end_date = get_date_for("end", begin_date + 1) available_rooms = hotel.get_available_rooms(beginning_date, end_date) show_table_of_rooms(available_rooms) end - - ####### COME BACK TO THIS TO SEE IF IT WORKS ########## + # choice G def view_available_rooms_in_block block = get_block @@ -67,6 +147,7 @@ def view_available_rooms_in_block end + # choice H def change_room_cost room = get_room new_cost = get_value @@ -78,36 +159,47 @@ def change_room_cost view_rooms end + # choce I def view_rooms puts "\nHere is a current list of the rooms and their prices: " show_table_of_rooms(hotel.rooms) end - def display_user_menu - puts "\nMenu Options:\n - A. Book a room - B. Reserve a block of rooms - C. View reservations - D. View available rooms - E. View available rooms in a block - F. Change the cost of a room - G. View all rooms in the hotel\n" + def get_num_rooms + num_rooms = nil + until num_rooms =~ (/[1-5]/) + print "How many rooms would you like to reserve? " + num_rooms = gets.chomp + end + return num_rooms.to_i end - def get_date_for(action) - puts "What date would you like to #{action}?" + def get_date_for(action, must_be_after_date = nil) + date = nil + while date == nil + date = get_date(action, must_be_after_date) + end + return date.to_date end - def get_menu_option - choice = nil - until choice =~ (/^[A-Ga-g]$/) - print "\nPlease choose an option: " - choice = $stdin.gets.chomp + def get_date(action, must_be_after_date) + begin + print "What date would you like to #{action}? " + input = gets.chomp + + date = Chronic.parse(input).to_date + + if (must_be_after_date != nil) && (date < must_be_after_date) + raise StandardError.new "Invalid Date" + end + rescue + puts "Invalid date" + date = nil end - return choice + return date end def get_block @@ -124,7 +216,6 @@ def get_block end end - ########## WRITE TESTS ########### def get_value print "\n\tNew Cost: " value = gets.chomp @@ -136,7 +227,6 @@ def get_value return value.to_i end - ########## WRITE TESTS ############## def get_room print "\n\tRoom Number: " room_number = gets.chomp @@ -157,15 +247,30 @@ def get_room def show_table_of_rooms(rooms_arry) table = Terminal::Table.new do |t| t << ["Room", "Cost per night"] - rooms.each do |room| + rooms_arry.each do |room| t << :separator t << [room.number, room.cost_per_night] end end puts table end + + def show_table_of_reservations(reservations) + table = Terminal::Table.new do |t| + t << ["Guest Name", "Check_in", "Check_out", "Room", "Block ID" ] + reservations.each do |res| + res.block_id ? block_id = res.block_id : block_id = "" + + t << :separator + t << [res.guest, res.check_in, res.check_out, res.room.number, block_id] + end + end + puts table + end end end # end of hotel module -# + + + interface = Hotel::Cli.new interface.begin diff --git a/lib/hotel.rb b/lib/hotel.rb index 173fddd8e..642679063 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,5 +1,6 @@ require_relative 'reservations' require_relative 'rooms' +require_relative 'block' module Hotel @@ -38,6 +39,8 @@ def make_block(check_in, check_out, num_rooms) raise StandardError.new "only possible to book 5 rooms in a block" end + ### Does this work to just say block.add_room? + num_rooms.times do room = assign_room(check_in, check_out) @blocks.each do |block_in_array| @@ -46,6 +49,8 @@ def make_block(check_in, check_out, num_rooms) end end end + + return block end diff --git a/lib/reservations.rb b/lib/reservations.rb index 3593fe0ee..bd9144850 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,7 +1,7 @@ module Hotel class Reservation - attr_reader :total_nights, :check_in, :check_out, :room, :block_id + attr_reader :total_nights, :check_in, :check_out, :room, :block_id, :guest def initialize(guest, check_in, check_out, room, block_id = nil) @guest = guest diff --git a/specs/cli_spec.rb b/specs/cli_spec.rb index 3e959f89b..963ac394a 100644 --- a/specs/cli_spec.rb +++ b/specs/cli_spec.rb @@ -1,26 +1,26 @@ require_relative 'spec_helper' describe "Command Line Interface" do - before do - @interface = Hotel::Cli.new + describe "creating and beginning" do + before do + @interface = Hotel::Cli.new + end + + it "can create an instance" do + @interface.must_be_instance_of Hotel::Cli + end + + it "initializes with a hotel" do + @interface.hotel.must_be_instance_of Hotel::Hotel + end + + it "displays_user_menu" do + @interface.must_respond_to :display_user_menu + end end - it " can create an instance" do - @interface.must_be_instance_of Hotel::Cli + describe "show_table_of_reservations" do + end - it "initializes with a hotel" do - @interface.hotel.must_be_instance_of Hotel::Hotel - end - - it "displays_user_menu" do - @interface.must_respond_to :display_user_menu - end - - - - - - - end From aa2fd7618df7615f6b63778290a9ea16d79bd389 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Sun, 10 Sep 2017 16:46:47 -0700 Subject: [PATCH 23/28] some bugs fixed.... --- lib/cli.rb | 104 ++++++++++++++++++++++++++------------------ lib/reservations.rb | 2 + specs/cli_spec.rb | 100 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 160 insertions(+), 46 deletions(-) diff --git a/lib/cli.rb b/lib/cli.rb index 9eea841ad..42fd77428 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -1,6 +1,7 @@ require_relative 'hotel' require 'terminal-table' require 'chronic' +require 'pry' module Hotel class Cli @@ -13,34 +14,42 @@ def initialize def begin while true + run_program + end + end + + def run_program + begin display_user_menu choice = get_menu_option case choice - when "A" - reserve_room - when "B" - reserve_room_from_block - when "C" - make_block_of_rooms - when "D" - view_reservations - when "E" - view_all_reservations - when "F" - view_available_rooms - when "G" - view_available_rooms_in_block - when "H" - change_room_cost - when "I" - view_rooms - when "X" - abort("Thank you! Have a nice day!") - else - raise ArgumentError.new "not a valid choice" + when "A" + reserve_room + when "B" + reserve_room_from_block + when "C" + make_block_of_rooms + when "D" + view_reservations + when "E" + view_all_reservations + when "F" + view_available_rooms + when "G" + view_available_rooms_in_block + when "H" + change_room_cost + when "I" + view_rooms + when "X" + abort("Thank you! Have a nice day!") + else + raise ArgumentError.new "not a valid choice" end - + rescue + puts "I'm sorry! Something went wrong! Please try again" + return true end end @@ -58,11 +67,16 @@ def display_user_menu X. Exit the program" end + def get_input + input = gets.chomp + return input + end + def get_menu_option choice = nil until choice =~ (/^[A-Ia-i]|[Xx]$/) print "\nPlease choose an option: " - choice = $stdin.gets.chomp + choice = get_input end return choice.upcase end @@ -70,18 +84,19 @@ def get_menu_option ### Write in option of no room preference # choice A def reserve_room - check_in= get_date_for("check in", Date.today) - check_out = get_date_for("check out", check_in + 1) + check_out = get_date_for("check out", check_in) print "Guest Name: " - guest = gets.chomp + guest = get_input - print "Preferred Room: " - room = get_room + print "Preferred Room (Type N for no preference): " + room_number = get_room + + res = hotel.make_reservation(guest, check_in, check_out, room_number) - hotel.make_reservation(guest, check_in, check_out, room.number) + show_table_of_reservations([res.last]) end # choice B @@ -89,7 +104,7 @@ def reserve_room_from_block block = get_block print "Guest Name: " - guest = gets.chomp + guest = get_input hotel.make_reservation_from_block(guest, block.id) end @@ -112,10 +127,9 @@ def make_block_of_rooms # choice D def view_reservations date = get_date_for("see reservations for") - hotel.get_res_by_date(date) + reservations = hotel.get_res_by_date(date) - - show_table_of_rooms(block.rooms_in_block) + show_table_of_reservations(reservations) end # choice E @@ -170,7 +184,7 @@ def get_num_rooms num_rooms = nil until num_rooms =~ (/[1-5]/) print "How many rooms would you like to reserve? " - num_rooms = gets.chomp + num_rooms = get_input end return num_rooms.to_i end @@ -188,7 +202,7 @@ def get_date_for(action, must_be_after_date = nil) def get_date(action, must_be_after_date) begin print "What date would you like to #{action}? " - input = gets.chomp + input = get_input date = Chronic.parse(input).to_date @@ -205,7 +219,7 @@ def get_date(action, must_be_after_date) def get_block while true print "Block ID: " - block_id = gets.chomp + block_id = get_input hotel.blocks.each do |block| if block.id = block_id @@ -222,23 +236,27 @@ def get_value until value =~ (/\d/) puts "Invalid Cost." print "New Cost: " - value = gets.chomp + value = get_input end return value.to_i end def get_room print "\n\tRoom Number: " - room_number = gets.chomp - until room_number =~ (/^([1-9]|1[0-9]|20)$/) + room_number = get_input + until room_number =~ (/^([1-9]|1[0-9]|20|[Nn])$/) puts "Invalid Room Number." print "Room Number: " - room_number = gets.chomp + room_number = get_input + end + + if room_number == "N" || room_number == "n" + return nil end hotel.rooms.each do |room| if room.number == room_number.to_i - return room + return room.number end end raise StandardError.new "No room found" @@ -253,6 +271,7 @@ def show_table_of_rooms(rooms_arry) end end puts table + return table end def show_table_of_reservations(reservations) @@ -266,6 +285,7 @@ def show_table_of_reservations(reservations) end end puts table + return table end end end # end of hotel module diff --git a/lib/reservations.rb b/lib/reservations.rb index bd9144850..1ea94156a 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -37,6 +37,8 @@ def check_out_date(check_out) def calculate_res_length if @check_in >= @check_out || @check_in < Date.today + puts @check_in + puts @check_out raise ArgumentError.new "invalid dates" else length = @check_out - @check_in diff --git a/specs/cli_spec.rb b/specs/cli_spec.rb index 963ac394a..8653a5e29 100644 --- a/specs/cli_spec.rb +++ b/specs/cli_spec.rb @@ -13,14 +13,106 @@ it "initializes with a hotel" do @interface.hotel.must_be_instance_of Hotel::Hotel end + end - it "displays_user_menu" do - @interface.must_respond_to :display_user_menu + describe "display_user_menu" do + it "displays the user menu" do + interface = Hotel::Cli.new + interface.must_respond_to :display_user_menu end end - describe "show_table_of_reservations" do - + describe "get menu option" do + it "accepts A as a user option" do + class Hotel::Cli + def get_input + return "A" + end + end + + interface = Hotel::Cli.new + interface.get_menu_option.must_equal "A" + end + it "accepts i as a user option and returns I" do + class Hotel::Cli + def get_input + return "i" + end + end + + interface = Hotel::Cli.new + interface.get_menu_option.must_equal "I" + end + it "accepts x as a user option and returns X" do + class Hotel::Cli + def get_input + return "x" + end + end + + interface = Hotel::Cli.new + interface.get_menu_option.must_equal "X" + end + end + + + describe "reserve room" do + before do + # @interface = Hotel::Cli.new + # class Hotel::Cli + # def get_date_for + # Date.new(2018, 5, 5) + # end + # def check_out + # Date.new(2018, 5, 8) + # end + # def room + # return 18 + # end + # def get_input + # return "Shaunna" + # end + # end + end + it "increases the reservation by one" do + # before = @interface.hotel.reservations.clone.length + # + # @interface.reserve_room + # + # after = @interface.hotel.reservations.length + # + # (before + 1).must_equal after + + + end + end + + + + + + # Doesn't properly test for content of table or that table shows up in the terminal + describe "show_tables" do + before do + @interface = Hotel::Cli.new + + check_in = Date.new(2018, 7, 6) + check_out = Date.new(2018, 7, 8) + + (1..10).each do |num| + @interface.hotel.make_reservation("guest", check_in, check_out, num) + end + end + + it "returns the table of rooms" do + table = @interface.show_table_of_rooms(@interface.hotel.rooms) + table.rows.length.must_equal 21 + end + + it "returns the table of reservations" do + table = @interface.show_table_of_reservations(@interface.hotel.reservations) + table.rows.length.must_equal 11 + end end end From bcc9b520b12144dbe6cdb38619b200a3845862d2 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Sun, 10 Sep 2017 22:49:13 -0700 Subject: [PATCH 24/28] cli file finished, still some bugs, no tests. cli_spec name chagnd so that it isn't included in rake --- lib/cli.rb | 38 ++++++++++++++++-------------- lib/hotel.rb | 24 +++++++------------ lib/pricing.rb | 9 ++----- lib/reservations.rb | 2 -- specs/{cli_spec.rb => cli-spec.rb} | 0 specs/hotel_spec.rb | 21 +++++++++++++++++ specs/reservations_spec.rb | 12 +++++++--- specs/spec_helper.rb | 2 +- 8 files changed, 62 insertions(+), 46 deletions(-) rename specs/{cli_spec.rb => cli-spec.rb} (100%) diff --git a/lib/cli.rb b/lib/cli.rb index 42fd77428..9e7fb5a98 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -1,4 +1,5 @@ require_relative 'hotel' +require_relative 'pricing' require 'terminal-table' require 'chronic' require 'pry' @@ -58,7 +59,7 @@ def display_user_menu A. Book a room B. Book a room from a block C. Reserve a block of rooms - D. View reservations by date + D. View reservations (and costs) by date E. View all reservations F. View available rooms G. View available rooms in a block @@ -84,9 +85,9 @@ def get_menu_option ### Write in option of no room preference # choice A def reserve_room - check_in= get_date_for("check in", Date.today) + check_in = get_date_for("check in", Date.today) - check_out = get_date_for("check out", check_in) + check_out = get_date_for("check out", check_in + 1) print "Guest Name: " guest = get_input @@ -106,7 +107,9 @@ def reserve_room_from_block print "Guest Name: " guest = get_input - hotel.make_reservation_from_block(guest, block.id) + res = hotel.make_reservation_from_block(guest, block.id) + + show_table_of_reservations([res.last]) end # choice C @@ -144,7 +147,7 @@ def view_available_rooms end_date = get_date_for("end", begin_date + 1) - available_rooms = hotel.get_available_rooms(beginning_date, end_date) + available_rooms = hotel.get_available_rooms(begin_date, end_date) show_table_of_rooms(available_rooms) end @@ -155,7 +158,7 @@ def view_available_rooms_in_block puts "Rooms still available for block ID:#{block.id} :" - rooms_available_in_block = hotel.get_available_rooms_from_block(bblock) + rooms_available_in_block = hotel.get_available_rooms_from_block(block) show_table_of_rooms(rooms_available_in_block) @@ -164,6 +167,7 @@ def view_available_rooms_in_block # choice H def change_room_cost room = get_room + print "New Cost: " new_cost = get_value room.cost_per_night = new_cost @@ -183,7 +187,7 @@ def view_rooms def get_num_rooms num_rooms = nil until num_rooms =~ (/[1-5]/) - print "How many rooms would you like to reserve? " + print "How many rooms would you like to reserve? (max 5)" num_rooms = get_input end return num_rooms.to_i @@ -219,23 +223,21 @@ def get_date(action, must_be_after_date) def get_block while true print "Block ID: " - block_id = get_input + block_id = get_value hotel.blocks.each do |block| - if block.id = block_id + if block.id == block_id.to_i return block end end - puts "I'm sorry, that ID doesn't exit." + puts "I'm sorry, that ID doesn't exist." end end def get_value - print "\n\tNew Cost: " value = gets.chomp until value =~ (/\d/) - puts "Invalid Cost." - print "New Cost: " + puts "Invalid. Please enter a number." value = get_input end return value.to_i @@ -256,7 +258,7 @@ def get_room hotel.rooms.each do |room| if room.number == room_number.to_i - return room.number + return room end end raise StandardError.new "No room found" @@ -276,12 +278,12 @@ def show_table_of_rooms(rooms_arry) def show_table_of_reservations(reservations) table = Terminal::Table.new do |t| - t << ["Guest Name", "Check_in", "Check_out", "Room", "Block ID" ] + t << ["Guest Name", "Check_in", "Check_out", "Room", "Total Cost", "Block ID" ] reservations.each do |res| - res.block_id ? block_id = res.block_id : block_id = "" + res.block_id ? block_id = res.block_id : block_id = nil t << :separator - t << [res.guest, res.check_in, res.check_out, res.room.number, block_id] + t << [res.guest, res.check_in, res.check_out, res.room.number, Pricing.calc_cost(res), block_id] end end puts table @@ -291,6 +293,6 @@ def show_table_of_reservations(reservations) end # end of hotel module - +# interface = Hotel::Cli.new interface.begin diff --git a/lib/hotel.rb b/lib/hotel.rb index 642679063..f48971d47 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -2,7 +2,6 @@ require_relative 'rooms' require_relative 'block' - module Hotel class Hotel @@ -43,17 +42,12 @@ def make_block(check_in, check_out, num_rooms) num_rooms.times do room = assign_room(check_in, check_out) - @blocks.each do |block_in_array| - if block.id == id - block.add_room(room) - end - end + block.add_room(room) end return block end - #THERE HAS TO BE A BETTER WAY TO DO THIS. def assign_room(check_in, check_out, room_requested = nil) available_rooms = get_available_rooms(check_in, check_out) @@ -131,14 +125,14 @@ def find_block_by_id(block_id) raise StandardError.new "this id doesn't exit" end - def find_room_by_number(room_number) - rooms.each do |room| - if room.number == room_number - return room - end - end - raise StandardError.new "this room doesn't exist" - end + # def find_room_by_number(room_number) + # rooms.each do |room| + # if room.number == room_number + # return room + # end + # end + # raise StandardError.new "this room doesn't exist" + # end def assign_id id = 111111 diff --git a/lib/pricing.rb b/lib/pricing.rb index 9e6045b27..3394fab51 100644 --- a/lib/pricing.rb +++ b/lib/pricing.rb @@ -4,15 +4,10 @@ class Pricing def self.calc_cost(reservation) total_nights = reservation.total_nights - if reservation.block_id != nil - discount = 0.1 - end - cost = (total_nights * 200.0) - if reservation.block_id != nil - discount = 0.1 - cost -= cost*0.1 + if reservation.block_id + cost -= cost * 0.1 end return cost diff --git a/lib/reservations.rb b/lib/reservations.rb index 1ea94156a..bd9144850 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -37,8 +37,6 @@ def check_out_date(check_out) def calculate_res_length if @check_in >= @check_out || @check_in < Date.today - puts @check_in - puts @check_out raise ArgumentError.new "invalid dates" else length = @check_out - @check_in diff --git a/specs/cli_spec.rb b/specs/cli-spec.rb similarity index 100% rename from specs/cli_spec.rb rename to specs/cli-spec.rb diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index df878c8d9..089066896 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -297,6 +297,27 @@ end # end get_res_by_date + # describe "find block by id" do + # it "returns an error if id doesn't exist" do + # hotel = Hotel::Hotel.new + # + # hotel.make_block(Date.new(2017, 12, 12), Date.new(2017, 12, 20), 4) + # + # proc{hotel.find_block_by_id(123456)}.must_raise StandardError + # end + # + # it "returns the block if the id exists" do + # hotel = Hotel::Hotel.new + # + # block = hotel.make_block(Date.new(2017, 12, 12), Date.new(2017, 12, 20), 4) + # + # hotel.make_block(Date.new(2018, 1, 12), Date.new(2017, 1, 20), 4) + # + # hotel.make_block(Date.new(2018, 12, 12), Date.new(2017, 12, 20), 4) + # + # hotel.find_block_by_id(111111).must_equal block + # end + # end ########### HOW TO TEST THIS METHOD?? ######### ## CURRENTLY TESTING FOR LENGTH ## describe "get_available_rooms method" do diff --git a/specs/reservations_spec.rb b/specs/reservations_spec.rb index 14599e8ab..6e5ce3257 100644 --- a/specs/reservations_spec.rb +++ b/specs/reservations_spec.rb @@ -17,6 +17,7 @@ check_in = [2017, 11, 14] check_out = [2017, 11, 16] proc{Hotel::Reservation.new(@guest, check_in, check_out, Hotel::Room.new(5))}.must_raise ArgumentError + proc{Hotel::Reservation.new(@guest, Date.new(2017, 11, 14), check_out, Hotel::Room.new(5))}.must_raise ArgumentError end it "accurately calculates the length of a stay of 1 night" do @@ -34,9 +35,15 @@ end it "accurately calculates the length of stay of 7 days" do - reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 19), Hotel::Room.new(12)) + reservation = Hotel::Reservation.new("guest", Date.new(2018, 11, 12), Date.new(2018, 11, 19), Hotel::Room.new(12)) - reservation.total_nights.must_equal 7 + reservation.total_nights.must_equal 7 + end + + it "raises an ArgumentError if the check in or check out date is too early" do + proc{Hotel::Reservation.new(@guest, Date.today - 1, Date.new(2017, 12, 25), Hotel::Room.new(5))}.must_raise ArgumentError + + proc{Hotel::Reservation.new(@guest, Date.new(2017, 12, 26), Date.new(2017, 12, 25), Hotel::Room.new(5))}.must_raise ArgumentError end end @@ -100,5 +107,4 @@ - end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index d276afdaa..207ad9d87 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -14,4 +14,4 @@ require_relative '../lib/rooms.rb' require_relative '../lib/pricing.rb' require_relative '../lib/block.rb' -require_relative '../lib/cli.rb' +# require_relative '../lib/cli.rb' From 918005de9f673b00c08df7a4ad0753583bea1b37 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Thu, 28 Sep 2017 09:24:10 -0700 Subject: [PATCH 25/28] design-acitvity included --- design-activity.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 design-activity.md diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..1c6fc25f0 --- /dev/null +++ b/design-activity.md @@ -0,0 +1,61 @@ +What classes does each implementation include? Are the lists the same? + +Each implementation includes the following classes (They are the same): +CartEntry +ShoppingCart +Order + + +Write down a sentence to describe each class. + +CartEntry: This class includes the quantity and price of each item in the ShoppingCart + +ShoppingCart: This class includes an array of entries. + +Order: This class calculates the total price of the order including sales tax. + +** In implementation B the CartEntry calculates the cost of the entry and the ShoppingCart calculated the total (with sales tax being included in the order). In implementation A the Order combines all the calculations for price. ** + + +How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. + +ShoppingCart holds an array that can be filled with instances of CartEntry (or anything else for that matter, since it isn't hard coded into the ShoppingCart class.) Order has-a ShoppingCart + +What data does each class store? How (if at all) does this differ between the two implementations? + +CartEntry: unit price and quantity of the item in the cart +ShoppingCart: collection of entries +Order: an instance of ShoppingCart, and the constant value of the SALES_TAX. + +The data stored in each class is the same for both classes, the difference is that in implementation A the Order is responsible for all the pricing calculations whereas in Implementation B, each class has a method to communicate the calculation of the price. + +What methods does each class have? How (if at all) does this differ between the two implementations? + +A: +CartEntry: attr_accessor for unit price and quantity +ShoppingCart: attr_accessor for entries +Order: total_price to calculate the total price of the Order + +B: +CartEntry: same as A with additional price method to calculate the price of the CartEntry +ShoppingCart: same as A with an additional price method to calculate the sum of all the CartEntry prices +Order: same, but the total_price method receives a method from the ShoppingCart to receive the total price before tax and the uses that to calculate the total_price with tax. This is a better implementation since the calculation done on the entries is done in their respective methods instead of in the Order class. + +Consider the Order#total_price method. In each implementation: + + +Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order? + + +Does total_price directly manipulate the instance variables of other classes? + + +If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? + +Which implementation better adheres to the single responsibility principle? + +Implementation B better adheres to the single responsibility principle. + +Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? + +Implementation B is more loosely coupled. From abaadeaeac2374e4d79c3f19d9eb6a34097659e3 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Thu, 28 Sep 2017 09:32:32 -0700 Subject: [PATCH 26/28] updated design_acitivity --- design-activity.md | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/design-activity.md b/design-activity.md index 1c6fc25f0..49b99383e 100644 --- a/design-activity.md +++ b/design-activity.md @@ -1,4 +1,4 @@ -What classes does each implementation include? Are the lists the same? +* **What classes does each implementation include? Are the lists the same?** Each implementation includes the following classes (They are the same): CartEntry @@ -6,7 +6,7 @@ ShoppingCart Order -Write down a sentence to describe each class. +* **Write down a sentence to describe each class.** CartEntry: This class includes the quantity and price of each item in the ShoppingCart @@ -14,14 +14,14 @@ ShoppingCart: This class includes an array of entries. Order: This class calculates the total price of the order including sales tax. -** In implementation B the CartEntry calculates the cost of the entry and the ShoppingCart calculated the total (with sales tax being included in the order). In implementation A the Order combines all the calculations for price. ** +_In implementation B the CartEntry calculates the cost of the entry and the ShoppingCart calculated the total (with sales tax being included in the order). In implementation A the Order combines all the calculations for price._ -How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. +* **How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper.** ShoppingCart holds an array that can be filled with instances of CartEntry (or anything else for that matter, since it isn't hard coded into the ShoppingCart class.) Order has-a ShoppingCart -What data does each class store? How (if at all) does this differ between the two implementations? +* **What data does each class store? How (if at all) does this differ between the two implementations?** CartEntry: unit price and quantity of the item in the cart ShoppingCart: collection of entries @@ -29,7 +29,7 @@ Order: an instance of ShoppingCart, and the constant value of the SALES_TAX. The data stored in each class is the same for both classes, the difference is that in implementation A the Order is responsible for all the pricing calculations whereas in Implementation B, each class has a method to communicate the calculation of the price. -What methods does each class have? How (if at all) does this differ between the two implementations? +* **What methods does each class have? How (if at all) does this differ between the two implementations?** A: CartEntry: attr_accessor for unit price and quantity @@ -41,21 +41,22 @@ CartEntry: same as A with additional price method to calculate the price of the ShoppingCart: same as A with an additional price method to calculate the sum of all the CartEntry prices Order: same, but the total_price method receives a method from the ShoppingCart to receive the total price before tax and the uses that to calculate the total_price with tax. This is a better implementation since the calculation done on the entries is done in their respective methods instead of in the Order class. -Consider the Order#total_price method. In each implementation: +* **Consider the Order#total_price method. In each implementation: +Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order?** +A: computing the price is all retained in Order +B: delegated to "lower level" classes +* **Does total_price directly manipulate the instance variables of other classes?** -Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order? +* **If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify?** -Does total_price directly manipulate the instance variables of other classes? +We would need to write a conditional statement into the price. This would be easier to modify in implementation B. - -If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? - -Which implementation better adheres to the single responsibility principle? +* **Which implementation better adheres to the single responsibility principle?** Implementation B better adheres to the single responsibility principle. -Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? +* **Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?** Implementation B is more loosely coupled. From 499175d46f76dd2df2f444db3d000c21ed9c78c6 Mon Sep 17 00:00:00 2001 From: Shaunna Date: Fri, 29 Sep 2017 10:42:24 -0700 Subject: [PATCH 27/28] added a date_range class --- design-activity.md | 26 ++++++++++++++++ lib/block.rb | 7 +++-- lib/date_range.rb | 45 +++++++++++++++++++++++++++ lib/hotel.rb | 35 +++++++++++++++------ lib/reservations.rb | 67 ++++++++++++++++++++++------------------- specs/daterange_spec.rb | 55 +++++++++++++++++++++++++++++++++ specs/hotel_spec.rb | 3 +- specs/spec_helper.rb | 1 + 8 files changed, 194 insertions(+), 45 deletions(-) create mode 100644 lib/date_range.rb create mode 100644 specs/daterange_spec.rb diff --git a/design-activity.md b/design-activity.md index 49b99383e..71763e28a 100644 --- a/design-activity.md +++ b/design-activity.md @@ -1,3 +1,5 @@ +# Activity: Evaluating Responsibility + * **What classes does each implementation include? Are the lists the same?** Each implementation includes the following classes (They are the same): @@ -60,3 +62,27 @@ Implementation B better adheres to the single responsibility principle. * **Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?** Implementation B is more loosely coupled. +------------------- + +# Revisiting Hotel Activity: + +- Block needs to do it's own testing for invalid dates (date range class?) + +- Price should be calculated by the reservation (Not right now since price of room is dictated by the room) + +- Find by can be done in all method of block and reservation + +-- create a date range class that is a superclass to reservation and block +-- take overlap from hotel class and put it into date range class. + + + + + +Nicely done! In your testing for Block you should include testing for things such as invalid dates at the Block class level because the class might be reused elsewhere. + +Also in your testing, what about when you try to reserve a room with an invalid room #? Good edge case testing to see if you can reserve a room on the day someone is checking out. + +For testing the uniqueness of the block booking you can make a hash of all the booking IDs and loop through counting how often they occur as the value. Then if all the values are 1, they're unique. Because they're random there's no way to verify it 100%, but you could run the test several times. + +For returns 17 rooms when there are three room conflicts you can also just verify that the available rooms don't include the rooms in the specific reservations. Overall you did really really well. The design was good, although as you noted, not perfect. You also did a very through job testing. diff --git a/lib/block.rb b/lib/block.rb index 412d50f43..6f8b34b19 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -1,11 +1,12 @@ +require_relative 'date_range.rb' + module Hotel - class Block + class Block < DateRange attr_reader :check_in, :check_out, :id, :rooms_in_block, :discount def initialize(check_in, check_out, id) - @check_in = check_in - @check_out = check_out + super(check_in, check_out) @id = id @rooms_in_block = [] end diff --git a/lib/date_range.rb b/lib/date_range.rb new file mode 100644 index 000000000..994aaab46 --- /dev/null +++ b/lib/date_range.rb @@ -0,0 +1,45 @@ + +module Hotel + class DateRange + + attr_reader :total_nights, :check_in, :check_out + + def initialize(check_in, check_out) + @check_in = check_valid_date(check_in) + @check_out = check_valid_date(check_out) + @total_nights = calculate_length + end + + def include_date?(date) + date.between?(@check_in, @check_out - 1) + end + + def calculate_length + if @check_in >= @check_out || @check_in < Date.today + raise ArgumentError.new "invalid dates" + else + length = @check_out - @check_in + return length.to_i + end + end + + def check_valid_date(date) + if date.is_a? (Date) + return date + else + raise ArgumentError.new "argument must be a Date. Current argument is #{date.class}" + end + end + + def overlap(other_res) + overlap = (@check_in...@check_out).to_a & (other_res.check_in...other_res.check_out).to_a + return overlap + end + + + + + + + end #end DateRange +end #end Hotel diff --git a/lib/hotel.rb b/lib/hotel.rb index f48971d47..af16a1525 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,6 +1,9 @@ require_relative 'reservations' require_relative 'rooms' require_relative 'block' +require_relative 'date_range' + +require 'pry' module Hotel class Hotel @@ -38,8 +41,6 @@ def make_block(check_in, check_out, num_rooms) raise StandardError.new "only possible to book 5 rooms in a block" end - ### Does this work to just say block.add_room? - num_rooms.times do room = assign_room(check_in, check_out) block.add_room(room) @@ -77,27 +78,43 @@ def get_res_by_date(date) return res_by_date end - def get_available_rooms(date_begin, date_end) + def get_available_rooms(check_in, check_out) available_rooms = @rooms.clone - @reservations.each do |res| - overlap = (res.check_in...res.check_out).to_a & (date_begin...date_end).to_a + res_date = DateRange.new(check_in, check_out) - if overlap[0] != nil + @reservations.each do |res| + unless res_date.overlap(res).empty? available_rooms.delete(res.room) end end @blocks.each do |block| - overlap = (block.check_in...block.check_out).to_a & (date_begin...date_end).to_a - - if overlap[0] != nil + unless res_date.overlap(block).empty? block.rooms_in_block.each do |room| available_rooms.delete(room) end end end + # @reservations.each do |res| + # overlap = (res.check_in...res.check_out).to_a & (date_begin...date_end).to_a + # + # if overlap[0] != nil + # available_rooms.delete(res.room) + # end + # end + # + # @blocks.each do |block| + # overlap = (block.check_in...block.check_out).to_a & (date_begin...date_end).to_a + # + # if overlap[0] != nil + # block.rooms_in_block.each do |room| + # available_rooms.delete(room) + # end + # end + # end + return available_rooms end diff --git a/lib/reservations.rb b/lib/reservations.rb index bd9144850..5210f76fc 100644 --- a/lib/reservations.rb +++ b/lib/reservations.rb @@ -1,48 +1,53 @@ +require_relative 'date_range.rb' +require_relative 'rooms.rb' + module Hotel - class Reservation + class Reservation < DateRange attr_reader :total_nights, :check_in, :check_out, :room, :block_id, :guest def initialize(guest, check_in, check_out, room, block_id = nil) + super(check_in, check_out) @guest = guest - @check_in = check_in_date(check_in) - @check_out = check_out_date(check_out) @room = room - @total_nights = calculate_res_length @block_id = block_id end # Reservations that are checking out on that date will return false since they are not staying that night at the hotel - def include_date?(date) - date.between?(@check_in, @check_out - 1) - end - - private - def check_in_date(check_in) - if check_in.is_a? (Date) - @check_in = check_in - else - raise ArgumentError.new "check_in must be a Date" - end - end + #CLASS INCLUDED IN DATE_RANGE + # def include_date?(date) + # date.between?(@check_in, @check_out - 1) + # end - def check_out_date(check_out) - if check_out.is_a? (Date) - @check_out = check_out - else - raise ArgumentError.new "check_out must be a date" - end - end + private - def calculate_res_length - if @check_in >= @check_out || @check_in < Date.today - raise ArgumentError.new "invalid dates" - else - length = @check_out - @check_in - return length.to_i - end - end + #CLASSES BELOW NOW COVERED UNDER DATE_RANGE CLASS + + # def check_in_date(check_in) + # if check_in.is_a? (Date) + # @check_in = check_in + # else + # raise ArgumentError.new "check_in must be a Date" + # end + # end + # + # def check_out_date(check_out) + # if check_out.is_a? (Date) + # @check_out = check_out + # else + # raise ArgumentError.new "check_out must be a date" + # end + # end + + # def calculate_res_length + # if @check_in >= @check_out || @check_in < Date.today + # raise ArgumentError.new "invalid dates" + # else + # length = @check_out - @check_in + # return length.to_i + # end + # end end #end of Reservation class end #end of Hotel module diff --git a/specs/daterange_spec.rb b/specs/daterange_spec.rb new file mode 100644 index 000000000..6cdc593ed --- /dev/null +++ b/specs/daterange_spec.rb @@ -0,0 +1,55 @@ +require_relative 'spec_helper' + +require 'pry' + +describe Hotel::DateRange do + describe "an instance of DateRange can be created" do + before do + @check_in = Date.new(2018, 10, 5) + @check_out = Date.new(2018, 10, 7) + @date_range = Hotel::DateRange.new(@check_in, @check_out) + end + it "can be created" do + @date_range.must_be_instance_of Hotel::DateRange + end + + it "has a check-in, check_out" do + @date_range.check_in.must_equal @check_in + @date_range.check_out.must_equal @check_out + end + + it "accurately calculates the total nights included" do + @date_range.total_nights.must_equal 2 + end + + it "returns and error if the check in date is after the check in date or if the check in date is before today" do + proc{Hotel::DateRange.new(Date.today - 1, Date.new(2017, 12, 25))}.must_raise ArgumentError + + proc{Hotel::DateRange.new(Date.new(2017, 12, 26), Date.new(2017, 12, 25))}.must_raise ArgumentError + end + end + + describe "overlap" do + before do + @dr1 = Hotel::DateRange.new(Date.new(2018, 1, 1),(Date.new(2018, 1, 20))) + + @dr2 = Hotel::DateRange.new(Date.new(2018, 1, 5),(Date.new(2018, 1, 15))) + + @dr3 = Hotel::DateRange.new(Date.new(2018, 1, 17),(Date.new(2018, 1, 20))) + end + + it "returns an array" do + @dr1.overlap(@dr2).must_be_kind_of Array + end + + it "returns an empty array if no dates overlap" do + @dr2.overlap(@dr3).empty?.must_equal true + end + + it "returns a non-empty array if some dates overlap" do + @dr1.overlap(@dr3).empty?.must_equal false + end + + end + +end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 089066896..3a70a7dd9 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -108,6 +108,7 @@ @block = @hotel.blocks[0] @id = @hotel.blocks[0].id @hotel.make_reservation_from_block("guest", @id) + end it "returns an Array of Rooms" do @@ -153,8 +154,6 @@ hotel.make_reservation_from_block("guest", block.id) end - - hotel.get_available_rooms_from_block(hotel.blocks[0]).length.must_equal 0 end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 207ad9d87..a35f15150 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -14,4 +14,5 @@ require_relative '../lib/rooms.rb' require_relative '../lib/pricing.rb' require_relative '../lib/block.rb' +require_relative '../lib/date_range.rb' # require_relative '../lib/cli.rb' From a7b858f8664a95e42090e2b1f8f7f98580a1b5bb Mon Sep 17 00:00:00 2001 From: Shaunna Date: Fri, 29 Sep 2017 10:51:54 -0700 Subject: [PATCH 28/28] description of hotel changes in design-activity --- design-activity.md | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/design-activity.md b/design-activity.md index 71763e28a..f09b4b4d8 100644 --- a/design-activity.md +++ b/design-activity.md @@ -49,7 +49,7 @@ A: computing the price is all retained in Order B: delegated to "lower level" classes * **Does total_price directly manipulate the instance variables of other classes?** - +I struggle with this question in terms of what it means to manipulate an instance variable. total_price does not change the value of any of the instance variables from other classes, but it does make calculations using the instance variables. * **If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify?** @@ -66,23 +66,8 @@ Implementation B is more loosely coupled. # Revisiting Hotel Activity: -- Block needs to do it's own testing for invalid dates (date range class?) - -- Price should be calculated by the reservation (Not right now since price of room is dictated by the room) +A change that I decided to make to my Hotel project included changes within several classes. I created a DateRange class that was a superclass for Reservations and Blocks. Since Blocks and Reservations need to utilize the same features such as a check_in date, a check_out date, and a way to check for room availability, this allowed for one class to take care of all those features as well as check for date validity. This creates for code that is more DRY as well as classes that are easier to re-use and change. Within the Hotel class I changed to responsibility for checking for an overlap between the dates requested to check in and the rooms in the hotel to the Date Range class. My tests proved useful when I ran rake and found a few failures that were due to my change in code and they pointed me in the right direction. I found myself extremely grateful for the existence of tests! -- Find by can be done in all method of block and reservation -- create a date range class that is a superclass to reservation and block -- take overlap from hotel class and put it into date range class. - - - - - -Nicely done! In your testing for Block you should include testing for things such as invalid dates at the Block class level because the class might be reused elsewhere. - -Also in your testing, what about when you try to reserve a room with an invalid room #? Good edge case testing to see if you can reserve a room on the day someone is checking out. - -For testing the uniqueness of the block booking you can make a hash of all the booking IDs and loop through counting how often they occur as the value. Then if all the values are 1, they're unique. Because they're random there's no way to verify it 100%, but you could run the test several times. - -For returns 17 rooms when there are three room conflicts you can also just verify that the available rooms don't include the rooms in the specific reservations. Overall you did really really well. The design was good, although as you noted, not perfect. You also did a very through job testing.