From b6a2590b46ff2972d343ba296d46b50dadb23bb1 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Tue, 5 Sep 2017 14:00:25 -0700 Subject: [PATCH 01/14] initial commit, setting up Rakefile amnd spec_helper --- .DS_Store | Bin 0 -> 6148 bytes Rakefile | 11 +++++++++++ lib/reservation.rb | 16 ++++++++++++++++ lib/room.rb | 8 ++++++++ specs/.DS_Store | Bin 0 -> 6148 bytes specs/reservation_spec.rb | 0 specs/room_spec.rb | 0 specs/spec_helper.rb | 12 ++++++++++++ 8 files changed, 47 insertions(+) create mode 100644 .DS_Store create mode 100644 Rakefile create mode 100644 lib/reservation.rb create mode 100644 lib/room.rb create mode 100644 specs/.DS_Store create mode 100644 specs/reservation_spec.rb create mode 100644 specs/room_spec.rb create mode 100644 specs/spec_helper.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..717b739a26e4c304abe5e2725dabe4aa45f8510c GIT binary patch literal 6148 zcmeHKL2lDP6#dhrU{fKoKx&uXRO+HasYu%eLNXy;bb*8#1dD=NJ9ep6*AvAK5riOb zI0PI3sYmGvI0L6BZ)SdxlQdg|%KYfh`!n@eq+{52G!j1`#=Mh4p(VZZOra ze9o4*#RUpIMo0nm=!_oG`5fCeSOu&C|C$2o-Cdy*it&r6`u;}ysqBTR48c&_!xQ+% zl{Q2~HA*R=aE5hpGb}k>Md;ZvzNhIVe1o>M z3RnfE6{wkNL!JM7i|_x_Nw#JcunOEN1w_5m?XY5PhR50*VA|EVr~0tZj}E3u}Ks^rB$k^yK`g@9+5g`~mvr!(ifp*oeqX zn0=GknVq`_x4Q#CrcYPLzy!dUswip|8 zLp9}fBUkIDBm>DnGLQ@;13zPcXST|C$1%rbAQ?yoRt)I=P^gMkVDD&K2M22bh$Fg9 zXzS%zb4p+p*gJBDBA!b0REZWtJe~d$aaCaN=;@GXJ|rrCG%sS+xqh*5NadJgGLQ_c zGoZaMWuoW*DLmZJ}OJRWz Date: Tue, 5 Sep 2017 14:03:44 -0700 Subject: [PATCH 02/14] adding require relative spec helper to specs --- specs/reservation_spec.rb | 1 + specs/room_spec.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index e69de29bb..ae9c220ea 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' diff --git a/specs/room_spec.rb b/specs/room_spec.rb index e69de29bb..ae9c220ea 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' From 0a42ac3c1d0295ad6beb6fa5d6947e56314dd40c Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Tue, 5 Sep 2017 14:30:15 -0700 Subject: [PATCH 03/14] added instructions in comments --- lib/reservation.rb | 2 +- lib/room.rb | 9 ++++++++- specs/room_spec.rb | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 6a6ca55e7..503a96f03 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,7 +1,7 @@ require_relative module Hotel - class Reservation + class Room reservation_hash = { num_guests: 0, check_in_date: Date, diff --git a/lib/room.rb b/lib/room.rb index 132253017..8a9e9b3fc 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,7 +1,14 @@ require_relative +# The hotel has 20 rooms, and they are numbered 1 through 20 +# Every room is identical, and a room always costs $200/night +# The last day of a reservation is the checkout day, +# so the guest should not be charged for that night +# For this wave, any room can be reserved at any time, +# and you don't need to check whether reservations +# conflict with each other (this will come in wave 2!) module Hotel - class Reservation + class Room end diff --git a/specs/room_spec.rb b/specs/room_spec.rb index ae9c220ea..9b7cd9c23 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1 +1,4 @@ require_relative 'spec_helper' + +# Your code should raise an error +# when an invalid date range is provided From ab62f2bf2b4f5fafeac947c01cc4dabe67974b9a Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Tue, 5 Sep 2017 15:28:47 -0700 Subject: [PATCH 04/14] added an outline of tests --- lib/reservation.rb | 36 +++++++++++++++------ lib/room.rb | 3 +- specs/room_spec.rb | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 10 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 503a96f03..47111ed22 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,15 +1,33 @@ require_relative +reservation_hash = { + num_guests: 0, + check_in_date: Date, + num_nights: 0, + room_nums: [], + res_name: "", + total_price: 0 +} + +def self.all(rooms) + rooms.each do |room| + + end +end + + def self.find + end + +# I can access the list of all of the rooms in the hotel +# I can reserve a room for a given date range +# I can access the list of reservations for a specific date +# I can get the total cost for a given reservation + + module Hotel - class Room - reservation_hash = { - num_guests: 0, - check_in_date: Date, - num_nights: 0, - room_nums: [], - res_name: "", - total_price: 0 - } + class Reservation + + # @max_occupants = 2 ??? end diff --git a/lib/room.rb b/lib/room.rb index 8a9e9b3fc..5b9717f82 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -9,7 +9,8 @@ module Hotel class Room - + @room_number = room_number + @room_price = 200 end end diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 9b7cd9c23..427609e34 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -2,3 +2,83 @@ # Your code should raise an error # when an invalid date range is provided + +describe 'Room' + +it "there should be 20 total rooms" do + +end + +it "can access the list of all of the rooms in the hotel" do + +end + + +it "can reserve a room for a given date range" do + +end + +it "can access the list of reservations for a specific date" do + +end + +it "I can get the total cost for a given reservation" do + +end + +it "room always costs $200/night" do + +end + +it "last day of a reservation is the checkout day, so the guest should not be charged for that night" do + +end + +it "Your code should raise an error when an invalid date range is provided" do + +end + + +it "I can view a list of rooms that are not reserved for a given date range" do + +end +it "I can reserve an available room for a given date range" do + +end + +it "Your code should raise an exception when asked to reserve a room that is not available" do + +end + +it " I can create a block of rooms:"do + +end +# need a date range, collection of rooms and a discounted room rate +it "block should only include rooms that are available for the given date range" do + +end +it "a room is set aside in a block, it is not available for reservation by the general public, nor can it be included in another block" do + +end +it "a room is set aside in a block it can't be included in another block" do + +end +it "can check whether a given block has any rooms available" do + +end + +it "can reserve a room from within a block of rooms" do + +end + +it "A block can contain a maximum of 5 rooms" do + +end + +it "When a room is reserved from a block of rooms, the reservation dates will always match the date range of the block" do + +end + +it "All of the availability checking logic from Wave 2 should now respect room blocks as well as individual reservations" do + +end From 452b95e91d3238da8f204ef0cba5adca108d3c0f Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Tue, 5 Sep 2017 22:16:52 -0700 Subject: [PATCH 05/14] rake file finally works and experimenting making a Hotel class, instead of Room class. --- lib/reservation.rb | 6 +----- lib/room.rb | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 47111ed22..f8bd9aff9 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,4 +1,4 @@ -require_relative +# require_relative reservation_hash = { num_guests: 0, @@ -9,11 +9,7 @@ total_price: 0 } -def self.all(rooms) - rooms.each do |room| - end -end def self.find end diff --git a/lib/room.rb b/lib/room.rb index 5b9717f82..56613b6d2 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,4 +1,4 @@ -require_relative +# require_relative # The hotel has 20 rooms, and they are numbered 1 through 20 # Every room is identical, and a room always costs $200/night # The last day of a reservation is the checkout day, @@ -8,9 +8,18 @@ # conflict with each other (this will come in wave 2!) module Hotel - class Room - @room_number = room_number - @room_price = 200 - end + class Hotel + + attr_reader :rooms, :room_price + + def initialize + @rooms = (1..20).to_a + @room_price = 200 + end + + end end + +hotel = Hotel::Hotel.new +p hotel.rooms From a776b8c07f814d468f5f88222c286830b4fb7ed1 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Tue, 5 Sep 2017 22:18:42 -0700 Subject: [PATCH 06/14] require_relative for lib added --- specs/.DS_Store | Bin 6148 -> 6201 bytes specs/reservation_spec.rb | 21 +++++++++++++++++++++ specs/room_spec.rb | 5 +++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/specs/.DS_Store b/specs/.DS_Store index 89792a9f8082165bf2b284a51a3fdab70aee9bcf..785b8ddd474799bcc69f26605cf51a7799bbd764 100644 GIT binary patch delta 159 zcmZoM*lDoAi&5zP{=H~uasZ>QBv6cjfk6XJ3do(@!DxtEcJoC>Gq#BhyqnoMOjwvf j%58Y8z;uI%9f;n%U&NJpVgt`+b^%+60#^}C1&mw(V$f44 delta 97 zcmdmK&|wj Date: Thu, 7 Sep 2017 10:36:10 -0700 Subject: [PATCH 07/14] added more classes and renamed --- .DS_Store | Bin 6148 -> 6148 bytes lib/block.rb | 24 +++++++++++ lib/{room.rb => hotel.rb} | 12 ++++-- lib/range.rb | 39 +++++++++++++++++ lib/reservation.rb | 35 ++++++++------- specs/{room_spec.rb => hotel_spec.rb} | 20 ++++++--- specs/range_spec.rb | 60 ++++++++++++++++++++++++++ specs/spec_helper.rb | 4 +- 8 files changed, 165 insertions(+), 29 deletions(-) create mode 100644 lib/block.rb rename lib/{room.rb => hotel.rb} (67%) create mode 100644 lib/range.rb rename specs/{room_spec.rb => hotel_spec.rb} (86%) create mode 100644 specs/range_spec.rb diff --git a/.DS_Store b/.DS_Store index 717b739a26e4c304abe5e2725dabe4aa45f8510c..f839ed23e4db1a7d61ad142d624490629de75d98 100644 GIT binary patch delta 184 zcmZoMXfc@JFUrHfz`)4BAi%(o&7j9n#E|5flb^gB1npZA&DV}A)g@`Svn~v zKM5!Y)Wi50NNfBD10V~eJ{hRGj3E_hR3bwV{ date.check_out || + @check_in < date.check_in && @check_out < date.check_out + return false + else + return true + end + end + + def num_nights + return @check_out - @check_in + end + + end +end diff --git a/lib/reservation.rb b/lib/reservation.rb index f8bd9aff9..052364bf4 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,18 +1,4 @@ -# require_relative - -reservation_hash = { - num_guests: 0, - check_in_date: Date, - num_nights: 0, - room_nums: [], - res_name: "", - total_price: 0 -} - - - - def self.find - end +require_relative 'range' # I can access the list of all of the rooms in the hotel # I can reserve a room for a given date range @@ -20,10 +6,23 @@ def self.find # I can get the total cost for a given reservation -module Hotel - class Reservation +module Property + + class Reservation < Range + + + def initialize(room, check_in, check_out, total_price) + @room = room + @total_price = (@check_out - @check_in) * 200 + # super(check_in, check_out) + @dates = Property::Range.new(check_in, check_out) + end - # @max_occupants = 2 ??? + def reserve(room,check_in,check_out) + reservation = Reservation.new(room, checkin, checkout, @room_price) + @reserved_rooms << reservation + return reservation + end end diff --git a/specs/room_spec.rb b/specs/hotel_spec.rb similarity index 86% rename from specs/room_spec.rb rename to specs/hotel_spec.rb index 925829f58..5ddbf50e4 100644 --- a/specs/room_spec.rb +++ b/specs/hotel_spec.rb @@ -1,17 +1,25 @@ require_relative 'spec_helper' -require_relative '../lib/room' -# Your code should raise an error -# when an invalid date range is provided +require_relative '../lib/hotel' -describe 'Room' do +describe 'Hotel' do + +before do + @test_hotel = Property::Hotel.new +end + +it "can access the list of all of the rooms in the hotel" do +@test_hotel.rooms.must_equal (1..20).to_a +end it "there should be 20 total rooms" do + @test_hotel.rooms.count.must_equal 20 +end +it "room always costs $200/night" do +@test_hotel.room_price.must_equal 200 end -it "can access the list of all of the rooms in the hotel" do -end it "can reserve a room for a given date range" do diff --git a/specs/range_spec.rb b/specs/range_spec.rb new file mode 100644 index 000000000..d852b4c67 --- /dev/null +++ b/specs/range_spec.rb @@ -0,0 +1,60 @@ +require_relative 'spec_helper' +require_relative '../lib/range' + +describe 'Range' do + + it 'Can initialize check in and check out' do + check_in = Date.new(2017, 02, 01) + check_out = check_in + 2 + range = Property::Range.new(check_in, check_out) + range.check_in.must_equal check_in + range.check_out.must_equal check_out + end + +end + +describe "valid?" do + + it "cannot have a negative date range" do + check_in = Date.new(2017, 02, 01) + check_out = check_in - 5 + proc {Property::Range.new(check_in, check_out).valid?}.must_raise ArgumentError + end + + it "date range must not be 0" do + check_in = Date.new(2017, 02, 01) + check_out = check_in + proc {Property::Range.new(check_in, check_out).valid?}.must_raise ArgumentError + end + + it "returns true for valid date range " do + check_in = Date.new(2017, 02, 01) + check_out = check_in + 5 + @range = Property::Range.new(check_in, check_out) + @range.valid?.must_equal true + end + +end + +describe 'overlap?' do + + before do + check_in = Date.new(2017, 02, 01) + check_out = check_in + 3 + @range = Property::Range.new(check_in, check_out) + end + + it "returns true for date range that overlaps" do + check_in = Date.new(2017, 02, 01) + check_out = check_in + 3 + other_range = Property::Range.new(check_in, check_out) + @range.overlap?(other_range).must_equal true + end + + it "returns false for date range that doesn't overlap" do + check_in = Date.new(2017, 05, 05) + check_out = check_in + 3 + other_range = Property::Range.new(check_in, check_out) + @range.overlap?(other_range).must_equal false + end +end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 9701f8dab..9519d638d 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -9,4 +9,6 @@ require 'date' require_relative '../lib/reservation' -require_relative '../lib/room' +require_relative '../lib/hotel' +require_relative '../lib/range' +# require_relative '../lib/block' From 074390eee023b640c27768a00f019d79c1962491 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Fri, 8 Sep 2017 15:13:47 -0700 Subject: [PATCH 08/14] added a bunch of functionality, only range passes tests --- lib/block.rb | 41 +++++++++++++++++++++---------- lib/hotel.rb | 45 +++++++++++++++++++++++++++++----- lib/range.rb | 4 +-- lib/reservation.rb | 19 ++++---------- specs/hotel_spec.rb | 8 +++--- specs/range_spec.rb | 60 +++++++++++++++++++++++++++++++++------------ 6 files changed, 121 insertions(+), 56 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 2288d7d17..c2555c3ec 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -1,24 +1,39 @@ module Property - class Blocks < Reservation + class Block + # make sure to uncomment block in spec helper - attr_reader :rooms, :room_price, :check_in, :check_out + attr_reader :rooms, :check_in, :check_out, :price - def initialize - @rooms = [] - @reserved_blocks = [] - @block_price = block_total - super(check_in, check_out) - end + def initialize(rooms,check_in,check_out,price) + raise ArgumentError.new "Cannot accomodate block reservation + for more than five rooms at a time." if rooms.length > 5 + raise ArgumentError.new "Must specify at least one room." if rooms.empty? - def block_total - return ((@check_out - @check_in) * 200 * @rooms.length) - end + @availability = rooms.clone + @rooms = [] + @dates = Property::Range.new(check_in, check_out) + @price = 200 + @total_price = @dates.num_nights * @price * @rooms.length + end + + def reserve_individual_room(room) + raise ArgumentError.new "No availability" if @availability.empty? + @vailability.pop(room) + @availability << room + retun room + end + end end -end -make sure to uncomment block in spec helper + + # block = { + # rooms => [], + # check_in => check_in, + # check_out => check_out, + # total_price => ((rooms.length * 200)*(check_out - check_in)) + # } diff --git a/lib/hotel.rb b/lib/hotel.rb index 47a502b86..59003d46d 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,4 +1,5 @@ -# require_relative +require_relative 'reservation' +require_relative 'block' # The hotel has 20 rooms, and they are numbered 1 through 20 # Every room is identical, and a room always costs $200/night # The last day of a reservation is the checkout day, @@ -16,14 +17,46 @@ class Hotel def initialize @rooms = (1..20).to_a @room_price = 200 - @reserved_rooms = [] #reservations + @reservations = [] @reserved_blocks = [] end end end -def reserve(room,check_in,check_out) - reservation = Property::Reservation.new(room, checkin, checkout, @room_price) - @reserved_rooms << reservation - return reservation +def available_rooms(check_in, check_out) + dates = Property::Range.new(check_in, check_out) + available_rooms = @rooms +end + +def reserve_room(room,check_in,check_out) + raise ArgumentError.new "Room unavailable." unless @rooms.include? room + raise ArgumentError.new "Room #{room}is booked between + #{check_in} and #{check_out}" unless available_rooms(check_in, check_out).include? room + + room_rez = Property::Reservation.new(room, checkin, checkout,@room_price) + @rooms.pop(room) + @reservations << room_rez + return room_rez +end + +def reserve_block(room_qty, check_in, check_out, price) + rooms = availability(check_in, check_out) + + raise ArgumentError "Insufficient room availability" if @rooms.length < room_qty + + block_rez = Property::Block.new(room_qty.first(rooms), check_in, check_out, price) + # rooms.each do |room| + # @availability.pop(room) + # end + @reserved_blocks << block_rez + return block_rez +end + +def list_reservations(date) + @reservations.select { |rez| rez.contains(date) } +end + +def reserve_from_block(block_rez) + room = block_rez.reserve_individual_room + room_rez = Reservation.new(room, block_rez.checkin, block_rez.checkout, block_rez.total_price) end diff --git a/lib/range.rb b/lib/range.rb index 830cde25d..60eb37288 100644 --- a/lib/range.rb +++ b/lib/range.rb @@ -1,5 +1,4 @@ require 'date' -require 'range_operators' module Property @@ -8,9 +7,10 @@ class Range def initialize(check_in, check_out) - unless @check_in < @check_out + unless check_in < check_out raise ArgumentError.new "Invalid date range" #return true ? end + @check_in = check_in @check_out = check_out end diff --git a/lib/reservation.rb b/lib/reservation.rb index 052364bf4..b97133449 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,6 +1,5 @@ require_relative 'range' -# I can access the list of all of the rooms in the hotel # I can reserve a room for a given date range # I can access the list of reservations for a specific date # I can get the total cost for a given reservation @@ -8,22 +7,14 @@ module Property - class Reservation < Range + class Reservation - def initialize(room, check_in, check_out, total_price) - @room = room - @total_price = (@check_out - @check_in) * 200 - # super(check_in, check_out) + def initialize(block) + @rooms = [] @dates = Property::Range.new(check_in, check_out) + @total_price = @dates.num_nights * 200 + # super(check_in, check_out) end - - def reserve(room,check_in,check_out) - reservation = Reservation.new(room, checkin, checkout, @room_price) - @reserved_rooms << reservation - return reservation - end - - end end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 5ddbf50e4..490379714 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -2,7 +2,7 @@ require_relative '../lib/hotel' describe 'Hotel' do - + before do @test_hotel = Property::Hotel.new end @@ -42,14 +42,11 @@ end -it "Your code should raise an error when an invalid date range is provided" do - -end - it "I can view a list of rooms that are not reserved for a given date range" do end + it "I can reserve an available room for a given date range" do end @@ -61,6 +58,7 @@ it " I can create a block of rooms:"do end + # need a date range, collection of rooms and a discounted room rate it "block should only include rooms that are available for the given date range" do diff --git a/specs/range_spec.rb b/specs/range_spec.rb index d852b4c67..a51a970b7 100644 --- a/specs/range_spec.rb +++ b/specs/range_spec.rb @@ -1,6 +1,7 @@ require_relative 'spec_helper' require_relative '../lib/range' + describe 'Range' do it 'Can initialize check in and check out' do @@ -11,50 +12,77 @@ range.check_out.must_equal check_out end -end - -describe "valid?" do - it "cannot have a negative date range" do check_in = Date.new(2017, 02, 01) check_out = check_in - 5 - proc {Property::Range.new(check_in, check_out).valid?}.must_raise ArgumentError + proc {Property::Range.new(check_in, check_out)}.must_raise ArgumentError end it "date range must not be 0" do check_in = Date.new(2017, 02, 01) check_out = check_in - proc {Property::Range.new(check_in, check_out).valid?}.must_raise ArgumentError + proc {Property::Range.new(check_in, check_out)}.must_raise ArgumentError end - it "returns true for valid date range " do - check_in = Date.new(2017, 02, 01) - check_out = check_in + 5 - @range = Property::Range.new(check_in, check_out) - @range.valid?.must_equal true - end + # it "returns true for valid date range " do + # check_in = Date.new(2017, 02, 01) + # check_out = check_in + 5 + # @range = Property::Range.new(check_in, check_out) + # @range.valid?must_equal true + # end end describe 'overlap?' do before do - check_in = Date.new(2017, 02, 01) + check_in = Date.new(2017, 2, 1) check_out = check_in + 3 @range = Property::Range.new(check_in, check_out) end - it "returns true for date range that overlaps" do - check_in = Date.new(2017, 02, 01) + it "returns true for date range that overlaps neatly" do + check_in = Date.new(2017, 2, 1) check_out = check_in + 3 other_range = Property::Range.new(check_in, check_out) @range.overlap?(other_range).must_equal true end it "returns false for date range that doesn't overlap" do - check_in = Date.new(2017, 05, 05) + check_in = Date.new(2017, 5, 5) check_out = check_in + 3 other_range = Property::Range.new(check_in, check_out) @range.overlap?(other_range).must_equal false end + + it "returns true for date range that overlaps for shorter reservations" do + check_in = Date.new(2017, 2, 1) + check_out = check_in + 1 + other_range = Property::Range.new(check_in, check_out) + @range.overlap?(other_range).must_equal true + end + + it "returns true for date range that overlaps for longer reservations" do + check_in = Date.new(2017, 2, 1) + check_out = check_in + 27 + other_range = Property::Range.new(check_in, check_out) + @range.overlap?(other_range).must_equal true + end + +end + +describe 'num_nights' do + + it "returns the correct number of nights booked" do + check_in = Date.new(2017, 5, 5) + check_out = Date.new(2017, 5, 8) + range = Property::Range.new(check_in, check_out) + range.num_nights.must_equal 3 + end + it "error for 0 nights" do + check_in = Date.new(2017, 5, 5) + check_out = check_in + proc {Property::Range.new(check_in, check_out)}.must_raise ArgumentError + end + end From dd2073e319b538201f13f31872f8bea52bffe734 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Fri, 8 Sep 2017 15:20:26 -0700 Subject: [PATCH 09/14] added one more test for range --- specs/range_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/specs/range_spec.rb b/specs/range_spec.rb index a51a970b7..1618b1054 100644 --- a/specs/range_spec.rb +++ b/specs/range_spec.rb @@ -61,6 +61,12 @@ other_range = Property::Range.new(check_in, check_out) @range.overlap?(other_range).must_equal true end + it "returns true for date range that overlaps for reservation with much earlier check in date" do + check_in = Date.new(2017, 1, 1) + check_out = Date.new(2017, 2, 2) + other_range = Property::Range.new(check_in, check_out) + @range.overlap?(other_range).must_equal true + end it "returns true for date range that overlaps for longer reservations" do check_in = Date.new(2017, 2, 1) @@ -79,6 +85,7 @@ range = Property::Range.new(check_in, check_out) range.num_nights.must_equal 3 end + it "error for 0 nights" do check_in = Date.new(2017, 5, 5) check_out = check_in From b6fbed7b364c3fe37a0dcabe8537ce8d52511759 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Fri, 8 Sep 2017 20:43:31 -0700 Subject: [PATCH 10/14] made Range a superclass, was unable to call on range otherwise --- lib/hotel.rb | 86 +++++++++++++++++++-------------------- lib/reservation.rb | 23 ++++++----- specs/block_spec.rb | 0 specs/hotel_spec.rb | 68 +++++++++++++++++++++++-------- specs/reservation_spec.rb | 45 +++++++++++--------- 5 files changed, 130 insertions(+), 92 deletions(-) create mode 100644 specs/block_spec.rb diff --git a/lib/hotel.rb b/lib/hotel.rb index 59003d46d..0dfc5c1ff 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,62 +1,62 @@ require_relative 'reservation' -require_relative 'block' -# The hotel has 20 rooms, and they are numbered 1 through 20 -# Every room is identical, and a room always costs $200/night -# The last day of a reservation is the checkout day, -# so the guest should not be charged for that night -# For this wave, any room can be reserved at any time, -# and you don't need to check whether reservations -# conflict with each other (this will come in wave 2!) module Property class Hotel - attr_reader :rooms, :room_price + attr_reader :reservations, :rooms, :room_price def initialize @rooms = (1..20).to_a @room_price = 200 @reservations = [] @reserved_blocks = [] + # @available = [] end - end -end - -def available_rooms(check_in, check_out) - dates = Property::Range.new(check_in, check_out) - available_rooms = @rooms -end - -def reserve_room(room,check_in,check_out) - raise ArgumentError.new "Room unavailable." unless @rooms.include? room - raise ArgumentError.new "Room #{room}is booked between - #{check_in} and #{check_out}" unless available_rooms(check_in, check_out).include? room - - room_rez = Property::Reservation.new(room, checkin, checkout,@room_price) - @rooms.pop(room) - @reservations << room_rez - return room_rez -end -def reserve_block(room_qty, check_in, check_out, price) - rooms = availability(check_in, check_out) + def available(checkin, checkout) + dates = Range.new(checkin, checkout) + available = @rooms + overlap = @reservations.select do |rez| + rez.overlap?(dates) + end + already_reserved = overlap.map do |rez| + rez.room + end + available -= already_reserved + return available + end - raise ArgumentError "Insufficient room availability" if @rooms.length < room_qty - block_rez = Property::Block.new(room_qty.first(rooms), check_in, check_out, price) - # rooms.each do |room| - # @availability.pop(room) - # end - @reserved_blocks << block_rez - return block_rez -end + def reserve_room(room, check_in, check_out) + raise ArgumentError.new "Room unavailable." unless @rooms.include? room + raise ArgumentError.new "Room #{room}is booked between + # #{check_in} and #{check_out}" unless available(check_in, check_out).include? room + room_rez = Reservation.new(room, check_in, check_out, @room_price) + @reservations << room_rez + return room_rez + end -def list_reservations(date) - @reservations.select { |rez| rez.contains(date) } -end + # def reserve_block(room_qty, check_in, check_out, price) + # rooms = availability(check_in, check_out) + # + # raise ArgumentError "Insufficient room availability" if @rooms.length < room_qty + # + # block_rez = Property::Block.new(room_qty.first(rooms), check_in, check_out, price) + # # rooms.each do |room| + # # @availability.pop(room) + # # end + # @reserved_blocks << block_rez + # return block_rez + # end + + def list_reservations(date) + return @reservations.select { |rez| rez.contains(date) } + end -def reserve_from_block(block_rez) - room = block_rez.reserve_individual_room - room_rez = Reservation.new(room, block_rez.checkin, block_rez.checkout, block_rez.total_price) + # def reserve_from_block(block_rez) + # room = block_rez.reserve_individual_room + # room_rez = Reservation.new(room, block_rez.checkin, block_rez.checkout, block_rez.price) + # end + end end diff --git a/lib/reservation.rb b/lib/reservation.rb index b97133449..c2a202b8c 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,20 +1,21 @@ require_relative 'range' -# I can reserve a room for a given date range -# I can access the list of reservations for a specific date -# I can get the total cost for a given reservation - - module Property - class Reservation + class Reservation < Range + attr_reader :room, :price + + def initialize(room, check_in, check_out, price) + @room = room + @price = 200 + # @dates = Property::Range.new(check_in, check_out) + # @total_price = @dates.num_nights * 200 + super(check_in, check_out) + end - def initialize(block) - @rooms = [] - @dates = Property::Range.new(check_in, check_out) - @total_price = @dates.num_nights * 200 - # super(check_in, check_out) + def total_price + return num_nights * @price end end end diff --git a/specs/block_spec.rb b/specs/block_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 490379714..6cba27458 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -3,24 +3,56 @@ describe 'Hotel' do -before do - @test_hotel = Property::Hotel.new -end - -it "can access the list of all of the rooms in the hotel" do -@test_hotel.rooms.must_equal (1..20).to_a -end - -it "there should be 20 total rooms" do - @test_hotel.rooms.count.must_equal 20 -end - -it "room always costs $200/night" do -@test_hotel.room_price.must_equal 200 -end - - - + before do + @test_hotel = Property::Hotel.new + end + + it "can be initialized" do + @test_hotel.must_be_instance_of Property::Hotel + end + it "responds to its attr_reader" do + @test_hotel.must_respond_to :reservations + @test_hotel.must_respond_to :rooms + @test_hotel.must_respond_to :room_price + end + + it "can access the list of all of the rooms in the hotel" do + @test_hotel.rooms.must_equal (1..20).to_a + end + + it "there should be 20 total rooms" do + @test_hotel.rooms.count.must_equal 20 + end + + it "room always costs $200/night" do + @test_hotel.room_price.must_equal 200 + end +end + +describe "reserve_room" do + + before do + @test_hotel = Property::Hotel.new + @check_in = Date.new(2017, 05, 05) + @check_out = @check_in + 3 + end + + + it "cannot book invalid room number" do + room = "garbage" + proc {@test_hotel.reserve_room(room, @check_in, @check_out)}.must_raise ArgumentError + end + + it "raises an error if tried to double-book room " do + room = 5 + @test_hotel.reserve_room(room, @check_in, @check_out) + proc {@test_hotel.reserve_room(room, @check_in, @check_out)}.must_raise ArgumentError + end + + it "adds the reservation to @reservations" do + test_rez = @test_hotel.reserve_room(10, @check_in, @check_out) + @test_hotel.reservations.must_include test_rez + end it "can reserve a room for a given date range" do diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 211d21f1e..51c360670 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1,22 +1,27 @@ require_relative 'spec_helper' require_relative '../lib/reservation' -# Used git regularly | -# Answer comprehension questions | -# Each class is responsible for a single piece of the program | -# Classes are loosely coupled -# List rooms | -# Reserve a room for a given date range | -# List reservations for a given date | -# Calculate reservation price | -# Invalid date range produces an error | -# Test coverage -# -# View available rooms for a given date range | -# Reserving a room that is not available produces an error | -# Test coverage -# -# -# Create a block of rooms | -# Check if a block has rooms | -# Reserve a room from a block | -# Test coverage + +describe 'Reservation' do + before do + + @room = 2 + @checkin = Date.new(2017, 5, 5) + @checkout = @checkin + 3 + @price = 200 + @test_rez = Property::Reservation.new(@room, @checkin, @checkout, @price) + end + + it " responds to attr reader" do + @test_rez.must_respond_to :room + @test_rez.must_respond_to :price + end + + it "is a subclass of Range" do + @test_rez.must_be_kind_of Property::Range + end + + it "calculates correct total" do + @test_rez.total_price.must_equal 600 + end + +end From 4a9a068ceb5db0d4fccd82e04d67d670e2603ef5 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sat, 9 Sep 2017 17:30:03 -0700 Subject: [PATCH 11/14] learned to add custom InvalidDateRange error --- lib/range.rb | 6 ++++-- specs/range_spec.rb | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/range.rb b/lib/range.rb index 60eb37288..b3305860c 100644 --- a/lib/range.rb +++ b/lib/range.rb @@ -3,12 +3,15 @@ module Property class Range + + class InvalidDateRange < StandardError ; end + attr_reader :check_in, :check_out def initialize(check_in, check_out) unless check_in < check_out - raise ArgumentError.new "Invalid date range" #return true ? + raise InvalidDateRange.new("Invalid date range") #return true ? end @check_in = check_in @@ -34,6 +37,5 @@ def overlap?(date) def num_nights return @check_out - @check_in end - end end diff --git a/specs/range_spec.rb b/specs/range_spec.rb index 1618b1054..6358fb1bc 100644 --- a/specs/range_spec.rb +++ b/specs/range_spec.rb @@ -15,13 +15,13 @@ it "cannot have a negative date range" do check_in = Date.new(2017, 02, 01) check_out = check_in - 5 - proc {Property::Range.new(check_in, check_out)}.must_raise ArgumentError + proc {Property::Range.new(check_in, check_out)}.must_raise Property::Range::InvalidDateRange end it "date range must not be 0" do check_in = Date.new(2017, 02, 01) check_out = check_in - proc {Property::Range.new(check_in, check_out)}.must_raise ArgumentError + proc {Property::Range.new(check_in, check_out)}.must_raise Property::Range::InvalidDateRange end # it "returns true for valid date range " do @@ -89,7 +89,7 @@ it "error for 0 nights" do check_in = Date.new(2017, 5, 5) check_out = check_in - proc {Property::Range.new(check_in, check_out)}.must_raise ArgumentError + proc {Property::Range.new(check_in, check_out)}.must_raise Property::Range::InvalidDateRange end end From 4388bd3ae61e932f5f6ac2d28fd113d3d7d265e8 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sun, 10 Sep 2017 22:34:46 -0700 Subject: [PATCH 12/14] added block functonality --- lib/block.rb | 38 ++++++--------- lib/hotel.rb | 46 ++++++++++-------- lib/range.rb | 2 +- specs/block_spec.rb | 40 +++++++++++++++ specs/hotel_spec.rb | 113 +++++++++++++++---------------------------- specs/spec_helper.rb | 2 +- 6 files changed, 122 insertions(+), 119 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index c2555c3ec..01fe2f16d 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -1,39 +1,31 @@ module Property - class Block - # make sure to uncomment block in spec helper + class Block < Range - attr_reader :rooms, :check_in, :check_out, :price + attr_reader :rooms, :price, :availability, :reservations - def initialize(rooms,check_in,check_out,price) + def initialize(rooms, check_in, check_out, price) raise ArgumentError.new "Cannot accomodate block reservation for more than five rooms at a time." if rooms.length > 5 - raise ArgumentError.new "Must specify at least one room." if rooms.empty? - - @availability = rooms.clone + super(check_in, check_out) @rooms = [] - @dates = Property::Range.new(check_in, check_out) - @price = 200 - @total_price = @dates.num_nights * @price * @rooms.length + @available = rooms.clone + @reservations = [] + @price = price #discounted end - def reserve_individual_room(room) + def reserve_block(room) raise ArgumentError.new "No availability" if @availability.empty? - @vailability.pop(room) - @availability << room - retun room + reservation = @available.pop(room) + @reservations << reservation + return reservation + end + + def block_price + return @rooms.length * num_nights * @price end end end - - - - # block = { - # rooms => [], - # check_in => check_in, - # check_out => check_out, - # total_price => ((rooms.length * 200)*(check_out - check_in)) - # } diff --git a/lib/hotel.rb b/lib/hotel.rb index 0dfc5c1ff..b648fc743 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,5 +1,5 @@ require_relative 'reservation' - +require_relative 'block' module Property class Hotel @@ -26,7 +26,13 @@ def available(checkin, checkout) available -= already_reserved return available end - + # pseudo : def no_check_in_on_same_day_as_check_out(room) + # for room's check out date + # do not allow check_in date to start on same day + # for that room + # use overlap? to control for this? + # make sure adjusting availability doesn;t affect the price + # end def reserve_room(room, check_in, check_out) raise ArgumentError.new "Room unavailable." unless @rooms.include? room @@ -37,26 +43,26 @@ def reserve_room(room, check_in, check_out) return room_rez end - # def reserve_block(room_qty, check_in, check_out, price) - # rooms = availability(check_in, check_out) - # - # raise ArgumentError "Insufficient room availability" if @rooms.length < room_qty - # - # block_rez = Property::Block.new(room_qty.first(rooms), check_in, check_out, price) - # # rooms.each do |room| - # # @availability.pop(room) - # # end - # @reserved_blocks << block_rez - # return block_rez - # end - - def list_reservations(date) + def reserve_block(room_qty, check_in, check_out, price) + rooms = availability(check_in, check_out) + + raise ArgumentError "Insufficient room availability" if @rooms.length < room_qty + + block_rez = Property::Block.new(room_qty.first(rooms), check_in, check_out, price) + rooms.each do |room| + @availability.pop(room) + end + @reserved_blocks << block_rez + return block_rez + end + + def list_rez(date) return @reservations.select { |rez| rez.contains(date) } end - # def reserve_from_block(block_rez) - # room = block_rez.reserve_individual_room - # room_rez = Reservation.new(room, block_rez.checkin, block_rez.checkout, block_rez.price) - # end + def reserve_from_block(block_rez) + room = block_rez.reserve_individual_room + room_rez = Reservation.new(room, block_rez.check_in, block_rez.check_out, block_rez.price) + end end end diff --git a/lib/range.rb b/lib/range.rb index b3305860c..0f390627c 100644 --- a/lib/range.rb +++ b/lib/range.rb @@ -4,7 +4,7 @@ module Property class Range - class InvalidDateRange < StandardError ; end + class InvalidDateRange < StandardError ; end attr_reader :check_in, :check_out diff --git a/specs/block_spec.rb b/specs/block_spec.rb index e69de29bb..01d848677 100644 --- a/specs/block_spec.rb +++ b/specs/block_spec.rb @@ -0,0 +1,40 @@ +require_relative 'spec_helper' +require_relative '../lib/block' + +describe 'Block' do + + before do + @check_in = Date.new(2017, 5, 5) + @check_out = @check_in + 3 + @price = 150 + end + + it "block is a subclass of Range"do + @rooms = [5, 12, 15] + @reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price) + @reserved_block.must_be_kind_of Property::Range + end + +it "A block can contain a maximum of 5 rooms" do + @rooms = [1, 2, 3, 4, 5, 6] + proc {@reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price)}.must_raise ArgumentError +end + +it "block should only include rooms that are available for the given date range" do + @rooms = [1, 2, 3] + @reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price) +end + +it "a room is set aside in a block, it is not available for reservation by the general public, nor can it be included in another block" do + +end + +# it "can reserve a room from within a block of rooms" do +# +# end +# +# +# it "When a room is reserved from a block of rooms, the reservation dates will always match the date range of the block" do +# +# end +end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 6cba27458..2c5e486ae 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -29,7 +29,7 @@ end end -describe "reserve_room" do + describe "reserve_room" do before do @test_hotel = Property::Hotel.new @@ -43,81 +43,46 @@ proc {@test_hotel.reserve_room(room, @check_in, @check_out)}.must_raise ArgumentError end - it "raises an error if tried to double-book room " do - room = 5 - @test_hotel.reserve_room(room, @check_in, @check_out) - proc {@test_hotel.reserve_room(room, @check_in, @check_out)}.must_raise ArgumentError - end - - it "adds the reservation to @reservations" do - test_rez = @test_hotel.reserve_room(10, @check_in, @check_out) - @test_hotel.reservations.must_include test_rez - end - -it "can reserve a room for a given date range" do - -end - -it "can access the list of reservations for a specific date" do - -end - -it "I can get the total cost for a given reservation" do - -end - -it "room always costs $200/night" do - -end - -it "last day of a reservation is the checkout day, so the guest should not be charged for that night" do - -end - - -it "I can view a list of rooms that are not reserved for a given date range" do - -end - -it "I can reserve an available room for a given date range" do - -end - -it "Your code should raise an exception when asked to reserve a room that is not available" do - -end - -it " I can create a block of rooms:"do - -end - -# need a date range, collection of rooms and a discounted room rate -it "block should only include rooms that are available for the given date range" do - -end -it "a room is set aside in a block, it is not available for reservation by the general public, nor can it be included in another block" do - -end -it "a room is set aside in a block it can't be included in another block" do - -end -it "can check whether a given block has any rooms available" do - -end - -it "can reserve a room from within a block of rooms" do - -end - -it "A block can contain a maximum of 5 rooms" do + it "raises an error if tried to double-book room " do + room = 5 + @test_hotel.reserve_room(room, @check_in, @check_out) + proc {@test_hotel.reserve_room(room, @check_in, @check_out)}.must_raise ArgumentError + end -end + it "adds the reservation to @reservations" do + test_rez = @test_hotel.reserve_room(10, @check_in, @check_out) + @test_hotel.reservations.must_include test_rez + end -it "When a room is reserved from a block of rooms, the reservation dates will always match the date range of the block" do + it "can access the list of reservations for a specific date" do + rez = @test_hotel.reserve_room(15, @check_in, @check_out) + @test_hotel.reservations.must_include rez + end -end + it "I can get the total cost for a given reservation" do + rez = @test_hotel.reserve_room(20, @check_in, @check_out) + rez.total_price.must_equal 600 + end -it "All of the availability checking logic from Wave 2 should now respect room blocks as well as individual reservations" do + it "I can view a list of rooms that are not reserved for a given date range" do + rez = @test_hotel.reserve_room(3, @check_in, @check_out) + @test_hotel.available(@check_in, @check_out).include?(3).must_equal false + end -end -end + it "can book a room that is available" do + excluding_one_room = @test_hotel.reserve_room(2, @check_in, @check_out) + available_room = @test_hotel.available(@check_in, @check_out).first + booking_available_room = @test_hotel.reserve_room(available_room, @check_in, @check_out) + @test_hotel.reservations.must_include booking_available_room + @test_hotel.reservations.length.must_equal 2 + end + # it "reservation cannot be made for room when check in and checkout dates overlap" do + # rez = @test_hotel.reserve_room(3, @check_in, @check_out) + # rez2 = @test_hotel.reserve_room(3, @check_out, (@check_out+ 3)) + # @test_hotel.reservations.include?(rez2).must_equal false + # end + #this test fails. I need to strategize and decide how I'll make sure check in is + #not available on the day of check out for the same room. + #one way I am thinking of doing this is to set time, but that just introduces more + #complexity ... + end diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 9519d638d..e8d458517 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -11,4 +11,4 @@ require_relative '../lib/reservation' require_relative '../lib/hotel' require_relative '../lib/range' -# require_relative '../lib/block' +require_relative '../lib/block' From 5372753e434675a4307986f82f34cb011bb25894 Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Mon, 11 Sep 2017 01:19:09 -0700 Subject: [PATCH 13/14] final push, couldn't get blocks to work properly --- lib/block.rb | 7 +-- lib/hotel.rb | 31 +++++----- specs/block_spec.rb | 41 ++++++------- specs/hotel_spec.rb | 138 ++++++++++++++++++++++++++------------------ 4 files changed, 117 insertions(+), 100 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 01fe2f16d..148a77891 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -13,7 +13,7 @@ def initialize(rooms, check_in, check_out, price) @rooms = [] @available = rooms.clone @reservations = [] - @price = price #discounted + @price = 150 #discounted end def reserve_block(room) @@ -22,10 +22,5 @@ def reserve_block(room) @reservations << reservation return reservation end - - def block_price - return @rooms.length * num_nights * @price - end - end end diff --git a/lib/hotel.rb b/lib/hotel.rb index b648fc743..7218edbe7 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,5 +1,8 @@ require_relative 'reservation' require_relative 'block' +require_relative 'range' +require 'date' + module Property class Hotel @@ -43,26 +46,24 @@ def reserve_room(room, check_in, check_out) return room_rez end - def reserve_block(room_qty, check_in, check_out, price) - rooms = availability(check_in, check_out) + def hotel_block(room_qty, check_in, check_out, price) + rooms = available(check_in, check_out) - raise ArgumentError "Insufficient room availability" if @rooms.length < room_qty + raise ArgumentError "Insufficient room availability" if rooms.length < room_qty - block_rez = Property::Block.new(room_qty.first(rooms), check_in, check_out, price) - rooms.each do |room| - @availability.pop(room) - end - @reserved_blocks << block_rez - return block_rez + block = Property::Block.new(rooms.first(room_qty), check_in, check_out, price) + #This is how to pull out first n elements + #a = [ "q", "r", "s", "t" ] + #a.first #=> "q" + # a.first(2) #=> ["q", "r"] + @reserved_blocks << block + return block end - def list_rez(date) - return @reservations.select { |rez| rez.contains(date) } + def reserve_from_block(block) + room = block.reserve_room + room_rez = Reservation.new(room, block.check_in, block.check_out, block.price) end - def reserve_from_block(block_rez) - room = block_rez.reserve_individual_room - room_rez = Reservation.new(room, block_rez.check_in, block_rez.check_out, block_rez.price) - end end end diff --git a/specs/block_spec.rb b/specs/block_spec.rb index 01d848677..a9229a1d9 100644 --- a/specs/block_spec.rb +++ b/specs/block_spec.rb @@ -10,31 +10,26 @@ end it "block is a subclass of Range"do - @rooms = [5, 12, 15] - @reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price) - @reserved_block.must_be_kind_of Property::Range + @rooms = [5, 12, 15] + @reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price) + @reserved_block.must_be_kind_of Property::Range end -it "A block can contain a maximum of 5 rooms" do - @rooms = [1, 2, 3, 4, 5, 6] - proc {@reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price)}.must_raise ArgumentError -end - -it "block should only include rooms that are available for the given date range" do - @rooms = [1, 2, 3] - @reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price) -end - -it "a room is set aside in a block, it is not available for reservation by the general public, nor can it be included in another block" do + it "A block can contain a maximum of 5 rooms" do + @rooms = [1, 2, 3, 4, 5, 6] + proc {@reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price)}.must_raise ArgumentError + end -end + it "block cannot be booked if no rooms available" do + @rooms = [] + proc {@reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price)}.must_raise ArgumentError + end -# it "can reserve a room from within a block of rooms" do -# -# end -# -# -# it "When a room is reserved from a block of rooms, the reservation dates will always match the date range of the block" do -# -# end + it "block rooms must appear in reservations once booked" do + @rooms = [5, 12, 15] + @reserved_block = Property::Block.new(@rooms, @check_in, @check_out, @price) + @reserved_block.rooms.each do |room| + @reservations.must_include room + end + end end diff --git a/specs/hotel_spec.rb b/specs/hotel_spec.rb index 2c5e486ae..e6b2f449b 100644 --- a/specs/hotel_spec.rb +++ b/specs/hotel_spec.rb @@ -29,60 +29,86 @@ end end - describe "reserve_room" do - - before do - @test_hotel = Property::Hotel.new - @check_in = Date.new(2017, 05, 05) - @check_out = @check_in + 3 - end - - - it "cannot book invalid room number" do - room = "garbage" - proc {@test_hotel.reserve_room(room, @check_in, @check_out)}.must_raise ArgumentError - end - - it "raises an error if tried to double-book room " do - room = 5 - @test_hotel.reserve_room(room, @check_in, @check_out) - proc {@test_hotel.reserve_room(room, @check_in, @check_out)}.must_raise ArgumentError - end - - it "adds the reservation to @reservations" do - test_rez = @test_hotel.reserve_room(10, @check_in, @check_out) - @test_hotel.reservations.must_include test_rez - end - - it "can access the list of reservations for a specific date" do - rez = @test_hotel.reserve_room(15, @check_in, @check_out) - @test_hotel.reservations.must_include rez - end - - it "I can get the total cost for a given reservation" do - rez = @test_hotel.reserve_room(20, @check_in, @check_out) - rez.total_price.must_equal 600 - end - - it "I can view a list of rooms that are not reserved for a given date range" do - rez = @test_hotel.reserve_room(3, @check_in, @check_out) - @test_hotel.available(@check_in, @check_out).include?(3).must_equal false - end - - it "can book a room that is available" do - excluding_one_room = @test_hotel.reserve_room(2, @check_in, @check_out) - available_room = @test_hotel.available(@check_in, @check_out).first - booking_available_room = @test_hotel.reserve_room(available_room, @check_in, @check_out) - @test_hotel.reservations.must_include booking_available_room - @test_hotel.reservations.length.must_equal 2 - end - # it "reservation cannot be made for room when check in and checkout dates overlap" do - # rez = @test_hotel.reserve_room(3, @check_in, @check_out) - # rez2 = @test_hotel.reserve_room(3, @check_out, (@check_out+ 3)) - # @test_hotel.reservations.include?(rez2).must_equal false - # end - #this test fails. I need to strategize and decide how I'll make sure check in is - #not available on the day of check out for the same room. - #one way I am thinking of doing this is to set time, but that just introduces more - #complexity ... +describe "reserve_room" do + + before do + @test_hotel = Property::Hotel.new + @check_in = Date.new(2017, 05, 05) + @check_out = @check_in + 3 + end + + + it "cannot book invalid room number" do + room = "garbage" + proc {@test_hotel.reserve_room(room, @check_in, @check_out)}.must_raise ArgumentError + end + + it "raises an error if tried to double-book room " do + room = 5 + @test_hotel.reserve_room(room, @check_in, @check_out) + proc {@test_hotel.reserve_room(room, @check_in, @check_out)}.must_raise ArgumentError + end + + it "adds the reservation to @reservations" do + test_rez = @test_hotel.reserve_room(10, @check_in, @check_out) + @test_hotel.reservations.must_include test_rez + end + + it "can access the list of reservations for a specific date" do + rez = @test_hotel.reserve_room(15, @check_in, @check_out) + @test_hotel.reservations.must_include rez + end + + it "I can get the total cost for a given reservation" do + rez = @test_hotel.reserve_room(20, @check_in, @check_out) + rez.total_price.must_equal 600 + end + + it "I can view a list of rooms that are not reserved for a given date range" do + @test_hotel.reserve_room(3, @check_in, @check_out) + @test_hotel.available(@check_in, @check_out).include?(3).must_equal false end + + it "can book a room that is available" do + excluding_one_room = @test_hotel.reserve_room(2, @check_in, @check_out) + available_room = @test_hotel.available(@check_in, @check_out).first + booking_available_room = @test_hotel.reserve_room(available_room, @check_in, @check_out) + @test_hotel.reservations.must_include booking_available_room + @test_hotel.reservations.length.must_equal 2 + end +end + +describe "block functionality" do + before do + @test_hotel = Property::Hotel.new + @room_qty = 3 + @check_in = Date.new(2017, 5, 5) + @check_out = @check_in + 3 + @price = 150 + # @block = @test_hotel.hotel_block(@room_qty, @check_in, @check_out, @price) + end + + it "cannot book zero rooms " do + proc {@test_hotel.hotel_block(0, @check_in, @check_out, @price)}.must_raise ArgumentError + end +end + # it "correct number of rooms booked in a block " do + # @block = @test_hotel.hotel_block(@room_qty, @check_in, @check_out, @price) + # @block.rooms.length.must_equal @room_qty + # end + + # it "once block booked, reserved_blocks reflects it" do + # @block = @test_hotel.hotel_block(@room_qty, @check_in, @check_out, @price) + # @reserved_blocks.must_include @block + # end + + + # it "reservation cannot be made for room when check in and checkout dates overlap" do + # rez = @test_hotel.reserve_room(3, @check_in, @check_out) + # rez2 = @test_hotel.reserve_room(3, @check_out, (@check_out+ 3)) + # @test_hotel.reservations.include?(rez2).must_equal false + # end + #this test fails. I need to strategize and decide how I'll make sure check in is + #not available on the day of check out for the same room. + #one way I am thinking of doing this is to set time, but that just introduces more + #complexity ... From 914960b2eb2235be00fa8110cbefd3877befd65d Mon Sep 17 00:00:00 2001 From: Tanja Stroble Date: Sun, 1 Oct 2017 21:26:57 -0700 Subject: [PATCH 14/14] added block functionality --- .DS_Store | Bin 6148 -> 6148 bytes lib/hotel.rb | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.DS_Store b/.DS_Store index f839ed23e4db1a7d61ad142d624490629de75d98..b69456a98628c3307776f29fd40bb9ceb1c98aef 100644 GIT binary patch delta 144 zcmZoMXfc@JFUZHhz`)4BAi%&-#E{64&XBq>VKp-&-)0+@QpUKPbi?4}{M-Vd8X(|5 z1SFUlau_lhl5+E1TvAF)k{KAT-sI*4OT%SSaL5#7Ae-jEFnKwv=Vk@A`;42}IsWnk E00)90R{#J2 delta 138 zcmZoMXfc@JFUZ5dz`)4BAi%(o&7j9n#E`TxVKuWMNR)#ii6Ms}pCK70mQu#aFInwXIe>;FGUPF&Go(Tc#G-A+W?8mZj1wC;HnVg5 G "q" - # a.first(2) #=> ["q", "r"] - @reserved_blocks << block + rooms = available(check_in, check_out) + + if rooms.length < room_qty + raise ArgumentError("Not enough rooms available") + end + + @reserved_blocks << block return block end + def reserve_from_block(block) room = block.reserve_room room_rez = Reservation.new(room, block.check_in, block.check_out, block.price)