-
Notifications
You must be signed in to change notification settings - Fork 45
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
Jamila Cornick Octos #35
base: master
Are you sure you want to change the base?
Changes from 8 commits
caedc6b
887bde8
1599475
f389763
e5a283f
ffc7cab
44a7cf9
0585303
a723dc1
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require_relative 'reservation' | ||
require_relative 'hotel_room' | ||
# require 'pry' | ||
|
||
module Hotel | ||
class Administrator | ||
attr_reader :room_list, :reservation_list | ||
|
||
def initialize | ||
@room_list = all_rooms | ||
@reservation_list = [] | ||
|
||
if reservation_list == [] | ||
puts "All rooms are available for reservation." | ||
end | ||
end | ||
|
||
def available_rooms | ||
rm_nums = [] | ||
@room_list.each do |room| | ||
if room.status == nil || room.status == :AVAILABLE | ||
rm_nums << room.rm_number | ||
end | ||
puts rm_nums | ||
return rm_nums | ||
end | ||
end | ||
|
||
def reserved_rooms(res_list, new_res) | ||
res_list.each do |reservation| | ||
if new_res.start_date == reservation.end_date | ||
reservation.room.each do |unit| | ||
unit.status = :AVAILABLE | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
# can create reservation | ||
def new_reservation(name, start_res, end_res) | ||
# this method should add the newly created reservation to reservation_list | ||
while @reservation_list == [] | ||
new_res = Hotel::Reservation.new(guest: name, start_date: start_res, end_date: end_res) | ||
@reservation_list << new_res | ||
end | ||
new_res = Hotel::Reservation.new(guest: name, start_date: start_res, end_date: end_res) | ||
reserved_rooms(@reservation_list, new_res) | ||
@reservation_list << new_res | ||
return new_res | ||
end | ||
|
||
|
||
|
||
|
||
# can see total cost of a reservation | ||
def reservation_cost(res_name) | ||
@reservation_list.each do |reservation| | ||
if reservation.guest == res_name | ||
res_cost = reservation.total_cost | ||
# puts res_cost | ||
return res_cost | ||
elsif reservation.guest != res_name | ||
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. What will happen with this if the reservation you're looking for is the second in the list? (hint: unexpected behavior) |
||
return ' Sorry! We do not have your reservation on file. Please contact customer service.' | ||
end | ||
end | ||
end | ||
|
||
def all_rooms | ||
rooms = [] | ||
20.times do |count| | ||
room = Hotel::HotelRoom.new(count) | ||
# room.rm_number = count | ||
|
||
rooms << room | ||
end | ||
return rooms | ||
end | ||
|
||
end #class end | ||
end | ||
|
||
# puts Hotel::Administrator.new.room_list |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require_relative 'administrator' | ||
module Hotel | ||
class Date | ||
# What would this class do? | ||
# I think validate everything to do with dates. | ||
# What would it need to do that? | ||
# dates from made reservations | ||
# to get access to those dates need the reservation list | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# require 'pry' | ||
module Hotel | ||
class HotelRoom | ||
attr_accessor :rm_number, :status | ||
attr_reader :cost_pr_day | ||
# need to refactor this so it is using hash ? make the data clearer | ||
def initialize(rm_number) | ||
@rm_number = rm_number | ||
@cost_pr_day = 200 | ||
@status = nil | ||
end | ||
|
||
def change_status | ||
@status = :UNAVAILABLE | ||
end | ||
end | ||
end | ||
|
||
|
||
|
||
|
||
|
||
# def all_rooms | ||
# | ||
# rooms = [] | ||
# 20.times do |count| | ||
# room = Hotel::HotelRoom.new(count) | ||
# @rm_number = count | ||
# | ||
# rooms << room | ||
# end | ||
# return rooms | ||
# end | ||
|
||
# room = Hotel::HotelRoom | ||
# puts room | ||
|
||
# binding.pry | ||
# @room = { | ||
# rm_number: count, cost_pr_day: 200, status: :AVILABLE | ||
# } | ||
|
||
# @rm_number = rm_number | ||
# @cost_pr_day = 200 | ||
# @status = :AVILABLE | ||
|
||
|
||
# def all_rooms | ||
# rooms = [] | ||
# 20.times do | ||
# rooms << HotelRoom.new | ||
# end | ||
# return room | ||
# | ||
# end | ||
|
||
# def room_generator | ||
# all_rooms = [] | ||
# count = 1 | ||
# | ||
# 20.times do | ||
# a_room = {} | ||
# a_room[:rm_number] = count | ||
# a_room[:cost_pr_day] = 200 | ||
# a_room[:status] = :AVILABLE | ||
# | ||
# count += 1 | ||
# | ||
# room = HotelRoom.new() | ||
# end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require_relative 'hotel_room' | ||
require 'date' | ||
# require_relative 'administrator' | ||
module Hotel | ||
class Reservation | ||
attr_reader :guest, :total_cost | ||
attr_accessor :start_date, :end_date, :room | ||
|
||
def initialize(guest:, start_date:, end_date:) | ||
@guest = guest | ||
@start_date = Date.parse(start_date) | ||
@end_date = Date.parse(end_date) | ||
# code from date class to validate dates should go here? | ||
# this code bit can be moved into a date class maybe? | ||
# generate a random room num based on whats available for the timeframe | ||
@room = open_rooms(1) | ||
@total_cost = stay_price | ||
if @end_date < @start_date | ||
raise StandardError.new('Invalid reservation dates!') | ||
end | ||
end | ||
|
||
def stay_price | ||
res_start = @start_date | ||
res_end = @end_date | ||
cost = ((res_end.mday - res_start.mday) - 1) * 200 | ||
return cost | ||
end | ||
|
||
def open_rooms(num_of_rooms) | ||
reserved_units = [] | ||
admin = Hotel::Administrator.new | ||
rm_units = admin.room_list | ||
(num_of_rooms).times do | ||
reserved_unit = rm_units.sample | ||
if reserved_unit.status == :UNAVAILABLE | ||
while reserved_unit.status == :UNAVAILABLE | ||
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. Why do you need an |
||
reserved_unit = rm_units.sample | ||
end | ||
end | ||
reserved_unit.change_status | ||
reserved_units << reserved_unit | ||
end | ||
return reserved_units | ||
end | ||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require_relative 'spec_helper' | ||
|
||
describe 'Administrator class' do | ||
it "creates an array of rooms" do | ||
admin = Hotel::Administrator.new | ||
|
||
admin.room_list.must_be_kind_of Array | ||
|
||
end | ||
|
||
it "can access individual rooms" do | ||
admin = Hotel::Administrator.new | ||
|
||
rm_1 = admin.room_list | ||
rm_2 = rm_1 | ||
|
||
rm_1[0].rm_number.must_equal 0 | ||
rm_2[1].rm_number.must_equal 1 | ||
|
||
|
||
end | ||
|
||
it "can access a list of reservations" do | ||
admin = Hotel::Administrator.new | ||
|
||
admin.reservation_list.must_be_kind_of Array | ||
|
||
end | ||
|
||
it "reservation_list contains instances of reservation" do | ||
# this also checks the new_reservation method because if it didnt work | ||
# the reservation list would be empty. | ||
admin = Hotel::Administrator.new | ||
admin.new_reservation('Liam', '18th April 2018 ', '22nd April 2018') | ||
admin.new_reservation( 'Mikaila', '12th December 2018','18th December 2018') | ||
|
||
admin.reservation_list.sample.must_be_instance_of Hotel::Reservation | ||
|
||
end | ||
|
||
it "can get total_cost" do | ||
admin = Hotel::Administrator.new | ||
admin.new_reservation( 'Mikaila', '12th December 2018','18th December 2018') | ||
admin.new_reservation('Liam', '18th April 2018 ', '22nd April 2018') | ||
admin.new_reservation('Miclah', '9th March 2018 ', '11th March 2018') | ||
|
||
|
||
name = 'Mikaila' | ||
name_1 = 'Mikah' | ||
|
||
admin.reservation_cost(name).must_equal 1000 | ||
admin.reservation_cost(name_1).must_equal ' Sorry! We do not have your reservation on file. Please contact customer service.' | ||
|
||
end | ||
|
||
it "can assign rervations with overlapping dates" do | ||
admin = Hotel::Administrator.new | ||
res_1 = admin.new_reservation('Liam', '18th April 2018 ', '22nd April 2018') | ||
res_2 = admin.new_reservation( 'Mikaila', '12th December 2018','18th December 2018') | ||
res_3 = admin.new_reservation('Miclah', '18th March 2018 ', '22nd March 2018') | ||
|
||
admin.reservation_list.must_include res_2 | ||
admin.reservation_list.must_include res_3 | ||
admin.reservation_list.must_include res_1 | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require_relative 'spec_helper' | ||
|
||
describe 'hotel_room class' do | ||
it "creates an instance of a room" do | ||
room = Hotel::HotelRoom.new(17) | ||
|
||
room.must_be_instance_of Hotel::HotelRoom | ||
|
||
end | ||
|
||
it "has a cost and room number" do | ||
room = Hotel::HotelRoom.new(20) | ||
|
||
room.rm_number.must_be_kind_of Integer | ||
room.cost_pr_day.must_equal 200 | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require_relative 'spec_helper' | ||
|
||
|
||
describe 'Reservation class' do | ||
it "creates a reservation" do | ||
reservation = Hotel::Reservation.new( | ||
guest: 'John', start_date: '8th March 2018', end_date: '10th March 2018' | ||
) | ||
|
||
reservation.must_be_instance_of Hotel::Reservation | ||
|
||
end | ||
|
||
it "the reservation must have a room" do | ||
reservation = Hotel::Reservation.new( | ||
guest: 'Malcom', start_date: '12th May 2018', end_date: '14th May 2018' | ||
) | ||
|
||
room = reservation.room | ||
|
||
room[0].must_be_instance_of Hotel::HotelRoom | ||
|
||
end | ||
|
||
it "the reservation must have a start and end" do | ||
reservation = Hotel::Reservation.new( | ||
guest: 'Terri', start_date: '8th April 2018', end_date: '12th April 2018' | ||
) | ||
|
||
reservation.start_date.mday.must_equal 8 | ||
reservation.end_date.mday.must_equal 12 | ||
|
||
end | ||
|
||
it "the reservation must have a total cost" do | ||
reservation = Hotel::Reservation.new( | ||
guest: 'Asrah', start_date: '6th October 2018', end_date: '9th October 2018' | ||
) | ||
|
||
reservation.total_cost.must_equal 400 | ||
|
||
end | ||
|
||
it "handles invalid start date and end_date" do | ||
proc { | ||
Hotel::Reservation.new(guest: 'Asrah', start_date: '9th October 2018', end_date: '6th October 2018') | ||
}.must_raise StandardError | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'simplecov' | ||
SimpleCov.start | ||
# require 'time' | ||
# require 'date' | ||
require 'minitest' | ||
require 'minitest/autorun' | ||
require 'minitest/reporters' | ||
# add my spec files as i create them for each class | ||
require_relative '../lib/reservation' | ||
require_relative '../lib/hotel_room' | ||
require_relative '../lib/administrator' | ||
# require_relative '../lib/' | ||
|
||
|
||
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new |
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.
How would this code path be executed where this conditional is false?