-
Notifications
You must be signed in to change notification settings - Fork 40
Space - Hala #30
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
base: master
Are you sure you want to change the base?
Space - Hala #30
Conversation
…ms into that class
HotelSection 1: Major Learning Goals
Section 2: Code Review and Testing Requirements
Section 3: Feature Requirements
Overall Feedback
Additional FeedbackGreat work overall! You've built your first project with minimal starting code. This represents an incredible milestone in your journey, and you should be proud of yourself! I am particularly impressed by the way that you broke down the problem in readable methods that each dealt with a small piece of the larger problems. Doing this effectively not only helps you read your code more effectively, but the way in which your methods are reusable makes it so that your code can flex and adapt to the future. I do see some room for improvement around testing and responsibility separations. Your tests cover a lot of good ground, but especially with something like checking if date ranges overlap, you need to be exhaustive in your testing. I often draw a picture or make a table to make sure I'm not missing anything key. Also, I left a few comments in your code about how responsibilities are divvied up. Basically, we want to make sure that our classes exist not only to hold their data, but to answer questions about it and manage it. Your code produced the following warnings, among others: Code Style Bonus AwardsWas the code particularly impressive in code style for any of these reasons (or more...?)
|
| # def room_aside_for_date_range(start_date,end_date,room) | ||
| # range = date_in...date_out | ||
| # rooms_block.each do |room_in_block| | ||
| # if room_in_block == room | ||
| # if range.include?(date) | ||
| # return :UNAVAILABLE | ||
| # end | ||
| # end | ||
| # end | ||
| # else return :AVAILABLE | ||
| # 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.
Don't forget to remove dead code before submission! As long as you have committed the code you can get old methods like this back.
| end | ||
| end | ||
|
|
||
| def add_a_reservation_to_room(room, reservation) |
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 define this inside of Room, because managing a class's data makes the most sense as a responsibility of that class. Also, it removes bloat from your HotelManager.
| def add_rooms_to_block(hotelblock,number_of_rooms_needed) | ||
| number_of_available_rooms = 0 | ||
| rooms.each do |room| | ||
| if room.test_overlap(hotelblock.date_in,hotelblock.date_out) == :AVAILABLE | ||
| number_of_available_rooms +=1 | ||
| end | ||
| end | ||
| if number_of_available_rooms < number_of_rooms_needed | ||
| raise ArgumentError, "Not enough room AVAILABILITY for this Block! Only #{number_of_available_rooms} AVAILABLE" | ||
| else | ||
| rooms_added = 0 | ||
| rooms.each do |room| | ||
| if room.test_overlap(hotelblock.date_in,hotelblock.date_out) == :AVAILABLE | ||
| hotelblock.rooms_block<< room | ||
| rooms_added +=1 | ||
| if rooms_added == number_of_rooms_needed | ||
| return | ||
| end | ||
| end | ||
| end | ||
| end | ||
| 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.
Again, this is probably the responsibility of HotelBlock, as it changes data inside the Block.
| class HotelBlock | ||
| attr_accessor :date_in, :date_out, :number_of_rooms, :rooms_block | ||
|
|
||
| @@increment_id = 1 | ||
| def initialize(date_in:,date_out:,number_of_rooms:, rooms_block:[], discounted_room_rate:) | ||
| @id = @@increment_id | ||
| @@increment_id += 1 | ||
| @date_in = date_in | ||
| @date_out = date_out | ||
| @number_of_rooms = number_of_rooms | ||
| # this range does not work, its an array of numbers | ||
| #raise argument error unless (2..5).include? number_of_rooms | ||
| @rooms_block =[] | ||
| 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 always get suspicious if a class ends up with just initialize. It usually means that the class in question is having its methods 'stolen' by other classes.
|
|
||
| attr_accessor :id, :date_in, :date_out, :room_id | ||
|
|
||
| @@increment_id = 1 | ||
| def initialize(date_in:, date_out:, room_id: , room: ) | ||
| @id = @@increment_id | ||
| @@increment_id += 1 | ||
| @date_in = date_in | ||
| @date_out = date_out | ||
| @room_id = room_id | ||
| @room = room | ||
|
|
||
| unless date_out >= date_in | ||
| raise ArgumentError, 'you cannot have date out come before date in' | ||
| end | ||
|
|
||
| if room.test_overlap(date_in,date_out) == :UNAVAILABLE | ||
| raise ArgumentError, 'there is an overlap' | ||
| end | ||
| end | ||
|
|
||
| def total_number_of_nights_per_reservation | ||
| return date_out - date_in | ||
| 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 class does a great job knowing what it's responsible for and having a good selection of methods for returning important info.
| overlap1 = start_date >= reservation.date_in && start_date < reservation.date_out | ||
| overlap2 = end_date > reservation.date_in && end_date < reservation.date_out | ||
| overlap3 = start_date >= reservation.date_in && end_date < reservation.date_out | ||
| overlap4 = start_date <= reservation.date_in && end_date >= reservation.date_out | ||
|
|
||
| overlap1 || overlap2 || overlap3 || overlap4 |
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.
There is a simpler way of doing this date checking! Make a timeline, put an existing reservation on the timeline, and then see where you can draw lines that don't conflict!
| attr_accessor :rooms, :blocks | ||
|
|
||
| def initialize(rooms:,blocks:) | ||
| @rooms = @Hotel::Room.list_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.
When you are inside the scope of module Hotel you don't need to do Hotel::. The @Hotel ends up causing a bunch of warnings.
| date_in1 = DateTime.new(2020,2,3.5) | ||
| date_out1 = DateTime.new(2020,2,5.5) | ||
| date_in2 = DateTime.new(2020,2,7.5) | ||
| date_out2 = DateTime.new(2020,2,14.5) | ||
| date_in3 = DateTime.new(2020,2,14.5) | ||
| date_out3 = DateTime.new(2020,2,16.5) | ||
| @hotel = Hotel::HotelManager.new(rooms: Hotel::Room.list_of_rooms,blocks: []) | ||
| @reservation1 = Hotel::Reservations.new(date_in:date_in1 , date_out:date_out1, room_id:1, room: @hotel.rooms[0]) | ||
| @reservation2 = Hotel::Reservations.new(date_in:date_in2 , date_out:date_out2, room_id:1, room: @hotel.rooms[0]) | ||
| @reservation3 = Hotel::Reservations.new(date_in:date_in3 , date_out:date_out3, room_id:1, room: @hotel.rooms[0]) | ||
| @hotel.add_a_reservation_to_room(@hotel.rooms[0],@reservation1) | ||
| @hotel.add_a_reservation_to_room(@hotel.rooms[0],@reservation2) | ||
| @hotel.add_a_reservation_to_room(@hotel.rooms[0],@reservation3) | ||
| @room = Hotel::Room.new(id: 34, reservations: []) |
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.
Do you need all of this data for every single test?
| it "returns false when a room is anavailable" do | ||
| date = DateTime.new(2020,2,4.5) | ||
| date1 = DateTime.new(2020,3,4.5) | ||
| date2 = DateTime.new(2020,2,5.5) | ||
| date3 = DateTime.new(2020,2,14.5) | ||
| expect(@hotel.rooms[0].specific_date_availability(date)).must_equal [false] | ||
| expect(@hotel.rooms[0].specific_date_availability(date1)).must_equal [] | ||
| expect(@hotel.rooms[0].specific_date_availability(date2)).must_equal [] | ||
| expect(@hotel.rooms[0].specific_date_availability(date3)).must_equal [false] | ||
| 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.
There are a lot of ways that date ranges can overlap! Somewhere you need to exhaustively test them to make sure your date checking logic is correct.
| @block = Hotel::HotelBlock.new(date_in: date_in1,date_out: date_out1 ,number_of_rooms: (2..5), rooms_block:[],discounted_room_rate: 150) | ||
| end | ||
|
|
||
| it "is an instance of FrontDesk" 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.
Test name?
Assignment Submission: Hotel
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection