-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bianca Fernandez <Pipes> Hotel #34
base: master
Are you sure you want to change the base?
Conversation
…ted a check to make sure check in date came before check out
…ng out hotel class methods and variables
… time trying to call the right methods
…eraction with hotel class
…each block of rooms
HotelWhat We're Looking For
This looks good overall! I've definitely got some opinions about your Make sure you check out our reference implementation, particularly the way we've structured and used |
@rooms = [] | ||
room_num = 0 | ||
num_of_rooms.times do |room| | ||
room_num += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not something like
@rooms = (1..num_of_rooms).to_a
# ability to reserve a room within a block of rooms | ||
#needs to match the date range of the block | ||
def reserve_room_in_block(check_in, check_out, num_of_rooms) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I'm convinced by this method signature. What if two blocks have the same checkin/checkout dates and the same number of rooms? Instead, you should pass in either some sort of ID for the block, or the BlockRoom
instance itself.
def make_reservation(check_in, check_out, room_num) | ||
if room_availability(check_in, check_out).include?(room_num) | ||
@reservation_made = Reservation.new(check_in, check_out, room_num) | ||
@reservation_collection << @reservation_made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method looks good! Very clear what's going on.
# binding.pry | ||
if entry.check_in <= date && entry.check_out >= date | ||
date_list << [entry.room_num, entry.check_in.to_s, entry.check_out.to_s] | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check, that the date falls within the reservation, would be a great candidate for an instance method on DateRange
. Then you could say something like if entry.date_range.contains?(date)
.
|
||
@date_range = DateRange.new(check_in, check_out) | ||
@check_in = @date_range.check_in | ||
@check_out = @date_range.check_out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're encapsulating the checkin and checkout dates in a DateRange
, the you should not also store them as individual instance variables. If someone wants access to a reservation's dates, they'll have to go through the date range.
|
||
it "Checks for invalid date entry - if check in is after check out date" do | ||
check_in_1 = "Sept 9 2017" | ||
check_out_1 = "Sept 8 2017" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might include an explicit check here for when the dates are the same. Whether or not it's a legal range, I feel like it's an interesting case.
it "can call on collection of reservations array - will be empty" do | ||
Hotel::Hotel.new(20, 200).reservation_collection.must_be_instance_of Array | ||
Hotel::Hotel.new(20, 200).block_reservation_collection.must_be_instance_of Array | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two observations about this test:
- You probably don't want to instantiate two different hotels
- You don't actually check that the array is empty
You might rewrite it as follows:
it "can call on collection of reservations array - will be empty" do
hotel = Hotel::Hotel.new(20, 200)
hotel.reservation_collection.must_be_instance_of Array
hotel.reservation_collection.length.must_equal 0
hotel.block_reservation_collection.must_be_instance_of Array
hotel.block_reservation_collection.length.must_equal 0
end
|
||
it "Can return an argument error if room is not available for that date range" do | ||
proc { @bb_hotel.make_reservation('sept 8 2017', 'sept 9 2017', 4)}.must_raise ArgumentError | ||
end ####NOTE##### Not sure how to create a test to check if there is no problem with the code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for an exception is a good call here. If you're trying to avoid it passing when you've written a bug, a common technique is to define your own exception and look for that instead.
def room_availability(check_in, check_out) | ||
#can be string with dates | ||
rooms_available = @rooms.clone | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you've made getting a list of available rooms its own method - this both DRYs up your code and makes testing easier.
it "Returns the room numbers available for a certain date range" do | ||
@hotel.room_availability('sept 1 2017', 'sept 3 2017').must_equal [1 ,4] | ||
@hotel.room_availability('sept 5 2017', 'sept 6 2017').must_equal [2,3,4] | ||
@hotel.room_availability('sept 7 2017', 'sept 8 2017').must_equal [1,3,4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to break this up into multiple different it
blocks, to make it more obvious why each date range is interesting.
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions