Skip to content

Sockets - Cyndi#43

Open
cyndilopez wants to merge 29 commits intoAda-C11:masterfrom
cyndilopez:master
Open

Sockets - Cyndi#43
cyndilopez wants to merge 29 commits intoAda-C11:masterfrom
cyndilopez:master

Conversation

@cyndilopez
Copy link
Copy Markdown

@cyndilopez cyndilopez commented Mar 18, 2019

Hotel

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
What was a design challenge that you encountered on this project? Which classes to implement and how classes communicate with the module.
What was a design decision you made that changed over time over the project? The behavior of room changed; originally it had no behavior and then was changed to be able to communicate whether it was available.
What was a concept you gained clarity on, or a learning that you'd like to share? I gained clarity on what guard and coverage do.
What is an example of a nominal test that you wrote for this assignment? What makes it a nominal case? A nominal test was checking whether the code could calculate the total cost of a reservation correctly for a span of a few days. It's nominal because it's a standard calculation with simple math.
What is an example of an edge case test that you wrote for this assignment? What makes it an edge case? Edge case date ranges were used to test whether a room was available for a given date range. It was an edge case because it was outside the norm.
How do you feel you did in writing pseudocode first, then writing the tests and then the code? I should've written more pseudocode; however I did well on first writing tests and then the code.

…d with room id, and update list of reservations; and tests associated with these three methods
…to its list of reservations. added a couple tests for this method that check a reservation was added and that it is of the correct type
… a given date range; argumenterror clause if tries to reserve room unavailable on date
… class. also created reserve hotel block method. added tests for these
… to reserve room or hotel block when room is set aside in hotel block
…el block. also now raises argument error if #rooms in a block is greater than 5
@droberts-sea
Copy link
Copy Markdown

Hotel

What We're Looking For

Feature Feedback
Baseline
Used git regularly yes
Answer comprehension questions yes - the test case you've labeled as an edge case (checking whether a room is available) is really more of a nominal case. There's not an "edge" in the behavior of the program that the test is exploring. An edge case would be checking if a room is available the day after the previous reservation ends.
Design
Each class is responsible for a single piece of the program
Classes are loosely coupled mostly
Wave 1
List rooms yes
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 mostly
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 mostly - see inline
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 Enumerable methods mostly - see inline
Appropriately writes and utilizes classes yes
Appropriately utilizes modules as a namespace yes
Wrap Up
There is a refactors.txt file yes
The file provides a roadmap to future changes yes
Additional Feedback Good work overall! This code is well-written and does a good job of solving the problem. I've left a fair bit of feedback inline, but most of it is for little things, and I am confident that the learning goals for this assignment were met. Keep up the hard work!

Comment thread lib/hotel.rb
def reserve_room(start_date, end_date, room_id, block_id = nil, discount = nil)
#check if room available during those days
rooms_available = available_rooms(start_date, end_date)
raise ArgumentError if !(rooms_available.include?(room_id)) && block_id == nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What if instead of calling available_rooms and then checking for inclusion, you called find_room and then is_available? directly? That would save you calling is_available? on all the other rooms.

Comment thread lib/hotel.rb
def available_rooms(start_date, end_date)
avail_rooms = []
rooms.each do |room|
avail_rooms << room.id if room.isAvailable?(start_date, end_date)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The .select enumerable might be helpful to clean up this code a little.

Comment thread lib/hotel.rb
def access_reservations(date)
list_reservations = @reservations.select { |reservation| (Range.new(reservation.start_date, reservation.end_date)).include?(date) }
return list_reservations.map { |reservation| reservation }
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On line 45 you do a lot of work with the internals of the reservation. I know we hadn't read POODR ch 4 yet when you wrote this code, but this is exactly what Metz is talking about when she says you should "ask for what instead of telling how". A cleaner approach might be to add a .includes_date? method to reservation, then use it here:

return @reservations.select { |res| res.include_date?(date) }

Also the map on line 46 is not needed.

Comment thread lib/reservation.rb
@block_id = block_id
@discount = discount
@total_cost = calc_total_cost
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In stead of storing @total_cost in an instance variable, it might be wise to rename the calc_total_cost method total_cost. That way if the price, discount, or number of nights were ever to change, the total price would "update" automatically (update is in quotes because it was never stored in the first place).

Comment thread lib/room.rb
def check_date_range_conflict(start_date, end_date, array)
if array != []
array.each do |item|
return true if (!(item.start_date...item.end_date).include?(start_date) &&
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would ask for more descriptive variable names here than array and item. What do you expect these variables to contain?

Comment thread spec/block_spec.rb
end
@hotel = Hotel::Hotel.new(
id: 1,
rooms: @rooms,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rather than messing around with an entire Hotel in the Block tests, you should instantiate a Block directly and test on that.

Comment thread spec/hotel_spec.rb

it "adds the reservation to the Hotel's list of reservations" do
new_reservation = @hotel.reserve_room(Date.new(2001, 3, 5), Date.new(2001, 3, 7), 0)
expect(@hotel.reservations.length).must_equal 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens if you try to reserve a room that's already taken?

Comment thread spec/hotel_spec.rb
expect(@hotel.find_room(0)).must_be_kind_of Hotel::Room
end

it "returns the correct room id" do
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would probably combine these two tests into one. However there is a case you're missing: what if the room to be found doesn't exist?

Comment thread spec/hotel_spec.rb
it "raises an Argument Error if tries to reserve room that is not available for a given day" do
expect { @hotel.reserve_room(Date.new(2001, 3, 5), Date.new(2001, 3, 17), 12) }.must_raise ArgumentError
end
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Aha, here is the test I asked for above. Since this exercises the reserve_room method, it should be grouped with those tests.

Comment thread spec/room_spec.rb
require "Date"
describe "Room class" do
describe "Room instantiation" do
before do
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should have some tests for the is_available? method.

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