-
Notifications
You must be signed in to change notification settings - Fork 40
Time - Lola #38
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: design-scaffolding
Are you sure you want to change the base?
Time - Lola #38
Changes from all commits
49a7e14
099e747
4c1474b
61aff24
d8b5910
3289c83
c2fd43e
93cc55f
6eb8dfb
0c7322c
a471fb7
95f324c
9cfb144
ae9df64
df966d7
fe360c1
65a8b36
db6dc08
e3c4ea4
6c14d91
eb7f899
a131840
2566193
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,38 @@ | ||
| module Hotel | ||
| class DateRange | ||
|
|
||
| attr_accessor :start_date, :end_date | ||
|
|
||
| def initialize(start_date, end_date) | ||
| @start_date = start_date | ||
| @end_date = end_date | ||
| if @end_date <= @start_date | ||
| raise DateError "Invalid date. Your start date cannot be after your end date." | ||
| end | ||
| end | ||
|
|
||
| def overlap?(other) | ||
| return false | ||
|
|
||
| # checks if a reservation overlaps with another | ||
| def overlap?(date_range) | ||
| if (end_date < date_range.start_date || start_date > date_range.end_date) | ||
| return false | ||
| else | ||
| return true | ||
| end | ||
| end | ||
|
|
||
| def include?(date) | ||
| return false | ||
| # checks if date is included in a reservation | ||
| def include?(date) | ||
| if date >= start_date && date <= end_date | ||
| return true | ||
| else | ||
| return false | ||
| end | ||
| end | ||
|
|
||
|
|
||
| # find the total of nights stayed | ||
| def nights | ||
| return 3 | ||
| length_of_stay = (@end_date - @start_date).to_i | ||
| return length_of_stay | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,44 @@ | ||
| module Hotel | ||
| class HotelController | ||
| # Wave 1 | ||
| def rooms | ||
| # You might want to replace this method with an attr_reader | ||
| return [] | ||
| end | ||
| class HotelController | ||
|
|
||
| def reserve_room(start_date, end_date) | ||
| # start_date and end_date should be instances of class Date | ||
| return Reservation.new(start_date, end_date, nil) | ||
| end | ||
| attr_accessor :hotel_rooms, :reservations | ||
| attr_reader | ||
|
|
||
| def reservations(date) | ||
| return [] | ||
| def initialize() | ||
| @hotel_rooms = (1..20).to_a | ||
| @reservations = [] | ||
| end | ||
|
|
||
| # Wave 2 | ||
| def available_rooms(start_date, end_date) | ||
| # start_date and end_date should be instances of class Date | ||
| return [] | ||
| # Wave 1 | ||
| # creates a reservation of a room for a given date range | ||
| def reserve_room(start_date, end_date, room_number, rate) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work implementing this complex logic. To fully tie together |
||
| if !available_rooms(start_date, end_date).include?(room_number) | ||
| raise ArgumentError.new "Sorry, there is no room available on those days." | ||
| else | ||
| reservation = Hotel::Reservation.new(start_date, end_date, room_number, rate) | ||
| @reservations << reservation | ||
| return reservation | ||
| end | ||
| end | ||
|
|
||
| # takes a date and returns an array of reservations | ||
| def reservations_by_date(date = Date.today) | ||
| @reservations.select do |reservation| | ||
| date_range = DateRange.new(reservation.start_date, reservation.end_date) | ||
| date_range.include?(date) | ||
| end | ||
| end | ||
|
|
||
| # Wave 2 | ||
| # locate available rooms by two dates and returns an array | ||
| def available_rooms(start_date, end_date) | ||
| reserved_rooms = @reservations.select do |reservation| | ||
| date_range = DateRange.new(start_date, end_date) | ||
| date_range.overlap?(reservation.date_range) | ||
| end.map do |reservation| | ||
| reservation.room_number | ||
| end | ||
| return @hotel_rooms - reserved_rooms | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Despite HotelController doing a bulk of the work, I would try to see how I can condense this to two classes | ||
| Raise more exceptions to account for user input error | ||
| I would consider trying to make more helper methods | ||
| Save the reservations and it's room number in a array of hashes | ||
| Get better at writing tests | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your tests look great! However, you need more of them. |
||
| Understand how to get the program to pass 95% test coverage | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By clicking on the file name in the |
||
| Move onto Wave 3 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,20 @@ | ||
| module Hotel | ||
| class Reservation | ||
| # Feel free to change this method signature as needed. Make sure to update the tests! | ||
| def initialize(start_date, end_date, room) | ||
|
|
||
| attr_reader :room_number, :rate, :date_range, :start_date, :end_date | ||
|
|
||
| def initialize(start_date, end_date, room_number, rate = 200) | ||
| @start_date = start_date | ||
| @end_date = end_date | ||
| @date_range = DateRange.new(start_date, end_date) | ||
| @room_number = room_number | ||
| @rate = rate | ||
| end | ||
|
|
||
| # calculates the total of each reservation | ||
| def cost | ||
| return 3 | ||
| total_cost = @date_range.nights.to_i * rate | ||
| return total_cost | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,10 @@ | |
| expect(range.end_date).must_equal end_date | ||
| end | ||
|
|
||
| xit "is an an error for negative-lenght ranges" do | ||
| it "is an an error for negative-lenght ranges" do | ||
| end | ||
|
|
||
| xit "is an error to create a 0-length range" do | ||
| it "is an error to create a 0-length range" do | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -35,32 +35,32 @@ | |
| expect(@range.overlap?(test_range)).must_equal true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good test for a single test case. The test cases below also need to be completed to insure that |
||
| end | ||
|
|
||
| xit "returns true for a contained range" do | ||
| it "returns true for a contained range" do | ||
| end | ||
|
|
||
| xit "returns true for a range that overlaps in front" do | ||
| it "returns true for a range that overlaps in front" do | ||
| end | ||
|
|
||
| xit "returns true for a range that overlaps in the back" do | ||
| it "returns true for a range that overlaps in the back" do | ||
| end | ||
|
|
||
| xit "returns true for a containing range" do | ||
| it "returns true for a containing range" do | ||
| end | ||
|
|
||
| xit "returns false for a range starting on the end_date date" do | ||
| it "returns false for a range starting on the end_date date" do | ||
| end | ||
|
|
||
| xit "returns false for a range ending on the start_date date" do | ||
| it "returns false for a range ending on the start_date date" do | ||
| end | ||
|
|
||
| xit "returns false for a range completely before" do | ||
| it "returns false for a range completely before" do | ||
| end | ||
|
|
||
| xit "returns false for a date completely after" do | ||
| it "returns false for a date completely after" do | ||
| end | ||
| end | ||
|
|
||
| xdescribe "include?" do | ||
| describe "include?" do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests below should be completed. This will bring up you test coverage |
||
| it "reutrns false if the date is clearly out" do | ||
| end | ||
|
|
||
|
|
@@ -71,7 +71,7 @@ | |
| end | ||
| end | ||
|
|
||
| xdescribe "nights" do | ||
| describe "nights" do | ||
| it "returns the correct number of nights" do | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,26 +6,23 @@ | |
| @date = Date.parse("2020-08-04") | ||
| end | ||
| describe "wave 1" do | ||
| describe "rooms" do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should keep this test to ensure that a |
||
| it "returns a list" do | ||
| rooms = @hotel_controller.rooms | ||
| expect(rooms).must_be_kind_of Array | ||
| end | ||
| end | ||
| describe "reserve_room" do | ||
| it "takes two Date objects and returns a Reservation" do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good test. Nice work! You also need to test edge cases. What if there is no room available? |
||
| start_date = @date | ||
| end_date = start_date + 3 | ||
| room_number = 10 | ||
| rate = 200 | ||
|
|
||
| reservation = @hotel_controller.reserve_room(start_date, end_date) | ||
| reservation = @hotel_controller.reserve_room(start_date, end_date, room_number, rate) | ||
|
|
||
| expect(reservation).must_be_kind_of Hotel::Reservation | ||
| expect(@hotel_controller.reservations.size).must_equal(1) | ||
| end | ||
| end | ||
|
|
||
| describe "reservations" do | ||
| it "takes a Date and returns a list of Reservations" do | ||
| reservation_list = @hotel_controller.reservations(@date) | ||
| reservation_list = @hotel_controller.reservations_by_date(@date) | ||
|
|
||
| expect(reservation_list).must_be_kind_of Array | ||
| reservation_list.each do |res| | ||
|
|
@@ -37,14 +34,44 @@ | |
|
|
||
| describe "wave 2" do | ||
| describe "available_rooms" do | ||
| before do | ||
| @room_number = 1 | ||
| #@hotel_controller.rooms | ||
| end | ||
|
|
||
| it "takes two dates and returns a list" do | ||
| start_date = @date | ||
| end_date = start_date + 3 | ||
|
|
||
| room_list = @hotel_controller.available_rooms(start_date, end_date) | ||
|
|
||
|
|
||
| expect(room_list).must_be_kind_of Array | ||
| expect(room_list).must_equal((1..20).to_a) | ||
| end | ||
|
|
||
| it "doesn't return reserved room" do | ||
| start_date = @date | ||
| end_date = start_date + 3 | ||
|
|
||
|
|
||
| @hotel_controller.reserve_room(start_date, end_date, 10, 200) | ||
| room_list = @hotel_controller.available_rooms(start_date, end_date) | ||
|
|
||
| expect(room_list).must_be_kind_of Array | ||
| expect(room_list.size).must_equal(19) | ||
| end | ||
|
|
||
| it "returns room if booking date isn't overlap" do | ||
| start_date = @date | ||
| end_date = start_date + 3 | ||
|
|
||
| @hotel_controller.reserve_room(@date + 4, @date + 5, 8, 200) | ||
| room_list = @hotel_controller.available_rooms(start_date, end_date) | ||
|
|
||
| expect(room_list).must_be_kind_of Array | ||
| expect(room_list.size).must_equal(20) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,9 @@ | |
| it "returns a number" do | ||
| start_date = Date.new(2017, 01, 01) | ||
| end_date = start_date + 3 | ||
| reservation = Hotel::Reservation.new(start_date, end_date, nil) | ||
| room_number = 7 | ||
| rate = 200 | ||
| reservation = Hotel::Reservation.new(start_date, end_date, room_number, rate) | ||
| expect(reservation.cost).must_be_kind_of Numeric | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition to checking that cost is |
||
| 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.
This constructor looks great. Make sure to include a test that check that the class is set up correctly.