Skip to content
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

Katrina - Edges - Hotel #39

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open

Katrina - Edges - Hotel #39

wants to merge 47 commits into from

Conversation

kaganon
Copy link

@kaganon kaganon commented Sep 10, 2018

Hotel

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Describe a design decision you had to make when working on this project. What options were you considering? What helped you make your final decision? In the beginning of my design I had a room class, which contained the room numbers and cost. However, I ended up removing the room class because I realized I that I could just keep track of all the rooms in my BookingSystem class, and that the cost of the room would be stored as a constant variable in my Reservation class.
Describe a concept that you gained more clarity on as you worked on this assignment. I think after drawing out what I needed from each class and seeing how the Booking System is the main driver code that connects all the other classes, it was a little bit clearer for me to figure out the direction of my program.
Describe a nominal test that you wrote for this assignment. A nominal test in my program include correctly calculating total cost of a reservation. It tests to make sure that it calculates the total cost of the reservation, even when adding multiple dates to the same reservation.
Describe an edge case test that you wrote for this assignment. An edge case I wrote included raising an error for invalid dates. For example if the user entered nil for either or both dates, it would raise an error.
How do you feel you did in writing pseudocode first, then writing the tests and then the code? I think it’s still challenging for me to think of pseudo code and tests first before writing code, especially if I’m not sure in my design of the code. But I’ve found that it’s been getting better with more practice.

@droberts-sea
Copy link

Hotel

What We're Looking For

Feature Feedback
Baseline
Used git regularly yes
Answer comprehension questions yes
Design
Each class is responsible for a single piece of the program yes
Classes are loosely coupled yes
Wave 1
List rooms
Reserve a room for a given date range yes
List reservations for a given date yes
Calculate reservation price yes
Invalid date range produces an error yes
Test coverage yes
Wave 2
View available rooms for a given date range yes
Reserving a room that is not available produces an error yes
Test coverage yes
Wave 3
Create a block of rooms yes
Check if a block has rooms yes
Reserve a room from a block yes
Test coverage yes
Fundamentals
Names variables, classes and modules appropriately yes
Understanding of variable scope - local vs instance yes
Can create complex logical structures utilizing variables yes
Appropriately uses methods to break down tasks into smaller simpler tasks yes
Understands the differences between class and instance methods yes
Appropriately uses iterators and enumerables mostly
Appropriately writes and utilizes classes yes
Appropriately utilizes modules as a mechanism to encapsulate functionality yes
Wrap Up
There is a refactors.txt file yes
The file provides a roadmap to future changes yes
Additional Feedback Great job overall! Your design is clean, your code well-written and your test coverage solid. I spotted at least one logic bug, and as always there are a few places where things could be cleaned up, but in general I am quite happy with what I see here. Keep up the hard work!


def list_rooms
return @rooms
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doing the same thing as attr_reader :rooms, just with a different name. I would say that the attr_reader hits the project requirement, and you could omit this method.


def list_reservations(date_range)
return @reservations.select { |res| res.date_range == date_range }
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of select here.

return @rooms if @reservations.empty?
unavailable_rooms = @reservations.map { |res| res.room_number if date_range.dates_overlap?(res.date_range) }

unavailable_rooms_block = @block_rooms.map { |res| res.block_rooms if date_range.dates_overlap?(res.date_range)}.flatten

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has some problems. On line 31, you'll end up with a bunch of nils in your array, since map must always produce a value even if none of the code in the block executes.

On line 33, not only will you have nil, but the elements in your array are more arrays, since that's what a BlockRoom stores. That means that after line 35 has run, you'll have an array like:

[nil, 3, nil, nil, 5, nil, [8, 9, 10], nil]

A side effect of this is that your code does not respect blocks when making reservations!

You could use a combination of Array#flatten and Array#compact to fix it, or it could be that map isn't a great choice for this problem.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do love the way this code flows though - logic problems aside, this is an excellent example of loose coupling. Rather than pulling the dates out of the reservation and doing a bunch of math here, you call a method and let the date range take care of it. That makes this code easier to read, and it means if something about how overlaps are calculated changes this code won't have to. Good work!

def find_room_in_block(date_range)
found_block = find_block(date_range)
room_block_rooms = found_block.first.block_rooms
available_rooms = find_available_rooms(date_range)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there's more than one block for a date range?


raise StandardError, "Invalid dates entered" if @start_date == nil || @end_date == nil

raise StandardError, "End date cannot be before start date" if (@end_date - @start_date) <= 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of raising a StandardError, best practice is to define your own appropriately named exception type that inherits from StandardError and raise that. The reason is that StandardError is very broad, and if the code that calls this method has to rescue StandardError, that will catch things like ArgumentErrors and NameErrors that indicate true bugs.

if new_dates.first < booked_dates.first && new_dates.last > booked_dates.last
return true
# back end
elsif new_dates.first < booked_dates.last && new_dates.last > booked_dates.last

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way you've placed this logic on the DateRange class - good division of responsibilities.

However, this check can be done in a single line! I challenge you to figure out how. Or you can go read the instructor implementation.

it 'Raises an error if there are no available rooms for the date range' do
hotel_booked = Hotel::BookingSystem.new()

20.times do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work catching this error case!

describe 'dates_overlap? method' do
before do
@date_range = @reservation_1.reservations[0].date_range
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though the list of these checks may originally have come from the instructors, you did the work of interpreting them and implementing them as tests. I appreciate your diligence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants