From 8f9a474b84f690bb858826f5f1213d92d3294651 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Mon, 5 Mar 2018 12:28:05 -0800 Subject: [PATCH 01/21] Ignore git file for converage --- specs/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 specs/.gitignore diff --git a/specs/.gitignore b/specs/.gitignore new file mode 100644 index 000000000..4ebc8aea5 --- /dev/null +++ b/specs/.gitignore @@ -0,0 +1 @@ +coverage From 9f24be4e1370c4532f2c649108731b67d444f30e Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Mon, 5 Mar 2018 12:35:49 -0800 Subject: [PATCH 02/21] All the ruby and spec files have been created for my hotel project. --- .DS_Store | Bin 0 -> 6148 bytes Rakefile | 9 +++++++++ lib/admin.rb | 17 +++++++++++++++++ lib/customer.rb | 12 ++++++++++++ lib/reservation.rb | 12 ++++++++++++ lib/room.rb | 12 ++++++++++++ specs/.gitignore | 1 - specs/admin_spec.rb | 1 + specs/customer_spec.rb | 1 + specs/reservation_spec.rb | 1 + specs/room_spec.rb | 1 + specs/spec_helper.rb | 14 ++++++++++++++ 12 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 Rakefile create mode 100644 lib/admin.rb create mode 100644 lib/customer.rb create mode 100644 lib/reservation.rb create mode 100644 lib/room.rb delete mode 100644 specs/.gitignore create mode 100644 specs/admin_spec.rb create mode 100644 specs/customer_spec.rb create mode 100644 specs/reservation_spec.rb create mode 100644 specs/room_spec.rb create mode 100644 specs/spec_helper.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3a8d8a31d01441a7ee1eda55993b65bbb124a508 GIT binary patch literal 6148 zcmeHK!EVz)5S>lZcAW~511cPS>8(PETB&eAG9f+mfP^q=D;3n*aiA8iH;Nr12tob} z_yq2J1fRg?z?BE zcrgmw;L50YQVeaapYbqDi?ZGRC2IA?%IcbwP1(HDd=s9jNmxeZxadZsWA43(%Cp$o zuawFz>?l4+2a}W5y=N*fqck6kbaI*u5c2vk%@Z~0s&Sqax=v^Yr1YeB(%P6#JCC;f z-JRK%Kiz%21GBw7n|bp7X6MQN>G{V`)6cUnUwJ0j*Lp@U?&|Jk^9`n@;6pgdGnK!C zhoe1uNqh8^dh{H~e}%uO6yFgwPvr^~G{ge*saT{_lm26lbR;@)3^)cH1J`H3zS`va z^-H-5jseHOEn|S+4?dJJuvi(?uMRZ&3IJ@ttpzrJEOL%-F|b$}#0W%~RG>)}_KG1) zI{dzk3oKR!O*#pC`4INW!roAXemd&=I-Epc(6x>M$G{>3b<=I}`M>w?`~PB+>p2D- z1GkC+(ddP}E~aG9)}_huS?fbjp)4F%8N5h=p^sw3@=^Q%ss( Date: Tue, 6 Mar 2018 16:04:20 -0800 Subject: [PATCH 03/21] Created the instance initialize method and also the test for the method. --- lib/room.rb | 25 ++++++++++++++++++++----- specs/room_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 0feed1220..2d415a991 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,12 +1,27 @@ module Hotel -class Room - attr_reader + class Room + attr_reader :room_num, :cost, :status - def initialize + ROOM_NUMBER = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + ROOM_COST = 200.00 - end + def initialize(room_num) + unless ROOM_NUMBER.include? room_num + raise ArgumentError.new("Invalid room number #{room_num}") + end -end # end of Room class + @room_num = room_num + @cost = ROOM_COST + + + # @status = input[:status] == nil ? :AVAILABLE : input[:status] + end + + # def add_reservation(reservation) + # @reservation << reservation + # end + + end # end of Room class end # end of Hotel module diff --git a/specs/room_spec.rb b/specs/room_spec.rb index ae9c220ea..27e8d6008 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1 +1,22 @@ require_relative 'spec_helper' + +describe "Room class" do + describe "You can create a Room instance" do + + it "Can be created" do + (1..20).each do |value| + room = Hotel::Room.new(1) + room.must_be_instance_of Hotel::Room + end + end + + + it "Raises an ArgumentError for invalid parameters" do + proc {Hotel::Room.new(0)}.must_raise ArgumentError + proc {Hotel::Room.new(21)}.must_raise ArgumentError + end + + + + end # end of describe "You can create a Room instance" +end # describe "Admin class" From a567f32c9db585f98f06b9d87038e66e56ea69a6 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Wed, 7 Mar 2018 16:58:14 -0800 Subject: [PATCH 04/21] Revised room.rb and room_spec.rb to only list the iindividual rooms and cost for one room. The test passed successfully. --- lib/room.rb | 21 +++++++++++---------- specs/room_spec.rb | 17 ++++++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index 2d415a991..fad932f5c 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,22 +1,23 @@ +require 'pry' module Hotel class Room - attr_reader :room_num, :cost, :status + attr_reader :room_num, :cost, :reservation ROOM_NUMBER = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] ROOM_COST = 200.00 - def initialize(room_num) - - unless ROOM_NUMBER.include? room_num - raise ArgumentError.new("Invalid room number #{room_num}") - end - - @room_num = room_num + def initialize(number) + @room_num = hotel_room(number) @cost = ROOM_COST + # @reservation = reservation + end - - # @status = input[:status] == nil ? :AVAILABLE : input[:status] + def hotel_room(number) + unless ROOM_NUMBER.include? number + raise ArgumentError.new("Invalid room number #{number}") + end + @room_num = number end # def add_reservation(reservation) diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 27e8d6008..420be5c7f 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -4,19 +4,22 @@ describe "You can create a Room instance" do it "Can be created" do - (1..20).each do |value| - room = Hotel::Room.new(1) - room.must_be_instance_of Hotel::Room - end + room = Hotel::Room.new(1) + room.must_be_instance_of Hotel::Room end + it "Correcty initialize with the cost per room" do + room_cost = Hotel::Room.new(9) + room_cost.cost.must_equal 200 + end + + end # end of describe "You can create a Room instance" + describe "hotel room method" do it "Raises an ArgumentError for invalid parameters" do proc {Hotel::Room.new(0)}.must_raise ArgumentError proc {Hotel::Room.new(21)}.must_raise ArgumentError end + end # end of describe "hotel room method" - - - end # end of describe "You can create a Room instance" end # describe "Admin class" From 13943bba39500fef7c52f790bfcfaab2f9e709f1 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Thu, 8 Mar 2018 15:36:05 -0800 Subject: [PATCH 05/21] updated the spec_helper file to include the updated SimpleCov code and the new request to help skip tests. Also, udpated the room.rb and spec file to take in a room rate so that it can be changed if needed to be later. --- lib/room.rb | 16 ++++------------ specs/room_spec.rb | 18 +++++++++++------- specs/spec_helper.rb | 6 ++++-- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index fad932f5c..79d1e7b48 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -2,27 +2,19 @@ module Hotel class Room - attr_reader :room_num, :cost, :reservation + attr_reader :room_num, :rate - ROOM_NUMBER = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] - ROOM_COST = 200.00 - - def initialize(number) + def initialize(number, rate) @room_num = hotel_room(number) - @cost = ROOM_COST - # @reservation = reservation + @rate = rate end def hotel_room(number) - unless ROOM_NUMBER.include? number + unless (1..20).include? number raise ArgumentError.new("Invalid room number #{number}") end @room_num = number end - # def add_reservation(reservation) - # @reservation << reservation - # end - end # end of Room class end # end of Hotel module diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 420be5c7f..0553bb9f0 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1,25 +1,29 @@ require_relative 'spec_helper' describe "Room class" do - describe "You can create a Room instance" do + describe "initialize" do - it "Can be created" do - room = Hotel::Room.new(1) + it "you can create a Room instance" do + room = Hotel::Room.new(1, 200) room.must_be_instance_of Hotel::Room end - it "Correcty initialize with the cost per room" do - room_cost = Hotel::Room.new(9) - room_cost.cost.must_equal 200 + it "reads the room number" do + room = Hotel::Room.new(9, 200) + room.must_respond_to :room_num + room.room_num.must_equal 9 + room.room_num.must_be_kind_of Integer end end # end of describe "You can create a Room instance" describe "hotel room method" do - it "Raises an ArgumentError for invalid parameters" do + + it "raises an ArgumentError for invalid room numbers" do proc {Hotel::Room.new(0)}.must_raise ArgumentError proc {Hotel::Room.new(21)}.must_raise ArgumentError end + end # end of describe "hotel room method" end # describe "Admin class" diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 88e49bffd..5f906ac60 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -1,14 +1,16 @@ require 'simplecov' -SimpleCov.start +SimpleCov.start do + add_filter "/specs/" +end require 'date' require 'minitest' require 'minitest/autorun' require 'minitest/reporters' +require 'minitest/skip_dsl' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new require_relative '../lib/admin' -require_relative '../lib/customer' require_relative '../lib/reservation' require_relative '../lib/room' From 9c841ad20782e3a67d58cf6de39456a6e032a43e Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Thu, 8 Mar 2018 16:12:16 -0800 Subject: [PATCH 06/21] Updated room spec to include a test on the rate method. --- specs/room_spec.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 0553bb9f0..28422e581 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -11,8 +11,15 @@ it "reads the room number" do room = Hotel::Room.new(9, 200) room.must_respond_to :room_num - room.room_num.must_equal 9 room.room_num.must_be_kind_of Integer + room.room_num.must_equal 9 + end + + it "reads the rate of the room" do + room = Hotel::Room.new(9, 200) + room.must_respond_to :rate + room.rate.must_be_instance_of Integer + room.rate.must_equal 200 end end # end of describe "You can create a Room instance" From cb636461a7363c074e6f55df06947089753693a3 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Thu, 8 Mar 2018 17:22:32 -0800 Subject: [PATCH 07/21] Updated the initialize method for the admin rile and admin spec file. --- lib/admin.rb | 44 ++++++++++++++++++++++++++++++++------ specs/admin_spec.rb | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index f00bf32dd..92baad4fb 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -1,17 +1,47 @@ require 'date' +require 'pry' +require 'awesome_print' -require_relative 'customer' require_relative 'reservation' require_relative 'room' -module Hotel -class Admin - attr_reader +module Hotel + class Admin + attr_reader :rooms, :reservations - def initialize + def initialize + @rooms = list_of_rooms + @reservations = [] + end - end + def list_rooms + @room + end -end # end of Admin class + def add_reservation(check_in, check_out) + + end + + + def list_reservations(date) + + end + + + def total_cost(reservation) + + end + + private + + def list_of_rooms + rooms = [] + (1..20).to_a.each do |num| + rooms << Hotel::Room.new(num, 200) + end + return rooms + end + + end # end of Admin class end # end of Hotel module diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index ae9c220ea..bdcd684d8 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -1 +1,53 @@ require_relative 'spec_helper' + +describe "Admin class" do + describe "Initializer" do + + it "must be an instance of admin" do + admin = Hotel::Admin.new + admin.must_be_instance_of Hotel::Admin + end + + it "creates a list of all 20 rooms" do + admin = Hotel::Admin.new + + admin.must_respond_to :rooms + admin.rooms.must_be_kind_of Array + admin.rooms.length.must_equal 20 + admin.rooms.each do |room| + room.must_be_instance_of Hotel::Room + end + end + + it "creates a reservation" do + admin = Hotel::Admin.new + + admin.must_respond_to :reservations + admin.reservations.must_be_kind_of Array + admin.reservations.length.must_equal 0 + + end + + end # end of describe "Initializer" + + + def "list_rooms method" do + + end + + + def "add_reservation(check_in, check_out) method" do + + end + + + def "list_reservations(date)" do + + end + + + def "total_cost(reservation)" do + + end + +end # describe "Admin class" From ad281576ad53cf3ec57c3fe8252fd7237cf31667 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Thu, 8 Mar 2018 18:04:52 -0800 Subject: [PATCH 08/21] Udpated the initialize for reservation Ruby filea and spec file. --- .DS_Store | Bin 6148 -> 6148 bytes lib/.DS_Store | Bin 0 -> 6148 bytes lib/admin.rb | 2 +- lib/customer.rb | 12 ------------ lib/reservation.rb | 18 +++++++++++------- lib/room.rb | 1 - specs/.DS_Store | Bin 0 -> 6148 bytes specs/admin_spec.rb | 12 ++++++------ specs/customer_spec.rb | 1 - specs/reservation_spec.rb | 18 ++++++++++++++++++ specs/room_spec.rb | 11 +++++------ specs/spec_helper.rb | 1 + 12 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 lib/.DS_Store delete mode 100644 lib/customer.rb create mode 100644 specs/.DS_Store delete mode 100644 specs/customer_spec.rb diff --git a/.DS_Store b/.DS_Store index 3a8d8a31d01441a7ee1eda55993b65bbb124a508..01d6d7b5beb4321004a69254bbeea7ff07566ca0 100644 GIT binary patch delta 344 zcmZoMXfc=|#>B!ku~2NHo}wrh0|Nsi1A_nqLlHwFLpnpMXHI_d=7Y@3nGHcw91O_} z`3z+YsmRhvIr&LIIiMb(P6md}|G|KPVKNU>A>)b3bxaK!;?>oL7CH*XCWf^-3f1P8 zCOQfx#%8s(oE+k+hPIvwxs_GbHMMm!CaW^bYtIB4!pxAvkjao#7F?8B)qu~2NHo}wrl0|Nsi1A_nqLlQ$GLo!1)gC0Zf#=_-{jBJx_SPB`B zPhQ8;pe|NjZD^sRU~W>Yqfl*bX#!*#7}wTva)_%M+IlABR#sKl)YeU(e2Yz9do{JeCK9h3L4#%~tm5M-IyV6&N>gP#NFhRuQ;-Lh|siDEfkafLOS+hzMSkmx@S>9ddVhy_-7 zLGSsSW!rF$!fD1_`zz^c zX{kUekP4&%slZ_su#1h?-}zzFX0}uy6*vL~^n566iZ!rvw4;Nal>o#Mht23~Euowe zSOYsp&d|iEM5juW7~*t}mx!x@ouktsQG7_O{9U|=t`R=jOKUq8Fv?V>yLfvU0c{5*wi$xQ-?->?<0VJ^c=agNuMw3 ZGp+`9j+#ZsjZVxD0TU#Y5PhR50)7y%vD{xEq_RCiEUaxTgy`=&t_+8M&z#PqYS>*XsmVL4t{+1o} zatSy0axIkD!?;aZMbLXwJYEXxB^=R zbbkmeibcZKFm4^J;uC{$;X{{6587u7E4>#}tsk^kO>UN2Rm% z%jfA?8(6Mc)HJSDhep4531CC_k>faM<3WAK6$x8I&7%F0PV|dF6vQi6;0F|V2gwXf AlK=n! literal 0 HcmV?d00001 diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index bdcd684d8..3455f9a79 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' -describe "Admin class" do +xdescribe "Admin class" do describe "Initializer" do it "must be an instance of admin" do @@ -31,23 +31,23 @@ end # end of describe "Initializer" - def "list_rooms method" do + describe "list_rooms method" do end - def "add_reservation(check_in, check_out) method" do + describe "add_reservation(check_in, check_out) method" do end - def "list_reservations(date)" do + describe "list_reservations(date)" do end - def "total_cost(reservation)" do + describe "total_cost(reservation)" do end -end # describe "Admin class" +end # end of describe "Admin class" diff --git a/specs/customer_spec.rb b/specs/customer_spec.rb deleted file mode 100644 index ae9c220ea..000000000 --- a/specs/customer_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative 'spec_helper' diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index ae9c220ea..11685daac 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1 +1,19 @@ require_relative 'spec_helper' + +describe "Reservation class" do + describe "Initializer" do + + it "must be an instance of reservation" do + check_in_date = Date.new(2018, 4, 7) + check_out_date = Date.new(2018, 4, 21) + room_info = Hotel::Room.new(9, 200) + reserv = Hotel::Reservation.new(check_in_date, check_out_date, room_info) + reserv.must_be_instance_of Hotel::Reservation + end + + end # end of describe "Initializer" + + + + +end # end of describe "Reservation class" diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 28422e581..12165af10 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1,9 +1,9 @@ require_relative 'spec_helper' -describe "Room class" do +xdescribe "Room class" do describe "initialize" do - it "you can create a Room instance" do + it "must be an instance of Room" do room = Hotel::Room.new(1, 200) room.must_be_instance_of Hotel::Room end @@ -24,13 +24,12 @@ end # end of describe "You can create a Room instance" - describe "hotel room method" do + describe "hotel_room method" do it "raises an ArgumentError for invalid room numbers" do proc {Hotel::Room.new(0)}.must_raise ArgumentError proc {Hotel::Room.new(21)}.must_raise ArgumentError end - end # end of describe "hotel room method" - -end # describe "Admin class" + end # end of describe "hotel_room method" +end # end of describe "Room class" diff --git a/specs/spec_helper.rb b/specs/spec_helper.rb index 5f906ac60..f9d255583 100644 --- a/specs/spec_helper.rb +++ b/specs/spec_helper.rb @@ -8,6 +8,7 @@ require 'minitest/autorun' require 'minitest/reporters' require 'minitest/skip_dsl' +require 'pry' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From ad460da2458347578325a3ece7cf6a898bf58059 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Thu, 8 Mar 2018 19:14:19 -0800 Subject: [PATCH 09/21] Updated the spec file for the Reservation class. --- specs/reservation_spec.rb | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 11685daac..14aef1fca 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -2,13 +2,31 @@ describe "Reservation class" do describe "Initializer" do + before do + @check_in = Date.new(2018, 4, 7) + @check_out = Date.new(2018, 4, 21) + @room = Hotel::Room.new(9, 200) + @reservation = Hotel::Reservation.new(@check_in, @check_out, @room) + end it "must be an instance of reservation" do - check_in_date = Date.new(2018, 4, 7) - check_out_date = Date.new(2018, 4, 21) - room_info = Hotel::Room.new(9, 200) - reserv = Hotel::Reservation.new(check_in_date, check_out_date, room_info) - reserv.must_be_instance_of Hotel::Reservation + @reservation.must_be_instance_of Hotel::Reservation + end + + it "reads the check_in date" do + @reservation.must_respond_to :check_in + @reservation.check_in.must_be_kind_of Date + end + + it "reads the check_out date" do + @reservation.must_respond_to :check_out + @reservation.check_out.must_be_kind_of Date + end + + it "room must be an instance of room" do + @reservation.must_respond_to :room + @reservation.room.must_be_instance_of Hotel::Room + @reservation.room.room_num.must_equal 9 end end # end of describe "Initializer" From 1398951634255ea0bb8ce66d27629de122e6c23a Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Fri, 9 Mar 2018 16:32:44 -0800 Subject: [PATCH 10/21] Updated the reservation class and the spec file to raise an ArgumentError if an invalid date range is provided. --- lib/admin.rb | 9 +++++---- lib/reservation.rb | 10 ++++++++-- lib/room.rb | 1 + specs/admin_spec.rb | 13 +++++++++---- specs/reservation_spec.rb | 24 ++++++++++++++++++------ 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index d424022f5..85bf61362 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -14,10 +14,11 @@ def initialize @reservations = [] end - def list_rooms - @rooms - end - + # def list_rooms + # @rooms + # # binding.pry + # end + # def add_reservation(check_in, check_out) diff --git a/lib/reservation.rb b/lib/reservation.rb index 067cb6d21..cede65377 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -3,13 +3,19 @@ module Hotel class Reservation - attr_reader :check_in, :check_out, :room, :cost + attr_reader :check_in, :check_out, :room, :total_cost def initialize(check_in, check_out, room) + + # raises ArgumentError if the check_in date is before the check_out date + if check_in >= check_out + raise ArgumentError.new("Invalid check_out date: #{check_out} must be later than #{check_in}") + end + @check_in = check_in @check_out = check_out @room = room - @cost = cost + @total_cost = ((check_out - check_in) * @room.rate).to_i end end # end of Reservation class diff --git a/lib/room.rb b/lib/room.rb index da4c61051..b68ed6184 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -8,6 +8,7 @@ def initialize(number, rate) @rate = rate end + # raises ArgumentError if the room number is not between 1 and 20 def hotel_room(number) unless (1..20).include? number raise ArgumentError.new("Invalid room number #{number}") diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 3455f9a79..61f150d18 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -14,6 +14,7 @@ admin.must_respond_to :rooms admin.rooms.must_be_kind_of Array admin.rooms.length.must_equal 20 + admin.rooms.must_equal @rooms admin.rooms.each do |room| room.must_be_instance_of Hotel::Room end @@ -24,6 +25,7 @@ admin.must_respond_to :reservations admin.reservations.must_be_kind_of Array + admin.reservations.must_equal @reservations admin.reservations.length.must_equal 0 end @@ -31,10 +33,13 @@ end # end of describe "Initializer" - describe "list_rooms method" do - - end - + # describe "list_rooms method" do + # admin = Hotel::Admin.new + # + # admin.list_rooms.must_be_kind_of Array + # + # end + # describe "add_reservation(check_in, check_out) method" do diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 14aef1fca..3f77d9f5d 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -3,12 +3,19 @@ describe "Reservation class" do describe "Initializer" do before do - @check_in = Date.new(2018, 4, 7) + @check_in = Date.new(2018, 4, 14) @check_out = Date.new(2018, 4, 21) @room = Hotel::Room.new(9, 200) @reservation = Hotel::Reservation.new(@check_in, @check_out, @room) end + it "must raise an ArgumentError if the check_out date is invalid" do + check_in = Date.new(2018, 4, 12) + check_out = Date.new(2018, 4, 10) + room_1 = Hotel::Room.new(9, 200) + proc { Hotel::Reservation.new(check_in, check_out, room_1) }.must_raise ArgumentError + end + it "must be an instance of reservation" do @reservation.must_be_instance_of Hotel::Reservation end @@ -16,22 +23,27 @@ it "reads the check_in date" do @reservation.must_respond_to :check_in @reservation.check_in.must_be_kind_of Date + @reservation.check_in.must_equal @check_in end it "reads the check_out date" do @reservation.must_respond_to :check_out @reservation.check_out.must_be_kind_of Date + @reservation.check_out.must_equal @check_out end - it "room must be an instance of room" do + it "reas in the correct room information" do @reservation.must_respond_to :room @reservation.room.must_be_instance_of Hotel::Room @reservation.room.room_num.must_equal 9 + @reservation.room.rate.must_equal 200 end - end # end of describe "Initializer" - - - + it "reads in the rate and calculates the correct total cost" do + @reservation.must_respond_to :total_cost + @reservation.total_cost.must_be_kind_of Integer + @reservation.total_cost.must_equal 1400 + end + end # end of describe "Initializer" end # end of describe "Reservation class" From 98462d3e9b8cc155220ba88845a76fa66014ef65 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Fri, 9 Mar 2018 17:34:37 -0800 Subject: [PATCH 11/21] Updated the Admin spec file and the Admin#add_reservation method to add a new reservation with a check_in and check_out date. --- lib/admin.rb | 25 ++++++++++++++++++++----- specs/admin_spec.rb | 25 ++++++++++++++++--------- specs/reservation_spec.rb | 2 +- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 85bf61362..6bd69eae2 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -15,13 +15,19 @@ def initialize end # def list_rooms - # @rooms - # # binding.pry + # return @rooms # end - # + def add_reservation(check_in, check_out) + date_check(check_in) + date_check(check_out) + + reservation = Hotel::Reservation.new(check_in, check_out, rooms.sample) + @reservations << reservation + # binding.pry + return reservation end @@ -30,12 +36,14 @@ def list_reservations(date) end - def total_cost(reservation) + # def total_cost(reservation) + # + # end - end private + # .each loop to create a list of all 20 rooms def list_of_rooms rooms = [] (1..20).to_a.each do |num| @@ -44,5 +52,12 @@ def list_of_rooms return rooms end + # check to see if the check_in and check_out date inputs are valid + def date_check(date) + if date.class != Date + raise ArgumentError.new("Invalid date") + end + end + end # end of Admin class end # end of Hotel module diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 61f150d18..7d1b7cca5 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' -xdescribe "Admin class" do +describe "Admin class" do describe "Initializer" do it "must be an instance of admin" do @@ -8,24 +8,22 @@ admin.must_be_instance_of Hotel::Admin end - it "creates a list of all 20 rooms" do + it "access to a list of all 20 rooms" do admin = Hotel::Admin.new admin.must_respond_to :rooms admin.rooms.must_be_kind_of Array admin.rooms.length.must_equal 20 - admin.rooms.must_equal @rooms admin.rooms.each do |room| room.must_be_instance_of Hotel::Room end end - it "creates a reservation" do + it "access to reservations" do admin = Hotel::Admin.new admin.must_respond_to :reservations admin.reservations.must_be_kind_of Array - admin.reservations.must_equal @reservations admin.reservations.length.must_equal 0 end @@ -43,7 +41,16 @@ describe "add_reservation(check_in, check_out) method" do - end + it "creates a instance of reservation with the check_in and check_out dates" do + @check_in = Date.new(2018, 4, 14) + @check_out = Date.new(2018, 4, 21) + admin = Hotel::Admin.new + reservation = admin.add_reservation(@check_in, @check_out) + + reservation.must_be_instance_of Hotel::Reservation + end + + end # end of describe "add_reservation(check_in, check_out) method" do describe "list_reservations(date)" do @@ -51,8 +58,8 @@ end - describe "total_cost(reservation)" do - - end + # describe "total_cost(reservation)" do + # + # end end # end of describe "Admin class" diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 3f77d9f5d..35f2e421a 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' -describe "Reservation class" do +xdescribe "Reservation class" do describe "Initializer" do before do @check_in = Date.new(2018, 4, 14) From d415c72d5fa5d486fe2fde1d6cab5fbabbfbbe5b Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Fri, 9 Mar 2018 18:01:15 -0800 Subject: [PATCH 12/21] Updated spec file for Admin. --- lib/admin.rb | 9 ++++++++- specs/admin_spec.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/admin.rb b/lib/admin.rb index 6bd69eae2..c64b01d8d 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -23,10 +23,11 @@ def add_reservation(check_in, check_out) date_check(check_in) date_check(check_out) + date_range_check(check_in, check_out) reservation = Hotel::Reservation.new(check_in, check_out, rooms.sample) @reservations << reservation - # binding.pry + binding.pry return reservation end @@ -59,5 +60,11 @@ def date_check(date) end end + def date_range_check(check_in, check_out) + if check_in >= check_out + raise ArgumentError.new("Invalid check_out date: #{check_out} must be later than #{check_in}") + end + end + end # end of Admin class end # end of Hotel module diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 7d1b7cca5..4b4e9ee7d 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -50,6 +50,19 @@ reservation.must_be_instance_of Hotel::Reservation end + it "correctly list the reserved room" do + @check_in = Date.new(2018, 4, 14) + @check_out = Date.new(2018, 4, 21) + admin = Hotel::Admin.new + reservation = admin.add_reservation(@check_in, @check_out) + + reservation.check_in.must_be_kind_of Date + reservation.check_out.must_be_kind_of Date + reservation.room.room_num.must_be_kind_of Integer + reservation.room.rate.must_equal 200 + reservation.total_cost.must_equal 1400 + end + end # end of describe "add_reservation(check_in, check_out) method" do From 2f1c8a5afb213692ed92543a22681aa820c35410 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Sat, 10 Mar 2018 13:32:40 -0800 Subject: [PATCH 13/21] Updated the ArguementError message just a little and also the spec file by adding a before method to create an instance variable @room. --- lib/room.rb | 2 +- specs/room_spec.rb | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/room.rb b/lib/room.rb index b68ed6184..8bc3c78e2 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -11,7 +11,7 @@ def initialize(number, rate) # raises ArgumentError if the room number is not between 1 and 20 def hotel_room(number) unless (1..20).include? number - raise ArgumentError.new("Invalid room number #{number}") + raise ArgumentError.new("Invalid room number: #{number}") end @room_num = number end diff --git a/specs/room_spec.rb b/specs/room_spec.rb index 12165af10..db3459383 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1,34 +1,35 @@ require_relative 'spec_helper' -xdescribe "Room class" do +describe "Room class" do describe "initialize" do + before do + @room = Hotel::Room.new(9, 200) + end it "must be an instance of Room" do - room = Hotel::Room.new(1, 200) - room.must_be_instance_of Hotel::Room + @room.must_be_instance_of Hotel::Room end it "reads the room number" do - room = Hotel::Room.new(9, 200) - room.must_respond_to :room_num - room.room_num.must_be_kind_of Integer - room.room_num.must_equal 9 + @room.must_respond_to :room_num + @room.room_num.must_be_kind_of Integer + @room.room_num.must_equal 9 end - it "reads the rate of the room" do - room = Hotel::Room.new(9, 200) - room.must_respond_to :rate - room.rate.must_be_instance_of Integer - room.rate.must_equal 200 + it "reads the rate of the @room" do + @room = Hotel::Room.new(9, 200) + @room.must_respond_to :rate + @room.rate.must_be_instance_of Integer + @room.rate.must_equal 200 end - end # end of describe "You can create a Room instance" + end # end of describe "initialize" describe "hotel_room method" do it "raises an ArgumentError for invalid room numbers" do - proc {Hotel::Room.new(0)}.must_raise ArgumentError - proc {Hotel::Room.new(21)}.must_raise ArgumentError + proc {Hotel::Room.new(0, 200)}.must_raise ArgumentError + proc {Hotel::Room.new(21, 200)}.must_raise ArgumentError end end # end of describe "hotel_room method" From 4c4de8092a5685797691ed6877e4675ecf261db2 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Sat, 10 Mar 2018 13:46:16 -0800 Subject: [PATCH 14/21] Updated the helper methods in the Reservation class. One to help check if the date is valid and one to calculate the total cost. --- lib/reservation.rb | 22 +++++++++++++++++++--- specs/reservation_spec.rb | 18 +++++++++--------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index cede65377..b2f174075 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -12,10 +12,26 @@ def initialize(check_in, check_out, room) raise ArgumentError.new("Invalid check_out date: #{check_out} must be later than #{check_in}") end - @check_in = check_in - @check_out = check_out + @check_in = date_check(check_in) + @check_out = date_check(check_out) @room = room - @total_cost = ((check_out - check_in) * @room.rate).to_i + @total_cost = calculate_total_cost + end + + private + + # check to see if the check_in and check_out date inputs are valid + def date_check(date) + if date.class != Date + raise ArgumentError.new("Invalid date") + else + return date + end + end + + # helper method to calculate the total cost of the reservation + def calculate_total_cost + ((check_out - check_in) * @room.rate).to_i end end # end of Reservation class diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 35f2e421a..561cd676c 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1,6 +1,6 @@ require_relative 'spec_helper' -xdescribe "Reservation class" do +describe "Reservation class" do describe "Initializer" do before do @check_in = Date.new(2018, 4, 14) @@ -9,13 +9,6 @@ @reservation = Hotel::Reservation.new(@check_in, @check_out, @room) end - it "must raise an ArgumentError if the check_out date is invalid" do - check_in = Date.new(2018, 4, 12) - check_out = Date.new(2018, 4, 10) - room_1 = Hotel::Room.new(9, 200) - proc { Hotel::Reservation.new(check_in, check_out, room_1) }.must_raise ArgumentError - end - it "must be an instance of reservation" do @reservation.must_be_instance_of Hotel::Reservation end @@ -32,7 +25,7 @@ @reservation.check_out.must_equal @check_out end - it "reas in the correct room information" do + it "reads in the correct room information" do @reservation.must_respond_to :room @reservation.room.must_be_instance_of Hotel::Room @reservation.room.room_num.must_equal 9 @@ -45,5 +38,12 @@ @reservation.total_cost.must_equal 1400 end + it "must raise an ArgumentError if the check_out date is invalid" do + check_in = Date.new(2018, 4, 12) + check_out = Date.new(2018, 4, 10) + room_1 = Hotel::Room.new(9, 200) + proc { Hotel::Reservation.new(check_in, check_out, room_1) }.must_raise ArgumentError + end + end # end of describe "Initializer" end # end of describe "Reservation class" From 24ae7f678c2878b68c72e854225ea8a83259bf68 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Sat, 10 Mar 2018 14:38:53 -0800 Subject: [PATCH 15/21] Updated the spec file for Admin#add_reservation method. Also, updated the spec file for Reservation class. Refractured some of the testing and private helper methods. --- lib/admin.rb | 24 +++++----- lib/reservation.rb | 16 ++++--- specs/admin_spec.rb | 93 ++++++++++++++++++++------------------- specs/reservation_spec.rb | 13 ++++-- 4 files changed, 78 insertions(+), 68 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index c64b01d8d..39ca1a663 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -14,11 +14,6 @@ def initialize @reservations = [] end - # def list_rooms - # return @rooms - # end - - def add_reservation(check_in, check_out) date_check(check_in) @@ -27,24 +22,26 @@ def add_reservation(check_in, check_out) reservation = Hotel::Reservation.new(check_in, check_out, rooms.sample) @reservations << reservation - binding.pry + # binding.pry + return reservation + end def list_reservations(date) - end + date_check(date) + - # def total_cost(reservation) - # - # end + + end private - # .each loop to create a list of all 20 rooms + # .each loop to iterate and create a list of all 20 rooms def list_of_rooms rooms = [] (1..20).to_a.each do |num| @@ -53,13 +50,14 @@ def list_of_rooms return rooms end - # check to see if the check_in and check_out date inputs are valid + # check to see if the check_in and check_out dates are invalid def date_check(date) if date.class != Date - raise ArgumentError.new("Invalid date") + raise ArgumentError.new("Invalid date: #{date}") end end + # check to see if the date range is invalid def date_range_check(check_in, check_out) if check_in >= check_out raise ArgumentError.new("Invalid check_out date: #{check_out} must be later than #{check_in}") diff --git a/lib/reservation.rb b/lib/reservation.rb index b2f174075..e23c15d50 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -7,10 +7,7 @@ class Reservation def initialize(check_in, check_out, room) - # raises ArgumentError if the check_in date is before the check_out date - if check_in >= check_out - raise ArgumentError.new("Invalid check_out date: #{check_out} must be later than #{check_in}") - end + date_range_check(check_in, check_out) @check_in = date_check(check_in) @check_out = date_check(check_out) @@ -20,10 +17,17 @@ def initialize(check_in, check_out, room) private - # check to see if the check_in and check_out date inputs are valid + # check to see if the date range is invalid + def date_range_check(check_in, check_out) + if check_in >= check_out + raise ArgumentError.new("Invalid check_out date: #{check_out} must be later than #{check_in}") + end + end + + # check to see if the check_in and check_out dates are invalid def date_check(date) if date.class != Date - raise ArgumentError.new("Invalid date") + raise ArgumentError.new("Invalid date: #{date}") else return date end diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 4b4e9ee7d..c53548ded 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -1,69 +1,74 @@ require_relative 'spec_helper' describe "Admin class" do - describe "Initializer" do + describe "initialize" do + before do + @admin = Hotel::Admin.new + end it "must be an instance of admin" do - admin = Hotel::Admin.new - admin.must_be_instance_of Hotel::Admin + @admin.must_be_instance_of Hotel::Admin end - it "access to a list of all 20 rooms" do - admin = Hotel::Admin.new - - admin.must_respond_to :rooms - admin.rooms.must_be_kind_of Array - admin.rooms.length.must_equal 20 - admin.rooms.each do |room| + it "has access to a list of all 20 rooms" do + @admin.must_respond_to :rooms + @admin.rooms.must_be_kind_of Array + @admin.rooms.length.must_equal 20 + @admin.rooms.each do |room| room.must_be_instance_of Hotel::Room end end it "access to reservations" do - admin = Hotel::Admin.new - - admin.must_respond_to :reservations - admin.reservations.must_be_kind_of Array - admin.reservations.length.must_equal 0 + @admin.must_respond_to :reservations + @admin.reservations.must_be_kind_of Array + @admin.reservations.length.must_equal 0 end - end # end of describe "Initializer" - - - # describe "list_rooms method" do - # admin = Hotel::Admin.new - # - # admin.list_rooms.must_be_kind_of Array - # - # end - # + end # end of describe "initialize" - describe "add_reservation(check_in, check_out) method" do - - it "creates a instance of reservation with the check_in and check_out dates" do + describe "add_reservation method" do + before do @check_in = Date.new(2018, 4, 14) @check_out = Date.new(2018, 4, 21) - admin = Hotel::Admin.new - reservation = admin.add_reservation(@check_in, @check_out) + @admin = Hotel::Admin.new + @reservation = @admin.add_reservation(@check_in, @check_out) + end - reservation.must_be_instance_of Hotel::Reservation + it "creates a instance of reservation with the check_in and check_out dates" do + @reservation.must_be_instance_of Hotel::Reservation end it "correctly list the reserved room" do - @check_in = Date.new(2018, 4, 14) - @check_out = Date.new(2018, 4, 21) - admin = Hotel::Admin.new - reservation = admin.add_reservation(@check_in, @check_out) - - reservation.check_in.must_be_kind_of Date - reservation.check_out.must_be_kind_of Date - reservation.room.room_num.must_be_kind_of Integer - reservation.room.rate.must_equal 200 - reservation.total_cost.must_equal 1400 + @reservation.check_in.must_equal @check_in + @reservation.check_out.must_equal @check_out + @reservation.check_in.must_be_kind_of Date + @reservation.check_out.must_be_kind_of Date + @reservation.room.room_num.must_be_kind_of Integer + @reservation.room.rate.must_equal 200 + @reservation.total_cost.must_equal 1400 end - end # end of describe "add_reservation(check_in, check_out) method" do + it "accurately addes the reserved room to the reservation list" do + number_of_reserved_rooms = @admin.reservations.length + + @admin.reservations.length.must_equal number_of_reserved_rooms + end + + it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do + check_in = Date.new(2018412) + check_out = Date.new(2018410) + proc { @admin.add_reservation(check_in, check_out) }.must_raise ArgumentError + end + + it "must raise an ArgumentError if the date range is invalid" do + check_in = Date.new(2018, 4, 12) + check_out = Date.new(2018, 4, 10) + proc { @admin.add_reservation(check_in, check_out) }.must_raise ArgumentError + end + + end # end of describe "add_reservation method" do describe "list_reservations(date)" do @@ -71,8 +76,4 @@ end - # describe "total_cost(reservation)" do - # - # end - end # end of describe "Admin class" diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 561cd676c..5a8b65732 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1,7 +1,7 @@ require_relative 'spec_helper' describe "Reservation class" do - describe "Initializer" do + describe "initialize" do before do @check_in = Date.new(2018, 4, 14) @check_out = Date.new(2018, 4, 21) @@ -38,12 +38,19 @@ @reservation.total_cost.must_equal 1400 end - it "must raise an ArgumentError if the check_out date is invalid" do + it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do + check_in = Date.new(2018412) + check_out = Date.new(2018410) + room_1 = Hotel::Room.new(9, 200) + proc { Hotel::Reservation.new(check_in, check_out, room_1) }.must_raise ArgumentError + end + + it "must raise an ArgumentError if the date range is invalid" do check_in = Date.new(2018, 4, 12) check_out = Date.new(2018, 4, 10) room_1 = Hotel::Room.new(9, 200) proc { Hotel::Reservation.new(check_in, check_out, room_1) }.must_raise ArgumentError end - end # end of describe "Initializer" + end # end of describe "initialize" end # end of describe "Reservation class" From ec2d7813b305193f97434ba8217a2aa5476ea3e0 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Sat, 10 Mar 2018 15:15:22 -0800 Subject: [PATCH 16/21] Updated the Admin#list_reservation method and the spec file. --- lib/admin.rb | 7 +++++++ specs/admin_spec.rb | 30 +++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index 39ca1a663..ec2d76ceb 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -33,8 +33,15 @@ def list_reservations(date) date_check(date) + reserved_list = [] + @reservations.each do |reservation| + if reservation.check_in <= date && reservation.check_out >= date + reserved_list << reservation + end + end + return reserved_list end diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index c53548ded..544e95344 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -67,13 +67,37 @@ check_out = Date.new(2018, 4, 10) proc { @admin.add_reservation(check_in, check_out) }.must_raise ArgumentError end - + end # end of describe "add_reservation method" do - describe "list_reservations(date)" do + describe "list_reservations method" do + before do + @admin = Hotel::Admin.new + @admin.add_reservation(Date.new(2018, 3, 22), Date.new(2018, 3, 24)) + @admin.add_reservation(Date.new(2018, 4, 21), Date.new(2018, 4, 24)) + @admin.add_reservation(Date.new(2018, 4, 22), Date.new(2018, 4, 24)) + end + + it "correctly adds all the new reservations" do + reservations = @admin.list_reservations(Date.new(2018, 4, 22)) - end + @admin.reservations.length.must_equal 3 + reservations.length.must_equal 2 + end + it "returns zero if no reservations are found" do + reservations = @admin.list_reservations(Date.new(2018, 3, 10)) + + reservations.length.must_equal 0 + end + + it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do + check_in = 2018-03-04 + check_out = 2018-03-06 + proc { @admin.list_reservations(check_in) }.must_raise ArgumentError + proc { @admin.list_reservations(check_out) }.must_raise ArgumentError + end + end # end of describe "list_reservations method" end # end of describe "Admin class" From c1688eb0e7d83a73b51f122ed1a080501b3a17bb Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Sat, 10 Mar 2018 15:20:02 -0800 Subject: [PATCH 17/21] Checked coverage and noticed the spec file test for raisinge ArgumentError when the check_in or check_out date is invalid was not fully covered. Updated the Reservation sepc file and now the coverage is at 100%. --- specs/reservation_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 5a8b65732..f593256cb 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -39,8 +39,8 @@ end it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do - check_in = Date.new(2018412) - check_out = Date.new(2018410) + check_in = 201841 + check_out = 2018410 room_1 = Hotel::Room.new(9, 200) proc { Hotel::Reservation.new(check_in, check_out, room_1) }.must_raise ArgumentError end From db9bd1cc7379d382d2fcb08bcc1ef84efccde30b Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Sun, 11 Mar 2018 00:28:00 -0800 Subject: [PATCH 18/21] Updated the Admin class and test to find the available rooms. Also, added a helper method to find empty rooms. --- lib/admin.rb | 48 ++++++++++++++++++++++++++++++--- lib/reservation.rb | 9 ++++--- specs/admin_spec.rb | 57 ++++++++++++++++++++++++++++++++++++--- specs/reservation_spec.rb | 13 +++++++++ 4 files changed, 115 insertions(+), 12 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index ec2d76ceb..a18b06763 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -20,9 +20,13 @@ def add_reservation(check_in, check_out) date_check(check_out) date_range_check(check_in, check_out) - reservation = Hotel::Reservation.new(check_in, check_out, rooms.sample) + available_rooms = available_rooms(check_in, check_out) + if available_rooms.empty? + raise Exception.new("Sorry for the inconvenience. No rooms are available for the date range") + end + + reservation = Hotel::Reservation.new(check_in, check_out, available_rooms.sample) @reservations << reservation - # binding.pry return reservation @@ -45,6 +49,27 @@ def list_reservations(date) end + def available_rooms(check_in, check_out) + + date_check(check_in) + date_check(check_out) + date_range_check(check_in, check_out) + + available_list = [] + + (check_in...check_out).to_a.each do |date| + available_list << empty_rooms(date) + end + + available_rooms = available_list[0] + (available_list.length - 1).times do |i| + available_rooms = available_rooms & available_list[i + 1] + end + # binding.pry + return available_rooms + + end + private @@ -59,9 +84,12 @@ def list_of_rooms # check to see if the check_in and check_out dates are invalid def date_check(date) - if date.class != Date - raise ArgumentError.new("Invalid date: #{date}") + if date.class == String + date = Date.parse(date) + elsif date.class != Date + raise ArgumentError.new("Invalid date: #{date}. Please enter date in the form of '2018, 03, 10'") end + return date end # check to see if the date range is invalid @@ -71,5 +99,17 @@ def date_range_check(check_in, check_out) end end + def empty_rooms(date) + date_check(date) + + reservation_list = list_reservations(date) + reserved_rooms = [] + + reservation_list.each do |reservation| + reserved_rooms << reservation.room + end + return @rooms - reserved_rooms + end + end # end of Admin class end # end of Hotel module diff --git a/lib/reservation.rb b/lib/reservation.rb index e23c15d50..5c5314838 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -26,11 +26,12 @@ def date_range_check(check_in, check_out) # check to see if the check_in and check_out dates are invalid def date_check(date) - if date.class != Date - raise ArgumentError.new("Invalid date: #{date}") - else - return date + if date.class == String + date = Date.parse(date) + elsif date.class != Date + raise ArgumentError.new("Invalid date: #{date}. Please enter date in the form of '2018, 03, 10'") end + return date end # helper method to calculate the total cost of the reservation diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 544e95344..58c31af4a 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -23,7 +23,6 @@ @admin.must_respond_to :reservations @admin.reservations.must_be_kind_of Array @admin.reservations.length.must_equal 0 - end end # end of describe "initialize" @@ -57,8 +56,8 @@ end it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do - check_in = Date.new(2018412) - check_out = Date.new(2018410) + check_in = 2018412 + check_out = 2018410 proc { @admin.add_reservation(check_in, check_out) }.must_raise ArgumentError end @@ -68,8 +67,17 @@ proc { @admin.add_reservation(check_in, check_out) }.must_raise ArgumentError end - end # end of describe "add_reservation method" do + it "must raise an Exception if there are no rooms available" do + admin = Hotel::Admin.new + + 20.times do + admin.add_reservation(Date.new(2018, 4, 14), Date.new(2018, 4, 21)) + end + proc { admin.add_reservation(Date.new(2018, 4, 14), Date.new(2018, 4, 21)) }.must_raise Exception + end + + end # end of describe "add_reservation method" do describe "list_reservations method" do before do @@ -100,4 +108,45 @@ end end # end of describe "list_reservations method" + + describe "available_rooms method" do + before do + @check_in = Date.new(2018, 4, 14) + @check_out = Date.new(2018, 4, 21) + @admin = Hotel::Admin.new + end + + it "lists out all the empty rooms with the given date range" do + @admin.add_reservation(@check_in, @check_out) + + available_list = @admin.available_rooms(@check_in, @check_out) + + available_list.length.must_equal 19 + available_list.must_be_kind_of Array + end + + it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do + check_in = 2018412 + check_out = 2018410 + proc { @admin.available_rooms(check_in, check_out) }.must_raise ArgumentError + end + + it "must raise an ArgumentError if the date range is invalid" do + check_in = Date.new(2018, 4, 12) + check_out = Date.new(2018, 4, 10) + proc { @admin.available_rooms(check_in, check_out) }.must_raise ArgumentError + end + + it "must return an empty Array if no rooms are available" do + 20.times do + @admin.add_reservation(@check_in, @check_out) + end + + find_available_rooms = @admin.available_rooms(@check_in, @check_out) + + find_available_rooms.length.must_equal 0 + find_available_rooms.must_be_kind_of Array + end + + end # end of describe "available_rooms method" end # end of describe "Admin class" diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index f593256cb..548800eb0 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -38,6 +38,19 @@ @reservation.total_cost.must_equal 1400 end + # it "correctly returns the date if the check_in and check_out dates are strings" do + # check_in = '2018414' + # check_out = '2018421' + # room_1 = Hotel::Room.new(9, 200) + # reservation1 = Hotel::Reservation.new(check_in, check_out, room_1) + # + # # reservation.check_in.must_be_kind_of Date + # # reservation.check_out.must_be_kind_of Date + # reservation.room.room_num.must_equal 9 + # reservation.room.rate.must_equal 200 + # reservation1.total_cost.must_equal 1400 + # end + it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do check_in = 201841 check_out = 2018410 From 1221e05c177ab60cf8eb7edc2c42083972bf1b06 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Sun, 11 Mar 2018 23:28:09 -0700 Subject: [PATCH 19/21] Updated the spec files so that the coverage is 100%. --- lib/admin.rb | 5 ++--- specs/admin_spec.rb | 36 ++++++++++++++++++++++++++++++++++++ specs/reservation_spec.rb | 24 ++++++++++++------------ 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index a18b06763..9bcc05d38 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -1,6 +1,4 @@ require 'date' -require 'pry' -require 'awesome_print' require_relative 'reservation' require_relative 'room' @@ -65,7 +63,7 @@ def available_rooms(check_in, check_out) (available_list.length - 1).times do |i| available_rooms = available_rooms & available_list[i + 1] end - # binding.pry + return available_rooms end @@ -99,6 +97,7 @@ def date_range_check(check_in, check_out) end end + # check to see if the given date input has any avilable empty rooms def empty_rooms(date) date_check(date) diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index 58c31af4a..c56cb6f07 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -55,6 +55,18 @@ @admin.reservations.length.must_equal number_of_reserved_rooms end + it "correctly returns the date if the check_in and check_out dates are strings" do + check_in = "2018-4-14" + check_out = "2018-4-21" + admin_1 = Hotel::Admin.new + reservation1 = admin_1.add_reservation(check_in, check_out) + + reservation1.check_in.must_be_kind_of Date + reservation1.check_out.must_be_kind_of Date + reservation1.room.rate.must_equal 200 + reservation1.total_cost.must_equal 1400 + end + it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do check_in = 2018412 check_out = 2018410 @@ -100,6 +112,18 @@ reservations.length.must_equal 0 end + it "correctly returns the date if the check_in and check_out dates are strings" do + check_in = "2018-4-14" + check_out = "2018-4-21" + admin_1 = Hotel::Admin.new + reservation1 = admin_1.add_reservation(check_in, check_out) + + reservation1.check_in.must_be_kind_of Date + reservation1.check_out.must_be_kind_of Date + reservation1.room.rate.must_equal 200 + reservation1.total_cost.must_equal 1400 + end + it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do check_in = 2018-03-04 check_out = 2018-03-06 @@ -125,6 +149,18 @@ available_list.must_be_kind_of Array end + it "correctly returns the date if the check_in and check_out dates are strings" do + check_in = "2018-4-14" + check_out = "2018-4-21" + admin_1 = Hotel::Admin.new + reservation1 = admin_1.add_reservation(check_in, check_out) + + reservation1.check_in.must_be_kind_of Date + reservation1.check_out.must_be_kind_of Date + reservation1.room.rate.must_equal 200 + reservation1.total_cost.must_equal 1400 + end + it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do check_in = 2018412 check_out = 2018410 diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 548800eb0..6e6e78e87 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -38,18 +38,18 @@ @reservation.total_cost.must_equal 1400 end - # it "correctly returns the date if the check_in and check_out dates are strings" do - # check_in = '2018414' - # check_out = '2018421' - # room_1 = Hotel::Room.new(9, 200) - # reservation1 = Hotel::Reservation.new(check_in, check_out, room_1) - # - # # reservation.check_in.must_be_kind_of Date - # # reservation.check_out.must_be_kind_of Date - # reservation.room.room_num.must_equal 9 - # reservation.room.rate.must_equal 200 - # reservation1.total_cost.must_equal 1400 - # end + it "correctly returns the date if the check_in and check_out dates are strings" do + check_in = "2018-4-14" + check_out = "2018-4-21" + room_1 = Hotel::Room.new(9, 200) + reservation1 = Hotel::Reservation.new(check_in, check_out, room_1) + + reservation1.check_in.must_be_kind_of Date + reservation1.check_out.must_be_kind_of Date + reservation1.room.room_num.must_equal 9 + reservation1.room.rate.must_equal 200 + reservation1.total_cost.must_equal 1400 + end it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do check_in = 201841 From 2d3e449cf31e1293f0f65e3d9650e31d72714620 Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Sun, 1 Apr 2018 16:28:26 -0700 Subject: [PATCH 20/21] Created and updated design-activity.md. Responded to all the prompts. --- design-activity.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 design-activity.md diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..11442e313 --- /dev/null +++ b/design-activity.md @@ -0,0 +1,73 @@ + + + + +Implementation A classes: CartEntry, ShoppingCart and Order +Implementation B classes: CartEntry, ShoppingCart and Order + +The list of classes between implementation A and B are the same. + + + +Implementation A classes: Both the CartEntry and ShoppingCart classes carry one single responsibility. However, all the logic to carry out those various responsibilities, such as calculating the subtotal and the total, are located in one place inside the Order class. The Order class is the "master" class that is in charge of all behavior, and other classes are only used to store state. +Implementation B classes: The logic has been delegated to "low level" classes, CartEntry and ShoppingCart. The Order class no longer carries all the behavior. + + + +Implementation A classes: The Order class creates an instance of the ShoppingCart class in its initialize. Then in the total_price method it carries out all the logic by finding each entry's unit price and quantity and calculating the subtotal and then the final total with tax included. + +Implementation B classes: Each class carries its own singal responsibility. The CartEntry class takes in each entry's quantity and price and calculates that entry's total price. Then, the ShoppingCart class adds up all entries and calculates the subtotal. Finally, the Order class calculates the final total with the sales tax. + + + +Implementation A classes: +CartEntry - unit_price & quantity +ShoppingCart - all entries +Order - the sales tax, all entries, the price of each entry, the subtotal and the final total with the sales tax + +Implementation B classes: +CartEntry - unit_price & quantity and the price of each entry +ShoppingCart - all entries and the subtotal +Order - the sales tax, all entries and the final total with the sales tax + +The Order class in implementation A carries all the responsibilities. While the responsibility is spread out evenly between all three classes in implementation B. + + + +Implementation A classes: +CartEntry - initialize +ShoppingCart - initialize +Order - initialize and total_price + +Implementation B classes: +CartEntry - initialize and price +ShoppingCart - initialize and price +Order - initialize and total_price + +The Order class in implementation A carries all the responsibilities. While the responsibility of calculating the prices are spread out evenly between all three classes in implementation B. + + + + + +Implementation A classes: the logic to compute the price is retained in Order. + +Implementation B classes: the logic to compute the price is delegated to "lower level" classes. + + + +Implementation A classes: yes + +Implementation B classes: no + + + +If items are cheaper when bought in bulk, then we could apply a discount to quantities that are equal or over a certain specific amount. This would be easier to modify in implementation B because the of how logic is evenly delegated between each class, the discount can be added in any of the three classes and its methods. Whereas in implementation A, the only class that the logic can go into is the Order class. + + + +Implementation B better adheres to the single responsibility principles because each class is responsible for one thing and the dependency the Order class has on the other two classes is very loose. + + + +Continuing off of my previous answer, implementation B is more loosely coupled because if there is a change in one class it will not affect the other two classes. Especially in the Order class. Whereas in implementation A, if any changes were to be done to the first two classes, this could drastically change the code of Order class because it depends on both "low level" classes. From 3080b7ada0611141bd56724b721ee1cf7aab6d3e Mon Sep 17 00:00:00 2001 From: Luxi Lindsey Date: Sun, 1 Apr 2018 21:52:06 -0700 Subject: [PATCH 21/21] Re-designed the Hotel project with more OOD and single responsiblity. --- design-activity.md | 15 +++++ lib/admin.rb | 64 ++++-------------- lib/date_range.rb | 33 +++++++++ lib/reservation.rb | 41 +++--------- lib/room.rb | 14 ++-- specs/admin_spec.rb | 137 +++++++++----------------------------- specs/date_range_spec.rb | 52 +++++++++++++++ specs/reservation_spec.rb | 64 +++++++----------- specs/room_spec.rb | 7 +- 9 files changed, 189 insertions(+), 238 deletions(-) create mode 100644 lib/date_range.rb create mode 100644 specs/date_range_spec.rb diff --git a/design-activity.md b/design-activity.md index 11442e313..36aa74b8e 100644 --- a/design-activity.md +++ b/design-activity.md @@ -71,3 +71,18 @@ Implementation B better adheres to the single responsibility principles because Continuing off of my previous answer, implementation B is more loosely coupled because if there is a change in one class it will not affect the other two classes. Especially in the Order class. Whereas in implementation A, if any changes were to be done to the first two classes, this could drastically change the code of Order class because it depends on both "low level" classes. + + + + +Based on the answers to the above questions, one of the places in my Hotel project where a class takes on multiple roles is the Admin class. The Admin class has dependency on both the Room and Reservation class. Also, the private method to check the date range and to see if the date inputs are valid are repeated in both the Admin and Reservation class. + +Here are the steps I took to make my Hotel project more Object Oriented with single responsibilities: + +-> Created new files date_range.rb and date_range_spec.rb +-> Created the DateRange class to remove the date_range method from the Reservation and Admin classes. Also, the date_check method, which stayed as a private method. +-> Updated the Reservation class to not be dependent on the Room class and created instance variables, rate. +-> Updated the Admin class to not be dependent of the Room class. +-> Updated the specs accordingly and made sure the dependency is as loose as possible. + +Afte the re-design that I made, I believe the logic is no longer heavily within Admin class. Although the logic could be spread out more evenly onto the Room class. The Admin class is now only dependent on the Revservation class. Maybe if I am able to add the block function for Hotel wave 3 then I will consider moving more logic into the Room class. diff --git a/lib/admin.rb b/lib/admin.rb index 9bcc05d38..c44a5eb63 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -1,40 +1,35 @@ -require 'date' - require_relative 'reservation' -require_relative 'room' module Hotel class Admin - attr_reader :rooms, :reservations + attr_reader :rooms, :reservations, :room_rate def initialize - @rooms = list_of_rooms + @rooms = (1..20).to_a + @room_rate = 200 @reservations = [] end - def add_reservation(check_in, check_out) + def add_reservation(room, check_in, check_out) - date_check(check_in) - date_check(check_out) - date_range_check(check_in, check_out) + # Check that the room exists + unless @rooms.include? room + raise ArgumentError.new("Invalid room number: #{room}") + end - available_rooms = available_rooms(check_in, check_out) - if available_rooms.empty? - raise Exception.new("Sorry for the inconvenience. No rooms are available for the date range") + # Check that the room is available + unless available_rooms(check_in, check_out).include? room + raise ArgumentError.new("Room #{room} already has a reservation between #{check_in} and #{check_out}") end - reservation = Hotel::Reservation.new(check_in, check_out, available_rooms.sample) + reservation = Reservation.new(check_in, check_out, room, @room_rate) @reservations << reservation return reservation - end - def list_reservations(date) - date_check(date) - reserved_list = [] @reservations.each do |reservation| @@ -49,13 +44,11 @@ def list_reservations(date) def available_rooms(check_in, check_out) - date_check(check_in) - date_check(check_out) - date_range_check(check_in, check_out) + DateRange.new(check_in, check_out) available_list = [] - (check_in...check_out).to_a.each do |date| + (check_in...check_out).each do |date| available_list << empty_rooms(date) end @@ -68,39 +61,10 @@ def available_rooms(check_in, check_out) end - private - # .each loop to iterate and create a list of all 20 rooms - def list_of_rooms - rooms = [] - (1..20).to_a.each do |num| - rooms << Hotel::Room.new(num, 200) - end - return rooms - end - - # check to see if the check_in and check_out dates are invalid - def date_check(date) - if date.class == String - date = Date.parse(date) - elsif date.class != Date - raise ArgumentError.new("Invalid date: #{date}. Please enter date in the form of '2018, 03, 10'") - end - return date - end - - # check to see if the date range is invalid - def date_range_check(check_in, check_out) - if check_in >= check_out - raise ArgumentError.new("Invalid check_out date: #{check_out} must be later than #{check_in}") - end - end - # check to see if the given date input has any avilable empty rooms def empty_rooms(date) - date_check(date) - reservation_list = list_reservations(date) reserved_rooms = [] diff --git a/lib/date_range.rb b/lib/date_range.rb new file mode 100644 index 000000000..279022236 --- /dev/null +++ b/lib/date_range.rb @@ -0,0 +1,33 @@ +module Hotel + class DateRange + class InvalidDateRange < StandardError ; end + + attr_reader :check_in, :check_out + + def initialize(check_in, check_out) + unless check_out > check_in + raise InvalidDateRange.new("Invalid dates #{check_in} to #{check_out}") + end + + @check_in = date_check(check_in) + @check_out = date_check(check_out) + end + + def nights + return @check_out - @check_in + end + + private + + # check to see if the check_in and check_out dates are invalid + def date_check(date) + if date.class == String + date = Date.parse(date) + elsif date.class != Date + raise ArgumentError.new("Invalid date: #{date}. Please enter date in the form of '2018, 03, 10'") + end + return date + end + + end +end diff --git a/lib/reservation.rb b/lib/reservation.rb index 5c5314838..b705094e6 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,42 +1,17 @@ -require 'date' -require_relative 'room' +require_relative 'date_range' module Hotel - class Reservation - attr_reader :check_in, :check_out, :room, :total_cost + class Reservation < DateRange + attr_reader :room, :rate - def initialize(check_in, check_out, room) - - date_range_check(check_in, check_out) - - @check_in = date_check(check_in) - @check_out = date_check(check_out) + def initialize(check_in, check_out, room, rate) + super(check_in, check_out) @room = room - @total_cost = calculate_total_cost - end - - private - - # check to see if the date range is invalid - def date_range_check(check_in, check_out) - if check_in >= check_out - raise ArgumentError.new("Invalid check_out date: #{check_out} must be later than #{check_in}") - end - end - - # check to see if the check_in and check_out dates are invalid - def date_check(date) - if date.class == String - date = Date.parse(date) - elsif date.class != Date - raise ArgumentError.new("Invalid date: #{date}. Please enter date in the form of '2018, 03, 10'") - end - return date + @rate = rate end - # helper method to calculate the total cost of the reservation - def calculate_total_cost - ((check_out - check_in) * @room.rate).to_i + def total_cost + return nights * @rate end end # end of Reservation class diff --git a/lib/room.rb b/lib/room.rb index 8bc3c78e2..9ccc12cae 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,19 +1,19 @@ module Hotel class Room - attr_reader :room_num, :rate + attr_reader :room, :rate - def initialize(number, rate) - @room_num = hotel_room(number) + def initialize(room, rate) + @room = hotel_room(room) @rate = rate end # raises ArgumentError if the room number is not between 1 and 20 - def hotel_room(number) - unless (1..20).include? number - raise ArgumentError.new("Invalid room number: #{number}") + def hotel_room(room) + unless (1..20).include? room + raise ArgumentError.new("Invalid room number: #{room}") end - @room_num = number + @room = room end end # end of Room class diff --git a/specs/admin_spec.rb b/specs/admin_spec.rb index c56cb6f07..907273f8f 100644 --- a/specs/admin_spec.rb +++ b/specs/admin_spec.rb @@ -1,10 +1,12 @@ require_relative 'spec_helper' describe "Admin class" do + + before do + @admin = Hotel::Admin.new + end + describe "initialize" do - before do - @admin = Hotel::Admin.new - end it "must be an instance of admin" do @admin.must_be_instance_of Hotel::Admin @@ -14,9 +16,11 @@ @admin.must_respond_to :rooms @admin.rooms.must_be_kind_of Array @admin.rooms.length.must_equal 20 - @admin.rooms.each do |room| - room.must_be_instance_of Hotel::Room - end + end + + it "tracks room rate" do + @admin.must_respond_to :room_rate + @admin.room_rate.must_equal 200 end it "access to reservations" do @@ -31,21 +35,36 @@ before do @check_in = Date.new(2018, 4, 14) @check_out = Date.new(2018, 4, 21) - @admin = Hotel::Admin.new - @reservation = @admin.add_reservation(@check_in, @check_out) + @room = 9 + @reservation = @admin.add_reservation(@room, @check_in, @check_out) end it "creates a instance of reservation with the check_in and check_out dates" do @reservation.must_be_instance_of Hotel::Reservation end + it "raises an error for an invalid room" do + [105, -12, "foo"].each do |room| + proc { + @admin.add_reservation(room, @check_in, @check_out) + }.must_raise ArgumentError + end + end + + it "raises an error if no rooms are available" do + @admin.add_reservation(10, @check_in, @check_out) + + proc { + @admin.add_reservation(10, @check_in, @check_out) + }.must_raise ArgumentError + end + it "correctly list the reserved room" do @reservation.check_in.must_equal @check_in @reservation.check_out.must_equal @check_out @reservation.check_in.must_be_kind_of Date @reservation.check_out.must_be_kind_of Date - @reservation.room.room_num.must_be_kind_of Integer - @reservation.room.rate.must_equal 200 + @reservation.room.must_be_kind_of Integer @reservation.total_cost.must_equal 1400 end @@ -55,48 +74,13 @@ @admin.reservations.length.must_equal number_of_reserved_rooms end - it "correctly returns the date if the check_in and check_out dates are strings" do - check_in = "2018-4-14" - check_out = "2018-4-21" - admin_1 = Hotel::Admin.new - reservation1 = admin_1.add_reservation(check_in, check_out) - - reservation1.check_in.must_be_kind_of Date - reservation1.check_out.must_be_kind_of Date - reservation1.room.rate.must_equal 200 - reservation1.total_cost.must_equal 1400 - end - - it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do - check_in = 2018412 - check_out = 2018410 - proc { @admin.add_reservation(check_in, check_out) }.must_raise ArgumentError - end - - it "must raise an ArgumentError if the date range is invalid" do - check_in = Date.new(2018, 4, 12) - check_out = Date.new(2018, 4, 10) - proc { @admin.add_reservation(check_in, check_out) }.must_raise ArgumentError - end - - it "must raise an Exception if there are no rooms available" do - admin = Hotel::Admin.new - - 20.times do - admin.add_reservation(Date.new(2018, 4, 14), Date.new(2018, 4, 21)) - end - - proc { admin.add_reservation(Date.new(2018, 4, 14), Date.new(2018, 4, 21)) }.must_raise Exception - end - end # end of describe "add_reservation method" do describe "list_reservations method" do before do - @admin = Hotel::Admin.new - @admin.add_reservation(Date.new(2018, 3, 22), Date.new(2018, 3, 24)) - @admin.add_reservation(Date.new(2018, 4, 21), Date.new(2018, 4, 24)) - @admin.add_reservation(Date.new(2018, 4, 22), Date.new(2018, 4, 24)) + @admin.add_reservation(1, Date.new(2018, 3, 22), Date.new(2018, 3, 24)) + @admin.add_reservation(2, Date.new(2018, 4, 21), Date.new(2018, 4, 24)) + @admin.add_reservation(3, Date.new(2018, 4, 22), Date.new(2018, 4, 24)) end it "correctly adds all the new reservations" do @@ -112,36 +96,16 @@ reservations.length.must_equal 0 end - it "correctly returns the date if the check_in and check_out dates are strings" do - check_in = "2018-4-14" - check_out = "2018-4-21" - admin_1 = Hotel::Admin.new - reservation1 = admin_1.add_reservation(check_in, check_out) - - reservation1.check_in.must_be_kind_of Date - reservation1.check_out.must_be_kind_of Date - reservation1.room.rate.must_equal 200 - reservation1.total_cost.must_equal 1400 - end - - it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do - check_in = 2018-03-04 - check_out = 2018-03-06 - proc { @admin.list_reservations(check_in) }.must_raise ArgumentError - proc { @admin.list_reservations(check_out) }.must_raise ArgumentError - end - end # end of describe "list_reservations method" describe "available_rooms method" do before do @check_in = Date.new(2018, 4, 14) @check_out = Date.new(2018, 4, 21) - @admin = Hotel::Admin.new end it "lists out all the empty rooms with the given date range" do - @admin.add_reservation(@check_in, @check_out) + @admin.add_reservation(12, @check_in, @check_out) available_list = @admin.available_rooms(@check_in, @check_out) @@ -149,40 +113,5 @@ available_list.must_be_kind_of Array end - it "correctly returns the date if the check_in and check_out dates are strings" do - check_in = "2018-4-14" - check_out = "2018-4-21" - admin_1 = Hotel::Admin.new - reservation1 = admin_1.add_reservation(check_in, check_out) - - reservation1.check_in.must_be_kind_of Date - reservation1.check_out.must_be_kind_of Date - reservation1.room.rate.must_equal 200 - reservation1.total_cost.must_equal 1400 - end - - it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do - check_in = 2018412 - check_out = 2018410 - proc { @admin.available_rooms(check_in, check_out) }.must_raise ArgumentError - end - - it "must raise an ArgumentError if the date range is invalid" do - check_in = Date.new(2018, 4, 12) - check_out = Date.new(2018, 4, 10) - proc { @admin.available_rooms(check_in, check_out) }.must_raise ArgumentError - end - - it "must return an empty Array if no rooms are available" do - 20.times do - @admin.add_reservation(@check_in, @check_out) - end - - find_available_rooms = @admin.available_rooms(@check_in, @check_out) - - find_available_rooms.length.must_equal 0 - find_available_rooms.must_be_kind_of Array - end - end # end of describe "available_rooms method" end # end of describe "Admin class" diff --git a/specs/date_range_spec.rb b/specs/date_range_spec.rb new file mode 100644 index 000000000..6249525cc --- /dev/null +++ b/specs/date_range_spec.rb @@ -0,0 +1,52 @@ +require_relative 'spec_helper' + +describe Hotel::DateRange do + + describe "initialize" do + it "can be initialized with two dates" do + check_in = Date.new(2017, 01, 01) + check_out = Date.new(2017, 01, 04) + + @range = Hotel::DateRange.new(check_in, check_out) + + @range.check_in.must_equal check_in + @range.check_out.must_equal check_out + end + + it "correctly returns the date if the check_in and check_out dates are strings" do + check_in = "2018-4-14" + check_out = "2018-4-21" + @range = Hotel::DateRange.new(check_in, check_out) + + @range.check_in.must_be_kind_of Date + @range.check_out.must_be_kind_of Date + end + + it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do + check_in = 201841 + check_out = 2018410 + proc { Hotel::DateRange.new(check_in, check_out) }.must_raise ArgumentError + end + + it "must raise an ArgumentError if the date range is invalid" do + check_in = Date.new(2018, 4, 12) + check_out = Date.new(2018, 4, 10) + proc { + Hotel::DateRange.new(check_in, check_out) + }.must_raise Hotel::DateRange::InvalidDateRange + end + end + + describe "nights" do + it "returns the correct number of nights" do + nights = 3 + check_in = Date.new(2017, 01, 01) + check_out = check_in + nights + + @range = Hotel::DateRange.new(check_in, check_out) + + @range.nights.must_equal nights + end + end + +end diff --git a/specs/reservation_spec.rb b/specs/reservation_spec.rb index 6e6e78e87..6b6811f20 100644 --- a/specs/reservation_spec.rb +++ b/specs/reservation_spec.rb @@ -1,69 +1,51 @@ require_relative 'spec_helper' describe "Reservation class" do + + before do + @check_in = Date.new(2018, 4, 14) + @check_out = Date.new(2018, 4, 21) + @room = 9 + @rate = 200 + @reservation = Hotel::Reservation.new(@check_in, @check_out, @room, @rate) + end + describe "initialize" do - before do - @check_in = Date.new(2018, 4, 14) - @check_out = Date.new(2018, 4, 21) - @room = Hotel::Room.new(9, 200) - @reservation = Hotel::Reservation.new(@check_in, @check_out, @room) - end it "must be an instance of reservation" do @reservation.must_be_instance_of Hotel::Reservation end it "reads the check_in date" do - @reservation.must_respond_to :check_in @reservation.check_in.must_be_kind_of Date @reservation.check_in.must_equal @check_in end it "reads the check_out date" do - @reservation.must_respond_to :check_out @reservation.check_out.must_be_kind_of Date @reservation.check_out.must_equal @check_out end - it "reads in the correct room information" do - @reservation.must_respond_to :room - @reservation.room.must_be_instance_of Hotel::Room - @reservation.room.room_num.must_equal 9 - @reservation.room.rate.must_equal 200 - end - - it "reads in the rate and calculates the correct total cost" do - @reservation.must_respond_to :total_cost - @reservation.total_cost.must_be_kind_of Integer - @reservation.total_cost.must_equal 1400 + it "is a kind of DateRange" do + @reservation.must_be_kind_of Hotel::DateRange end - it "correctly returns the date if the check_in and check_out dates are strings" do - check_in = "2018-4-14" - check_out = "2018-4-21" - room_1 = Hotel::Room.new(9, 200) - reservation1 = Hotel::Reservation.new(check_in, check_out, room_1) - - reservation1.check_in.must_be_kind_of Date - reservation1.check_out.must_be_kind_of Date - reservation1.room.room_num.must_equal 9 - reservation1.room.rate.must_equal 200 - reservation1.total_cost.must_equal 1400 + it "reads in the correct room information" do + @reservation.must_respond_to :room + @reservation.room.must_equal 9 end - it "must raise an ArgumentError if the check_in and/or check_out date is invalid" do - check_in = 201841 - check_out = 2018410 - room_1 = Hotel::Room.new(9, 200) - proc { Hotel::Reservation.new(check_in, check_out, room_1) }.must_raise ArgumentError + it "reads in the correct rate information" do + @reservation.must_respond_to :rate + @reservation.rate.must_equal 200 end + end # end of describe "initialize" - it "must raise an ArgumentError if the date range is invalid" do - check_in = Date.new(2018, 4, 12) - check_out = Date.new(2018, 4, 10) - room_1 = Hotel::Room.new(9, 200) - proc { Hotel::Reservation.new(check_in, check_out, room_1) }.must_raise ArgumentError + describe "calculate_total_cost" do + it "calculates the price" do + expected_price = @rate * (@check_out - @check_in) + @reservation.total_cost.must_equal expected_price end + end - end # end of describe "initialize" end # end of describe "Reservation class" diff --git a/specs/room_spec.rb b/specs/room_spec.rb index db3459383..5287915ba 100644 --- a/specs/room_spec.rb +++ b/specs/room_spec.rb @@ -1,6 +1,7 @@ require_relative 'spec_helper' describe "Room class" do + describe "initialize" do before do @room = Hotel::Room.new(9, 200) @@ -11,9 +12,9 @@ end it "reads the room number" do - @room.must_respond_to :room_num - @room.room_num.must_be_kind_of Integer - @room.room_num.must_equal 9 + @room.must_respond_to :room + @room.room.must_be_kind_of Integer + @room.room.must_equal 9 end it "reads the rate of the @room" do