forked from AdaGold/hotel
-
Notifications
You must be signed in to change notification settings - Fork 43
Hannah Cameron - Hotel - Octos #37
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
Open
hannahlcameron
wants to merge
18
commits into
Ada-C9:master
Choose a base branch
from
hannahlcameron:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c861cf4
set up file structure for current classes; wrote tests for HotelManag…
hannahlcameron 7e44b09
added in testing for Reservation#initialize - no tests passing yet
hannahlcameron 66e3210
reformatted testing in hotel_manager_spec to match formatterin in res…
hannahlcameron eb1c8d5
rewrote tests for reservation#initialize that take into account chang…
hannahlcameron e862d29
wrote tests for helper methods #get_reservation_id and #get_available…
hannahlcameron f808cb8
all helper methods for #add_reservation passing tests; tests written …
hannahlcameron a440a6d
added tests for reservation#stay_date_list; method passing all tests
hannahlcameron a00cc4b
shifted method to calculate cost of reservation to the reservation cl…
hannahlcameron 7bf7fec
added in error handling for date range. wave 1* requirements met. mov…
hannahlcameron b0cbbb5
added tests for HotelManager#find_available_rooms. code passing tests…
hannahlcameron e0f4fa7
modified HotelManager#reservations_by_date and #find_available_rooms …
hannahlcameron 397f058
fixed failure of testing for HotelManager#Get_available_room; added i…
hannahlcameron 297eae8
fixed my errors with hotelmanager#get_available_rooms. passing all te…
hannahlcameron 1dedcde
cleaned up spacing and indentation for hotelmanager.rb and reservaion.rb
hannahlcameron 99742bb
added in initialize tests for block - passing all tests. minor format…
hannahlcameron 0ebad6e
block#calculate_cost method passing tests
hannahlcameron 44b1b75
added in exception handling for if a block size is over 5.
hannahlcameron 005dff6
added in exception handling for if a block size is under 2
hannahlcameron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| require 'rake/testtask' | ||
|
|
||
| Rake::TestTask.new do |t| | ||
| t.libs = ["lib"] | ||
| t.warning = true | ||
| t.test_files = FileList['specs/*_spec.rb'] | ||
| end | ||
|
|
||
| task default: :test | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| require 'date' | ||
| require 'pry' | ||
|
|
||
| module Hotel | ||
| class Block < Reservation | ||
|
|
||
| RATE_DISCOUNT = 0.8 | ||
|
|
||
| attr_accessor :block_size, :reserved_rooms | ||
|
|
||
| def initialize(input) | ||
| super | ||
|
|
||
| @block_size = input[:block_size] | ||
| @reserved_rooms = Array.new | ||
|
|
||
| if block_size > 5 | ||
| raise StandardError.new('The maximum bock size is 5 rooms.') | ||
| elsif block_size < 2 | ||
| raise StandardError.new('The minimum block size is 2 rooms.') | ||
| end | ||
|
|
||
| end | ||
|
|
||
| def calculate_cost | ||
| duration = Integer(check_out- check_in) | ||
| reservation_cost = duration * (RATE * RATE_DISCOUNT) | ||
| return reservation_cost | ||
| end | ||
|
|
||
|
|
||
|
|
||
| end # end of block | ||
| end # end of module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| require 'date' | ||
| require 'pry' | ||
|
|
||
| module Hotel | ||
| class HotelManager | ||
|
|
||
| attr_reader :room_list | ||
| attr_accessor :reservations | ||
|
|
||
| def initialize | ||
| @room_list = load_rooms | ||
| @reservations = Array.new | ||
| # puts "A new hotel manager has been created." | ||
| end | ||
|
|
||
| def load_rooms | ||
| room_list = Array(1..20) | ||
| return room_list | ||
| end | ||
|
|
||
| def get_reservation_id | ||
|
|
||
| if @reservations == [] | ||
| next_reservation_id = 1 | ||
| # puts "The next reservation will be #{next_reservation_id}" | ||
| return next_reservation_id | ||
| else | ||
| next_reservation_id = @reservations.length + 1 | ||
| # puts "The next reservation will be #{next_reservation_id}" | ||
| return next_reservation_id | ||
| end | ||
| end | ||
|
|
||
| def reservations_by_date(date) | ||
| reservation_list = [] | ||
| @reservations.each do |reservation| | ||
| if reservation.stay_date_list.include?(date) | ||
| reservation_list << reservation | ||
| end | ||
| end | ||
| return reservation_list | ||
| end | ||
|
|
||
| def find_available_rooms(start_date, end_date) | ||
| potential_dates = (start_date..(end_date - 1)).to_a | ||
| unavailable_rooms = [] | ||
| @reservations.each do |reservation| | ||
| date_check_list = reservation.stay_date_list | ||
| checked_date_list = date_check_list - potential_dates | ||
| if checked_date_list.length < date_check_list.length | ||
| unavailable_rooms << reservation.room_id | ||
| end | ||
| end | ||
|
|
||
| if unavailable_rooms.length == 20 | ||
| raise StandardError.new('There are no available rooms at this time.') | ||
| elsif unavailable_rooms.length > 0 | ||
| available_rooms = @room_list - unavailable_rooms | ||
| else | ||
| available_rooms = @room_list | ||
| end | ||
| return available_rooms | ||
| end | ||
|
|
||
| def get_available_room(check_in_date, check_out_date) | ||
| potential_rooms = find_available_rooms(check_in_date, check_out_date) | ||
| next_room_id = potential_rooms.first | ||
| # puts "the next room id will be #{next_room_id}" | ||
| return next_room_id | ||
| end | ||
|
|
||
| def add_reservation(check_in_date, check_out_date) | ||
| new_reservation = Hotel::Reservation.new({reservation_id: get_reservation_id, room_id: get_available_room(check_in_date, check_out_date), check_in: check_in_date, check_out: check_out_date}) | ||
| @reservations.push(new_reservation) | ||
| # puts "the new reservation is #{new_reservation}." | ||
| return new_reservation | ||
| end | ||
|
|
||
| def add_block(block_size, check_in_date, check_out_date) | ||
| new_block = Hotel::Block.new({reservation_id: get_reservation_id, block_size: block_size, check_in: check_in_date, check_out: check_out_date}) | ||
| @reservations.push(new_block) | ||
| end | ||
|
|
||
| end # end of class | ||
| end # end of module | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| require 'date' | ||
| require 'pry' | ||
|
|
||
| module Hotel | ||
| class Reservation | ||
|
|
||
| RATE = 200.00 | ||
|
|
||
| attr_accessor :reservation_id, :room_id, :check_in, :check_out | ||
|
|
||
| def initialize(input) | ||
| @reservation_id = input[:reservation_id] | ||
| @room_id = input[:room_id] | ||
| @check_in = input[:check_in] | ||
| @check_out = input[:check_out] | ||
|
|
||
| if check_in == check_out | ||
| raise StandardError.new('The start date and the end date cannot be the same date.') | ||
| elsif check_in > check_out | ||
| raise StandardError.new('The end date cannot be before the start date.') | ||
| end | ||
|
|
||
| end | ||
|
|
||
| def stay_date_list | ||
| list_of_dates = (@check_in..@check_out).to_a | ||
| list_of_dates = list_of_dates[0..-2] | ||
| return list_of_dates | ||
| end | ||
|
|
||
| def calculate_cost | ||
| duration = Integer(check_out- check_in) | ||
| reservation_cost = duration * RATE | ||
| return reservation_cost | ||
| end | ||
|
|
||
| end # end of class | ||
| end # end of module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| require_relative "spec_helper.rb" | ||
|
|
||
| describe 'block' do | ||
| describe 'initialize' do | ||
| it 'instantiates the class properties as the correct class type' do | ||
| input = {reservation_id: 1, block_size: 2, check_in: Date.new(2018, 7, 06), check_out: Date.new(2018, 7, 10)} | ||
| @new_block = Hotel::Block.new(input) | ||
|
|
||
| @new_block.reservation_id.must_be_kind_of Integer | ||
| @new_block.block_size.must_be_kind_of Integer | ||
| @new_block.check_in.must_be_kind_of Date | ||
| @new_block.check_out.must_be_kind_of Date | ||
| @new_block.reserved_rooms.must_be_kind_of Array | ||
| end | ||
|
|
||
| it 'raises an error if provided an invalid date range' do | ||
|
|
||
| # the start and end dates are the same | ||
| proc{ | ||
| @new_block = Hotel::Block({reservation_id: 1, block_size: 2, check_in: Date.new(2018, 5, 25), check_out: Date.new(2018, 5, 25)}) | ||
| }.must_raise StandardError | ||
|
|
||
| # the start date is after the end date | ||
| proc{ | ||
| @new_block1 = Hotel::Block({reservation_id: 1, block_size: 2, check_in: Date.new(2018, 5, 25), check_out: Date.new(2018, 5, 19)}) | ||
| }.must_raise StandardError | ||
| end | ||
|
|
||
| it 'raises an error if provided an invalid block size' do | ||
|
|
||
| proc{ | ||
| @new_block = Hotel::Block({reservation_id: 1, block_size: 6, check_in: Date.new(2018, 5, 25), check_out: Date.new(2018, 5, 26)}) | ||
| }.must_raise StandardError | ||
|
|
||
| proc{ | ||
| @new_block = Hotel::Block({reservation_id: 1, block_size: 1, check_in: Date.new(2018, 5, 25), check_out: Date.new(2018, 5, 26)}) | ||
| }.must_raise StandardError | ||
| end | ||
| end # end of describe initialize | ||
|
|
||
| describe 'calculate_cost' do | ||
| it 'calculates cost based on block rate not reservation rate' do | ||
| input = {reservation_id: 1, block_size: 2, check_in: Date.new(2018, 7, 06), check_out: Date.new(2018, 7, 10)} | ||
| @new_block = Hotel::Block.new(input) | ||
|
|
||
| @new_block.calculate_cost.must_equal 640 | ||
| end | ||
| end | ||
|
|
||
|
|
||
| end # end of describe Block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| require_relative "spec_helper.rb" | ||
|
|
||
| describe 'HotelManager' do | ||
| describe 'initialize' do | ||
| before do | ||
| @new_hotel = Hotel::HotelManager.new | ||
| end | ||
| it 'can create a new instance of HotelManager' do | ||
| @new_hotel.must_be_instance_of Hotel::HotelManager | ||
| end # end of can create new instance | ||
|
|
||
| # it 'can call class properties when instantiated' do | ||
| # [room_list, reservations].each do |prop| | ||
| # @new_hotel.must_respond_to prop | ||
| # end | ||
| # end | ||
|
|
||
| it 'instantiates the properties correctly' do | ||
| @new_hotel.room_list.must_be_kind_of Array | ||
| @new_hotel.reservations.must_be_kind_of Array | ||
| @new_hotel.reservations.length.must_equal 0 | ||
| end | ||
| end # end of describe initialize | ||
|
|
||
| describe 'load_rooms' do | ||
| it 'correctly creates room_list array' do | ||
| @new_hotel = Hotel::HotelManager.new | ||
| @new_hotel.room_list.length.must_equal 20 | ||
| end | ||
| end # end of describe load_rooms | ||
|
|
||
| describe 'get_reservation_id' do | ||
| it 'correctly generates the next reservation_id when no reservations' do | ||
| @new_hotel = Hotel::HotelManager.new | ||
| @new_hotel.reservations.length.must_equal 0 | ||
| @new_hotel.get_reservation_id.must_equal 1 | ||
| end | ||
| it 'correctly generates the next reservation_id when reservations already exist' do | ||
| @new_hotel = Hotel::HotelManager.new | ||
| @new_hotel.reservations = [1, 2, 3] | ||
| @new_hotel.reservations.length.must_equal 3 | ||
| @new_hotel.get_reservation_id.must_equal 4 | ||
| end | ||
|
|
||
| end # end of describe 'get_reservation_id' | ||
|
|
||
| describe 'get_available_room' do | ||
| it 'must return an appropriate room id' do | ||
| @new_hotel = Hotel::HotelManager.new | ||
| @start_date = Date.new(2018, 5, 26) | ||
| @end_date = Date.new(2018, 5, 28) | ||
| room_id = @new_hotel.get_available_room(@start_date, @end_date) | ||
| room_id.must_be_kind_of Integer | ||
| room_id.must_be :>, 0 | ||
| room_id.must_be :<, 21 | ||
| end | ||
| end # end of get_available_room | ||
|
|
||
| describe 'add_reservation' do | ||
| it 'creates an instance of Reservation' do | ||
| @new_hotel = Hotel::HotelManager.new | ||
|
|
||
| @new_hotel.add_reservation(Date.new(2018, 3, 25), Date.new(2018, 3, 28)).must_be_instance_of Hotel::Reservation | ||
| end | ||
|
|
||
| it 'adds the reservation to array of reservations' do | ||
| @new_hotel = Hotel::HotelManager.new | ||
| @new_hotel.reservations.length.must_equal 0 | ||
| @new_hotel.add_reservation(Date.new(2018, 3, 25), Date.new(2018, 3, 28)) | ||
| @new_hotel.reservations.length.must_equal 1 | ||
| end | ||
| end # end of describe add_reservation | ||
|
|
||
| describe 'reservations_by_date' do | ||
| before do | ||
| @overlap_date = Date.new(2018, 5, 26) | ||
| @new_hotel = Hotel::HotelManager.new | ||
|
|
||
| # Two should contain the overlap date | ||
| @new_hotel.add_reservation(@overlap_date - 1, @overlap_date + 1) | ||
| @new_hotel.add_reservation(@overlap_date - 5, @overlap_date + 3) | ||
|
|
||
| # One should not | ||
| @new_hotel.add_reservation(@overlap_date - 20, @overlap_date - 15) | ||
| # puts "This is to check what is in #{@new_hotel}" | ||
| end | ||
|
|
||
| it 'returns an array of reservations for a specific date' do | ||
| # binding.pry | ||
| reservation_list = @new_hotel.reservations_by_date(@overlap_date) | ||
| reservation_list.must_be_instance_of Array | ||
| reservation_list.length.must_equal 2 | ||
| reservation_list.each do |res| | ||
| res.must_be_instance_of Hotel::Reservation | ||
| end | ||
| end | ||
|
|
||
| end # end of describe reservations_by_date | ||
|
|
||
| describe 'find_available_rooms' do | ||
|
|
||
| it 'returns correct size list when 1 overlapping date' do | ||
| @begin_date = Date.new(2018, 5, 26) | ||
| @end_date = Date.new(2018, 5, 28) | ||
| @new_hotel = Hotel::HotelManager.new | ||
|
|
||
| # one reservation should affect returned array | ||
| @new_hotel.add_reservation(@begin_date - 2, @end_date + 3) | ||
| @new_hotel.add_reservation(@begin_date + 45, @end_date + 47) | ||
| @new_hotel.find_available_rooms(@begin_date, @end_date).length.must_equal 19 | ||
| end | ||
|
|
||
| it 'returns correct size list when no overlapping dates' do | ||
| @begin_date = Date.new(2018, 5, 26) | ||
| @end_date = Date.new(2018, 5, 28) | ||
| @new_hotel = Hotel::HotelManager.new | ||
| # neither reservation should affect returned array | ||
| @new_hotel.add_reservation(@begin_date - 20, @end_date - 15) | ||
| @new_hotel.add_reservation(@begin_date + 45, @end_date + 47) | ||
| @new_hotel.find_available_rooms(@begin_date, @end_date).length.must_equal 20 | ||
| end | ||
|
|
||
| it 'raises an error if there are no available rooms' do | ||
| proc{ | ||
| @new_hotel = Hotel::HotelManager.new | ||
| check_in_date = Date.new(2018, 3, 12) | ||
| check_out_date = Date.new(2018, 3, 20) | ||
| 21.times do | ||
| @new_hotel.add_reservation(check_in_date, check_out_date) | ||
| end | ||
| @new_hotel.find_available_rooms(Date.new(2018, 3, 12), Date.new(2018, 3, 20)) | ||
| }.must_raise StandardError | ||
| end | ||
| end # end of describe find_available_rooms | ||
|
|
||
| end # end of describe HotelManager | ||
|
|
||
|
|
||
|
|
||
| # Two should contain the overlap date | ||
| # @new_hotel.add_reservation(@begin_date - 1, @overlap_date + 1) | ||
| # @new_hotel.add_reservation(@begin_date- 5, @end_date + 3) | ||
| # | ||
| # # One should not | ||
| # @new_hotel.add_reservation(@begin_date - 20, @end_date - 15) | ||
|
|
||
| # check_in_date = Date.new(2018, 4, 15) | ||
| # check_out_date = Date.new(2018, 4, 24) | ||
| # @new_hotel.add_reservation(check_in_date, check_out_date) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 else logic will actually still work if the array is empty so you don't need the conditional