-
Notifications
You must be signed in to change notification settings - Fork 46
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
hotel.rb #24
base: master
Are you sure you want to change the base?
hotel.rb #24
Conversation
…servatoin method in TrackingSystem class, tests passing but still need to refactor for more reasonable usability
…eturn value to the @Reservations list
…refactoring this code and creating helper methods"
…ultiple rooms in one reservation
…ssertions, 2 failures(failures surrounding create reservation )
…ake_reservation method
…lects the room number that is reserved
…o tests, all tests passing
…. now the method returns an array of available rooms
…failing, need to increase coverage
…ent error is raised appropriately
… unnecessary comments
… rather than Array. Each reservation just stores one room
…his method as well
… commented out code blocks in TrackingSystem to see if I'll call on that method from TS later
…are 3 tests for this method, all tests passing
… that are already in a block
…all rooms were available
…n TrackingSystem class should be !=
…'t recognize id as a Symbol
HotelWhat We're Looking For
|
class Reservation | ||
attr_reader :room_num, :start_time, :end_time, :price | ||
|
||
def initialize(attributes) |
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 should have some checks to make sure the start and end dates are correct here.
total_cost = 0 | ||
return total_cost = ((end_time - start_time) * price).round(2) | ||
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.
I would suggest to add methods to tell if two reservations clash, or if a reservation is on a specific date.
require_relative 'block' | ||
require 'pry' | ||
|
||
NUMBER_OF_ROOMS = 20 |
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.
good use of constants!
lib/tracking_system.rb
Outdated
raise ArgumentError.new"#{date} must be instance of Date" unless date.instance_of? Date | ||
all_reservations = [] | ||
@reservations.each do |reservation| | ||
if (reservation.start_time...reservation.end_time).include?(date) |
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 would make a great deal of sense to have a method in Reservation
to tell if the reservation occurs on the given date. That way the tracking system doesn't need to involve itself in the internal details of a reservation.
available_rooms << room | ||
else | ||
room.reserved_dates.each do |dates_hash| | ||
if ranges_overlap?((dates_hash[:start_time]...dates_hash[:end_time]).to_a, (start_time..end_time).to_a) == false && room.block == :NA |
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.
Just because a room's reservation range doesn't overlap once, doesn't mean the room isn't reserved on that date.
end | ||
|
||
it "raises an ArgumentError if no reservations are available on given date" do | ||
expect{@tracker.view_reservations_on(Date.new(3333,10,5))}.must_raise ArgumentError |
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 raise an error, why not just return an empty list?
expect(@available_rooms[0]).must_be_kind_of Room | ||
end | ||
|
||
it "raises ArgumentError if no rooms are available on these dates(aka they're in a block or reserved)" do |
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 test assumes too much detail about how Room
is implemented. Instead what you could do is add 20 reservations on a given date using TrackingSystem
' s method. Then try making a 21st reservation on the same date range.
@reservations = @tracker.add_reservation(start_time: Date.new(2018,8,1), end_time: Date.new(2018,8,25), number_of_rooms:1) | ||
@reservations = @tracker.add_reservation(start_time: Date.new(2018,8,1), end_time: Date.new(2018,8,25), number_of_rooms:6) | ||
list = @tracker.reservations | ||
expect(@reservations).must_be_kind_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.
This is more testing reservations
instead of add_reservation
it "raises ArgumentError if there are not enough available-rooms on the requested date" do | ||
expect{@tracker.add_reservation(start_time: Date.new(2018,1,1),end_time:Date.new(2018,1,2),number_of_rooms:350)}.must_raise ArgumentError | ||
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.
You should also test that if you make 2 reservations in the same date range, they are for different rooms.
Also test that you can make a reservation on the same date as another reservation ends.
end | ||
end | ||
|
||
describe "#retrieve_block_dates" do |
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 would suggest using a block Id number instead of a symbol just because it's easier to work with.
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions