Conversation
…king room instead of room_id as an argument for reservation and also have each room keep track of their reservations
…ade my make reservation method take a room from the available room array
…tion array for the room and added more test cases to hotel spec
HotelWhat We're Looking For
|
|
|
||
| def initialize(id) | ||
| @id = id | ||
| @price = 200 |
There was a problem hiding this comment.
This could be a constant somewhere else instead!
| @rooms = [] | ||
| id = 1 | ||
| 20.times do | ||
| room = Room.new(id) |
There was a problem hiding this comment.
Given your implementation of Room below, what is the difference between a Hash of Int:Array pairs and an array of Room objects?
Besides a guaranteed order, I don't think there is one, because the Room class is basically a stub.
| return all_available | ||
| end | ||
|
|
||
| def self.load_rooms |
| i = 0 | ||
| number_of_dates.times do | ||
| date = @start_date + i | ||
| dates.push(date) |
There was a problem hiding this comment.
Check out the Range class in Ruby: https://ruby-doc.org/core-2.2.0/Range.html
You can replace this method with the following call: (start_date .. end_date)
| # end | ||
| @room_rate = room_rate | ||
| @cost = ((@dates.length) - 1) * (@room_rate.to_i) | ||
| @dates = date_range |
There was a problem hiding this comment.
why do you make this call again? super has already called it!
| @reservations.each do |reservation| | ||
| reserved << reservation.room | ||
| end | ||
| return @rooms - reserved.uniq |
There was a problem hiding this comment.
Nice work on this! very clear and readable.
| it "makes an array of all the dates in the blocks date range" do | ||
| expect(@block.dates).must_be_kind_of Array | ||
| expect(@block.dates.length).must_equal 5 | ||
| end |
There was a problem hiding this comment.
Some tests you should be doing:
- Can you make a reservation into the block?
- What if someone tries to book a room in the block and they aren't from the block?
- What if someone tries to book a room in the block that extends past the block dates?
| i += 1 | ||
| end | ||
| return dates | ||
| end |
There was a problem hiding this comment.
Your implementation of block seems to miss one of the points of a block; that is, one needs to be able to book a room that is in the block, on top of creating the block itself.
| available_rooms = [] | ||
| all_available = [] | ||
| @reservations.each do |reservation| | ||
| if start_date >= reservation.dates.last || end_date <= reservation.dates.first |
There was a problem hiding this comment.
This will return true for a room on a single reservation, but that same room could be booked by another reservation. The list of available rooms needs to be built subtractively, not additively.
Example:
load_availables(Jan 3rd 2019, Jan 15th 2019)
if someone has booked room 1 for those exact dates, but there was another booking that happened from Jan 1st to Jan 3rd in room 1, room 1 would be added to the list of available rooms.
| @reservation2 = @hotel.make_reservation(start_date2, end_date2) | ||
| start_date3 = Date.new(2018, 3, 5) | ||
| end_date3 = start_date3 + 3 | ||
| @reservation3 = @hotel.make_reservation(start_date3, end_date3) |
There was a problem hiding this comment.
There is a significant flaw in this test: you used the same date range for all 3 bookings. This won't catch the case mentioned in the Hotel#load_availables comment above, where the same room is booked back to back.
…he load available method
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions