Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cec97c2
copied over the 'scaffolding' given to us
ktvoort123 Mar 3, 2020
f7664ec
added initialize method
ktvoort123 Mar 3, 2020
1751a4e
added test for .include?
ktvoort123 Mar 3, 2020
b72173a
updated the overlap? and include? methods
ktvoort123 Mar 4, 2020
1f92e10
created room test file and created tests to test initialize method
ktvoort123 Mar 4, 2020
d9c8db7
created file and initialize method for room
ktvoort123 Mar 4, 2020
976a41d
copied over from the design scaffolding
ktvoort123 Mar 4, 2020
3c7ca28
added tests for reservations to test if the reservations method would…
ktvoort123 Mar 4, 2020
e5cf6c2
added test to see length of reservations returned
ktvoort123 Mar 4, 2020
9577086
copied over from design scaffolding
ktvoort123 Mar 4, 2020
d426993
added initialize method to hotel controller
ktvoort123 Mar 4, 2020
3d52ad4
updated reserve_room method
ktvoort123 Mar 4, 2020
14c59ed
updated reservations method
ktvoort123 Mar 4, 2020
3c42144
copied over from design scaffolding
ktvoort123 Mar 4, 2020
45131b9
added tests for the initialize method
ktvoort123 Mar 4, 2020
29e51e4
updated cost test
ktvoort123 Mar 4, 2020
fce61b8
copied over from design scaffolding
ktvoort123 Mar 4, 2020
6617737
updated initialize method
ktvoort123 Mar 4, 2020
9718e91
updated cost method
ktvoort123 Mar 4, 2020
7766e87
added require relatives and requires
ktvoort123 Mar 4, 2020
40aec0f
removed date_range_for_reservation method and instead used the date_r…
ktvoort123 Mar 6, 2020
5492456
created the tests for overlap? method
ktvoort123 Mar 6, 2020
d13fd98
added tests for include? method
ktvoort123 Mar 6, 2020
59eb095
added tests for the nights method
ktvoort123 Mar 6, 2020
a9280fe
added initial available_rooms tests
ktvoort123 Mar 6, 2020
567f5eb
crated the available_rooms method
ktvoort123 Mar 6, 2020
7021874
refactored available_rooms method
ktvoort123 Mar 6, 2020
507a804
added tests for avail_rooms method
ktvoort123 Mar 6, 2020
94735c8
added tests for overlapping rooms and added runtimeerror in reserve_r…
ktvoort123 Mar 6, 2020
3c864a3
added error in initialize to raise argument error if room argument is…
ktvoort123 Mar 8, 2020
ebf2cde
created block and block test files and added to test helper
ktvoort123 Mar 8, 2020
3ce2069
removed reservations_from_room from room attributes
ktvoort123 Mar 8, 2020
d1bb5f1
added initialize method and test for block
ktvoort123 Mar 8, 2020
268e0bd
created new subclass room_reservation
ktvoort123 Mar 8, 2020
32ae361
changed reservation to be a parent class instead of to actually reser…
ktvoort123 Mar 8, 2020
4a41754
changed code that creates new reservations to now create RoomReservat…
ktvoort123 Mar 8, 2020
513b267
changed init of room reservation and block to inherit from reservation
ktvoort123 Mar 8, 2020
1ae6a10
added reserve_room_from_block method and tests for it
ktvoort123 Mar 9, 2020
94597fa
added hotel block methods to hotel controller and created test for them
ktvoort123 Mar 9, 2020
73d6f30
cleaned up code and added test to check if instance variables can be …
ktvoort123 Mar 9, 2020
e76380f
added more tests for argumenterrors
ktvoort123 Mar 9, 2020
3b3f36e
changed some spacing
ktvoort123 Mar 9, 2020
162bee9
changed spacing
ktvoort123 Mar 9, 2020
d5befb6
final changes in formatting, also added refactors.txt file
ktvoort123 Mar 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'date'

module Hotel
class Block < Reservation
attr_reader :start_date, :end_date, :date_range, :disc_rate, :available_rooms, :reserved_rooms

def initialize(start_date, end_date, collection_of_rooms, disc_rate)
super(start_date,end_date)
@date_range = get_date_range(start_date, end_date)
@collection_of_rooms = collection_of_rooms
@disc_rate = disc_rate
@available_rooms = collection_of_rooms
@reserved_rooms = []
end

def reserve_room(room)
raise RuntimeError.new("room is not available in hotel block") unless @available_rooms.include?(room)

@available_rooms.delete(room)
@reserved_rooms.push(room)
Comment on lines +19 to +20

Choose a reason for hiding this comment

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

This is pretty good, but did you consider using the rooms as keys and a bool as a value in a hash? That would reduce your data overhead a bit, and means that you don't run the risk of forgetting to update one of the two arrays! :)

end

end
end
34 changes: 34 additions & 0 deletions lib/date_range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'date'

module Hotel
class DateRange
attr_accessor :start_date, :end_date

def initialize(start_date, end_date)
raise ArgumentError.new("start date has to be at least 1 day before end date") if (end_date - start_date).to_i < 1
@start_date = start_date
@end_date = end_date
end

def overlap?(range)
self.nights.times do |day|
range.nights.times do |day_in_range|
return true if (range.start_date + day_in_range) == (@start_date + day)
end
end
return false
Comment on lines +14 to +19

Choose a reason for hiding this comment

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

There is a simpler version of this logic that doesn't require looping! Draw a timeline, and put a date range on it, then draw out all possible relationships the ranges can have with it. I often take the approach of making a table or drawing a sketch when I want to simplify boolean logic.

end

def include?(date)
self.nights.times do |day|
return true if date == (@start_date + day)
end
return false
end

def nights
date_diff = @end_date - start_date
return date_diff.to_i
end
end
end
80 changes: 80 additions & 0 deletions lib/hotel_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'date'

require_relative 'reservation.rb'
require_relative 'room_reservation.rb'
require_relative 'date_range.rb'
require_relative 'room.rb'

module Hotel
class HotelController

Choose a reason for hiding this comment

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

This class is REALLY well scoped! It's letting the classes that its composed of do the heavy lifting!

attr_reader :rooms, :reservations

def initialize
rooms_array = []
20.times{ |i| rooms_array.push(Hotel::Room.new(i+1)) }
@rooms = rooms_array
@reservations = []
@blocks = []
end

def list_rooms
return @rooms
end

def reserve_room(start_date, end_date, room=@rooms.sample)
raise RuntimeError.new("room #{room.room_number} isn't available for those dates") unless available_rooms(start_date,end_date).include?(room)

new_reservation = RoomReservation.new(start_date, end_date, room)
@reservations.push(new_reservation)
return new_reservation
end

def create_hotel_block(date_range,collection_of_rooms,disc_rate)
raise ArgumentError.new("A block can only contain up to five rooms") if collection_of_rooms.length > 5


collection_of_rooms.each do |room|
raise RuntimeError.new("#{room.room_number} is not available") if available_rooms(date_range.start_date,date_range.end_date).include?(room) == false

reserve_room(date_range.start_date,date_range.end_date,room)
end

new_block = Hotel::Block.new(date_range.start_date, date_range.end_date, collection_of_rooms, disc_rate)

@blocks.push(new_block)

return new_block

end

def reserve_room_from_block(block,room)
raise ArgumentError.new("#{room.room_number} is not available") unless block.available_rooms.include?(room)

block.reserve_room(room)
end

def reservations(date)
reservations_to_return = []
@reservations.each do |reservation|
reservations_to_return.push(reservation) if reservation.date_range.include?(date)
end

return reservations_to_return
end

def available_rooms(start_date, end_date)
raise ArgumentError.new("start date has to be at least 1 day before end date") if (end_date - start_date).to_i < 1

requested_range = Hotel::DateRange.new(start_date,end_date)
avail_rooms = rooms.clone
overlapping_reservations = @reservations.select { |res| res.date_range.overlap?(requested_range) }

overlapping_reservations.each do |res|
avail_rooms.delete_if { |room| room == res.room }
end

return avail_rooms
end

end
end
20 changes: 20 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'date'

require_relative 'date_range.rb'

module Hotel
class Reservation
attr_reader :start_date, :end_date, :date_range

def initialize(start_date, end_date)
@start_date = start_date
@end_date = end_date
end

def get_date_range(start_date,end_date)
@date_range = Hotel::DateRange.new(start_date, end_date)
return @date_range
end

end
end
13 changes: 13 additions & 0 deletions lib/room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Hotel
class Room
attr_reader :room_number, :cost

def initialize(room_number, cost: 200)
raise ArgumentError if room_number.class != Integer

@room_number = room_number
@cost = cost
end

end
end
23 changes: 23 additions & 0 deletions lib/room_reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'date'

require_relative 'date_range.rb'
require_relative 'room.rb'

module Hotel
class RoomReservation < Reservation
attr_reader :start_date, :end_date, :room, :date_range

def initialize(start_date, end_date, room)
super(start_date,end_date)
raise ArgumentError.new("room must be an instance of room") if room.class != Hotel::Room

@room = room # instance of room class
@date_range = get_date_range(start_date, end_date)
end

def cost
return Hotel::DateRange.new(@start_date, @end_date).nights * @room.cost
end

end
end
5 changes: 5 additions & 0 deletions refactors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Changes I could have made:
-I could have somehow changed the hotel controller class and/or block class in order to keep track of room reservations for blocks once they're made
-I could have had the number of rooms be something that could be changed (a parameter with a default value?)
-I could have done the structure of the reservation, room reservation, and block reservation classes differently -- currently the reservation class is the parent class, while the room reservation and block reservation classes are children classes.
-I could have added functionality that allows for different rates for different rooms (this would make the block discounted rate actually work)
52 changes: 52 additions & 0 deletions test/block_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require_relative "test_helper"

describe Hotel::Block do
before do
@start_date = Date.new(2020,03,07)
@end_date = @start_date + 5

@collection_of_rooms = []
[6,10,13,16].each do |room_num|
@collection_of_rooms.push(Hotel::Room.new(room_num))
end

@room1 = Hotel::Room.new(1)
@collection_of_rooms.push(@room1)

@disc_rate = 0.2

@hotel_block = Hotel::Block.new(@start_date,@end_date,@collection_of_rooms,@disc_rate)
@hotel_block.reserve_room(@room1)

end


describe "initializes block correctly" do

it "block can be succesfully created" do
expect(@hotel_block).must_be_kind_of Hotel::Block
expect(@hotel_block.start_date).must_equal @start_date
expect(@hotel_block.end_date).must_equal @end_date
expect(@hotel_block.available_rooms).must_equal @collection_of_rooms
expect(@hotel_block.available_rooms).must_be_kind_of Array
expect(@hotel_block.available_rooms[0]).must_be_kind_of Hotel::Room
expect(@hotel_block.disc_rate).must_equal @disc_rate

end

end

describe "reserve_room" do
it "successfully reserves from block" do
expect(@hotel_block.reserved_rooms[0]).must_equal @room1
expect(@hotel_block.available_rooms.include?(@room1)).must_equal false
end

it "raises an exception if I try to reserve a room from the block that isn't available" do
expect{@hotel_block.reserve_room(@room1)}.must_raise RuntimeError
end

end


end
5 changes: 5 additions & 0 deletions test/coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{

Choose a reason for hiding this comment

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

Looks like you forgot to .gitignore the coverage folder!

"result": {
"covered_percent": 100.0
}
}
7 changes: 7 additions & 0 deletions test/coverage/.resultset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Minitest": {
"coverage": {
},
"timestamp": 1583526383
}
}
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/coverage/assets/0.12.2/application.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions test/coverage/assets/0.12.2/application.js

Large diffs are not rendered by default.

Binary file added test/coverage/assets/0.12.2/colorbox/border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/colorbox/controls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/colorbox/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/favicon_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/favicon_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/favicon_yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/loading.gif
Binary file added test/coverage/assets/0.12.2/magnify.png
93 changes: 93 additions & 0 deletions test/coverage/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Code coverage for Test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src='./assets/0.12.2/application.js' type='text/javascript'></script>
<link href='./assets/0.12.2/application.css' media='screen, projection, print' rel='stylesheet' type='text/css' />
<link rel="shortcut icon" type="image/png" href="./assets/0.12.2/favicon_green.png" />
<link rel="icon" type="image/png" href="./assets/0.12.2/favicon.png" />
</head>

<body>
<div id="loading">
<img src="./assets/0.12.2/loading.gif" alt="loading"/>
</div>
<div id="wrapper" class="hide">
<div class="timestamp">Generated <abbr class="timeago" title="2020-03-06T12:26:23-08:00">2020-03-06T12:26:23-08:00</abbr></div>
<ul class="group_tabs"></ul>

<div id="content">
<div class="file_list_container" id="AllFiles">
<h2>
<span class="group_name">All Files</span>
(<span class="covered_percent">
<span class="green">
100.0%
</span>

</span>
covered at
<span class="covered_strength">
<span class="red">
0.0
</span>
</span> hits/line
)
</h2>

<a name="AllFiles"></a>

<div>
<b>0</b> files in total.
</div>

<div class="t-line-summary">
<b>0</b> relevant lines,
<span class="green"><b>0</b> lines covered</span> and
<span class="red"><b>0</b> lines missed. </span>
(<span class="green">
100.0%
</span>
)
</div>



<div class="file_list--responsive">
<table class="file_list">
<thead>
<tr>
<th>File</th>
<th class="cell--number">% covered</th>
<th class="cell--number">Lines</th>
<th class="cell--number">Relevant Lines</th>
<th class="cell--number">Lines covered</th>
<th class="cell--number">Lines missed</th>
<th class="cell--number">Avg. Hits / Line</th>

</tr>
</thead>
<tbody>

</tbody>
</table>
</div>
</div>



</div>

<div id="footer">
Generated by <a href="https://github.com/colszowka/simplecov">simplecov</a> v0.18.5
and simplecov-html v0.12.2<br/>
using Minitest
</div>

<div class="source_files">

</div>
</div>
</body>
</html>
Loading