From cf8adaa6b9706b3ff21a207008495684f4ec366c Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Thu, 6 Sep 2018 14:02:20 -0700 Subject: [PATCH 01/13] Set up reservation and room spec files. Created and passed initialization tests for both classes. Working on returning room instance in reservation class --- spec/spec_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d1e3fdc8..c199377a7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ + + require 'minitest' require 'minitest/autorun' require 'minitest/reporters' @@ -6,3 +8,5 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # Require_relative your lib files here! +require_relative '../lib/reservation' +require_relative '../lib/room' From 126b9bdfb95ffc06d763cfc83da854f6ceaed97b Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Thu, 6 Sep 2018 14:04:01 -0700 Subject: [PATCH 02/13] set up foundation for hotel program --- lib/reservation.rb | 27 +++++++++++++++ lib/reservation_mngr.rb | 29 ++++++++++++++++ lib/room.rb | 20 +++++++++++ spec/reservation_spec.rb | 73 ++++++++++++++++++++++++++++++++++++++++ spec/room_spec.rb | 38 +++++++++++++++++++++ 5 files changed, 187 insertions(+) create mode 100644 lib/reservation.rb create mode 100644 lib/reservation_mngr.rb create mode 100644 lib/room.rb create mode 100644 spec/reservation_spec.rb create mode 100644 spec/room_spec.rb diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..82d2860d0 --- /dev/null +++ b/lib/reservation.rb @@ -0,0 +1,27 @@ +require 'time' +require 'date' + +module Hotel + class Reservation + attr_accessor :room, :check_in, :check_out, :cost + + def initialize(input) + @room = input[:room] + @check_in = Date.strptime(input[:check_in], '%m/%d/%Y') + @check_out = Date.strptime(input[:check_out], '%m/%d/%Y') + @cost = input[:cost] + end + + # def room_reserved + # return @room + # - what is the room associated with this reservation + # - return room instance with this reservation + # end + + def calculate_cost + # total_days = (@check_out - @check_in).to_i + # return (total_days * @room.Room.price) + end + + end +end diff --git a/lib/reservation_mngr.rb b/lib/reservation_mngr.rb new file mode 100644 index 000000000..9908eecf0 --- /dev/null +++ b/lib/reservation_mngr.rb @@ -0,0 +1,29 @@ +module Hotel + + class Reservation_mngr + attr_reader :rooms, :reservations, + + def initialize + @rooms = (array of rooms (1-20)) + @reservations = reservations (array of reservations) + @price = 200 + end + + def list_rooms + return @rooms + end + + def find_room(date-date) + end + + def reserve_room + end + + def list_reservations + end + + def get_total + end + end + +end diff --git a/lib/room.rb b/lib/room.rb new file mode 100644 index 000000000..847194c94 --- /dev/null +++ b/lib/room.rb @@ -0,0 +1,20 @@ +require 'time' + +module Hotel + class Room + attr_reader :room_number, :price + + ROOM_NUMBERS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + + def initialize(input) + @room_number = input[:room_number] + if @room_number < 1 || @room_number > 21 + raise ArgumentError + end + @price = input[:price] + if @price != 200 + raise ArgumentError + end + end + end +end diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb new file mode 100644 index 000000000..8d63fac7d --- /dev/null +++ b/spec/reservation_spec.rb @@ -0,0 +1,73 @@ +require_relative 'spec_helper' + +require 'date' + +describe 'Reservation class' do + + describe "Reservation instantiation" do + before do + @room = Hotel::Room.new({room_number: 1, price: 200}) + @res_1 = Hotel::Reservation.new({room: @room, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) + end + + it "it is an instance of Reservation" do + expect(@res_1).must_be_kind_of Hotel::Reservation + end + + it "is set up for specific attributes and data types" do + [:room, :check_in, :check_out, :cost].each do |prop| + expect(@res_1).must_respond_to prop + end + + expect(@res_1.room).must_be_kind_of Hotel::Room + expect(@res_1.check_in).must_be_kind_of Date + expect(@res_1.check_out).must_be_kind_of Date + expect(@res_1.cost).must_be_kind_of Integer + end + end + + describe 'room_reserved' do + it "returns the room instance associated with this reservation" do + end + + end + # + # describe "calculate_cost" do + # it "returns total cost of room per night" do + # + # room_data = { + # room_number: 2, + # price: 200 + # } + # + # hyatt = Hotel::Room.new(room_data) + # + # expect(hyatt.calculate_cost(5)).must_equal 1000 + # end + # end + + # describe "calculate_cost" do + # it "returns total cost of room per night" do + # + # room_data = { + # room_number: 2, + # price: 200 + # } + # + # hyatt = Hotel::Room.new(room_data) + # + # reservation_data = { + # rooms: hyatt, + # check_in: (2018, 01, 10), + # check_out: (2018, 01, 17), + # cost: hyatt.Room.price + # } + # + # reservation_2 = Hotel::Reservation() + # # + # expect(hyatt.calculate_cost('1/10/2018', '01/12/2018')).must_equal 400 + # end + + + +end diff --git a/spec/room_spec.rb b/spec/room_spec.rb new file mode 100644 index 000000000..d2b3ff943 --- /dev/null +++ b/spec/room_spec.rb @@ -0,0 +1,38 @@ +require_relative 'spec_helper' + +describe 'Room class' do + + describe "Room instantiation" do + before do + @room = Hotel::Room.new({room_number: 1, price: 200}) + end + + it "it is an instance of Room" do + expect(@room).must_be_kind_of Hotel::Room + end + + it "throws an argument error with a invalid room_number" do + expect{ + Hotel::Room.new({room_number: 0, price: 200}) + }.must_raise ArgumentError + end + + it "is set up for specific attributes and data types" do + [:room_number,:price].each do |prop| + expect(@room).must_respond_to prop + end + + expect(@room.room_number).must_be_kind_of Integer + expect(@room.price).must_be_kind_of Integer + end + + end +end +# +# describe 'hotel' do +# it 'returns the string "this is a hotel"' do +# result = hotel() +# expect(result).must_equal "this is a hotel" +# end +# end +# end From 7100dcdd9caa13477676a66364dd8b18dab76115 Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Thu, 6 Sep 2018 15:41:10 -0700 Subject: [PATCH 03/13] completed tests and methods for room and reservation classes --- lib/reservation.rb | 14 ++++------ spec/reservation_spec.rb | 59 ++++++++++++++-------------------------- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 82d2860d0..b16ed9a14 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -9,18 +9,16 @@ def initialize(input) @room = input[:room] @check_in = Date.strptime(input[:check_in], '%m/%d/%Y') @check_out = Date.strptime(input[:check_out], '%m/%d/%Y') - @cost = input[:cost] + @cost = calculate_cost end - # def room_reserved - # return @room - # - what is the room associated with this reservation - # - return room instance with this reservation - # end + def room_reserved + return @room + end def calculate_cost - # total_days = (@check_out - @check_in).to_i - # return (total_days * @room.Room.price) + total_days = (@check_out - @check_in).to_i + return (total_days * @room.price) end end diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index 8d63fac7d..b84eb40de 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -6,8 +6,8 @@ describe "Reservation instantiation" do before do - @room = Hotel::Room.new({room_number: 1, price: 200}) - @res_1 = Hotel::Reservation.new({room: @room, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) + @honeymoon_suite = Hotel::Room.new({room_number: 1, price: 200}) + @res_1 = Hotel::Reservation.new({room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) end it "it is an instance of Reservation" do @@ -27,47 +27,28 @@ end describe 'room_reserved' do - it "returns the room instance associated with this reservation" do + before do + @honeymoon_suite = Hotel::Room.new({room_number: 1, price: 200}) + @res_2 = Hotel::Reservation.new({room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) end + it "returns the room instance associated with this reservation" do + expect(@res_2.room_reserved).must_equal @honeymoon_suite + expect(@res_2).must_be_kind_of Hotel::Reservation + end end - # - # describe "calculate_cost" do - # it "returns total cost of room per night" do - # - # room_data = { - # room_number: 2, - # price: 200 - # } - # - # hyatt = Hotel::Room.new(room_data) - # - # expect(hyatt.calculate_cost(5)).must_equal 1000 - # end - # end - - # describe "calculate_cost" do - # it "returns total cost of room per night" do - # - # room_data = { - # room_number: 2, - # price: 200 - # } - # - # hyatt = Hotel::Room.new(room_data) - # - # reservation_data = { - # rooms: hyatt, - # check_in: (2018, 01, 10), - # check_out: (2018, 01, 17), - # cost: hyatt.Room.price - # } - # - # reservation_2 = Hotel::Reservation() - # # - # expect(hyatt.calculate_cost('1/10/2018', '01/12/2018')).must_equal 400 - # end + describe 'calculate_cost' do + before do + @honeymoon_suite = Hotel::Room.new({room_number: 1, price: 200}) + @res_3 = Hotel::Reservation.new({room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: nil}) + end + it "returns cost of room based on days reserved" do + expect(@res_3.check_in).must_be_kind_of Date + expect(@res_3.check_out).must_be_kind_of Date + expect(@res_3.calculate_cost).must_equal 1400 + end + end end From 3a5bba77ecf551972441040e869b0e5f575412b6 Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Thu, 6 Sep 2018 17:25:44 -0700 Subject: [PATCH 04/13] added new variable to reservation class - reservation_id --- lib/reservation.rb | 3 ++- lib/reservation_mngr.rb | 25 +++++++++++++++++-------- spec/reservation_spec.rb | 7 ++++--- spec/room_spec.rb | 8 -------- spec/spec_helper.rb | 1 + 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index b16ed9a14..8bfc47b1c 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -3,9 +3,10 @@ module Hotel class Reservation - attr_accessor :room, :check_in, :check_out, :cost + attr_accessor :reservation_id, :room, :check_in, :check_out, :cost def initialize(input) + @reservation_id = input[:reservation_id] @room = input[:room] @check_in = Date.strptime(input[:check_in], '%m/%d/%Y') @check_out = Date.strptime(input[:check_out], '%m/%d/%Y') diff --git a/lib/reservation_mngr.rb b/lib/reservation_mngr.rb index 9908eecf0..1f4a167fe 100644 --- a/lib/reservation_mngr.rb +++ b/lib/reservation_mngr.rb @@ -1,29 +1,38 @@ module Hotel class Reservation_mngr - attr_reader :rooms, :reservations, + attr_reader :rooms, :reservations def initialize - @rooms = (array of rooms (1-20)) - @reservations = reservations (array of reservations) + @rooms = input[:rooms].nil? [] : input[:rooms] + @reservations = input[:reservations].nil? [] : input[:reservations] @price = 200 end def list_rooms - return @rooms + # if @rooms == nil + # 20.times do |i| + # @rooms << Hotel::Room.new({room_number: "#{i + 1}".to_i, price: 200}) + # end + # return @rooms end - def find_room(date-date) + def list_reservations + # return @reservations end - def reserve_room + def find_room(check_in, check_out) + end - def list_reservations + def reserve_room + end - def get_total + def get_total(reservation_id) + end + end end diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index b84eb40de..cf7a5e7b5 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -7,7 +7,7 @@ describe "Reservation instantiation" do before do @honeymoon_suite = Hotel::Room.new({room_number: 1, price: 200}) - @res_1 = Hotel::Reservation.new({room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) + @res_1 = Hotel::Reservation.new({reservation_id: 1, room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) end it "it is an instance of Reservation" do @@ -19,6 +19,7 @@ expect(@res_1).must_respond_to prop end + expect(@res_1.reservation_id).must_be_kind_of Integer expect(@res_1.room).must_be_kind_of Hotel::Room expect(@res_1.check_in).must_be_kind_of Date expect(@res_1.check_out).must_be_kind_of Date @@ -29,7 +30,7 @@ describe 'room_reserved' do before do @honeymoon_suite = Hotel::Room.new({room_number: 1, price: 200}) - @res_2 = Hotel::Reservation.new({room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) + @res_2 = Hotel::Reservation.new({reservation_id: 1, room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) end it "returns the room instance associated with this reservation" do @@ -41,7 +42,7 @@ describe 'calculate_cost' do before do @honeymoon_suite = Hotel::Room.new({room_number: 1, price: 200}) - @res_3 = Hotel::Reservation.new({room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: nil}) + @res_3 = Hotel::Reservation.new({reservation_id: 2, room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: nil}) end it "returns cost of room based on days reserved" do diff --git a/spec/room_spec.rb b/spec/room_spec.rb index d2b3ff943..08c9011fb 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -28,11 +28,3 @@ end end -# -# describe 'hotel' do -# it 'returns the string "this is a hotel"' do -# result = hotel() -# expect(result).must_equal "this is a hotel" -# end -# end -# end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c199377a7..bc02ee97c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,3 +10,4 @@ # Require_relative your lib files here! require_relative '../lib/reservation' require_relative '../lib/room' +require_relative '../lib/Reservation_mngr' From f345ac9091837de4eb3b07a9102db19d8ec240fd Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Fri, 7 Sep 2018 17:31:39 -0700 Subject: [PATCH 05/13] Working on reservation_mngr test for creating a reservation --- lib/reservation_mngr.rb | 51 +++++++++++++++----------- lib/room.rb | 6 +++- spec/reservation_mngr_spec.rb | 67 +++++++++++++++++++++++++++++++++++ spec/reservation_spec.rb | 2 +- spec/room_spec.rb | 1 - 5 files changed, 103 insertions(+), 24 deletions(-) create mode 100644 spec/reservation_mngr_spec.rb diff --git a/lib/reservation_mngr.rb b/lib/reservation_mngr.rb index 1f4a167fe..88592d7bc 100644 --- a/lib/reservation_mngr.rb +++ b/lib/reservation_mngr.rb @@ -1,37 +1,46 @@ +require 'time' +require 'date' + module Hotel class Reservation_mngr attr_reader :rooms, :reservations def initialize - @rooms = input[:rooms].nil? [] : input[:rooms] - @reservations = input[:reservations].nil? [] : input[:reservations] - @price = 200 + @rooms = build_room_list + @reservations = [] end - def list_rooms - # if @rooms == nil - # 20.times do |i| - # @rooms << Hotel::Room.new({room_number: "#{i + 1}".to_i, price: 200}) - # end - # return @rooms - end - - def list_reservations - # return @reservations + def build_room_list + rooms = [] + 20.times do |i| + rooms << Hotel::Room.new({room_number: "#{i + 1}".to_i, price: 200}) + end + return rooms end def find_room(check_in, check_out) - - end - - def reserve_room - + return @rooms.first + # availability = [] + # @rooms.length.times do |i| + # if @rooms[i][:check_in] !>= Date.strptime(check_in) && @rooms[i][:check_out] !< Date.strptime(check_out) + # availability << @rooms[i] + # end + # end + # return availability end - def get_total(reservation_id) - - end + # def create_reservation(check_in, check_out) + # room = find_room(check_in, check_out) + # + # reservation = Reservation.new(...) + # @reservations << reservation + # return reservation + # end + # + # def get_total(reservation_id) + # + # end end diff --git a/lib/room.rb b/lib/room.rb index 847194c94..261c0175a 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,8 +1,10 @@ require 'time' module Hotel + class Room - attr_reader :room_number, :price + attr_accessor :room_number + attr_reader :price ROOM_NUMBERS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] @@ -16,5 +18,7 @@ def initialize(input) raise ArgumentError end end + end + end diff --git a/spec/reservation_mngr_spec.rb b/spec/reservation_mngr_spec.rb new file mode 100644 index 000000000..073ca457e --- /dev/null +++ b/spec/reservation_mngr_spec.rb @@ -0,0 +1,67 @@ +require_relative 'spec_helper' + +require 'date' + +describe 'Reservation_mngr class' do + + describe "Reservation_mngr instantiation" do + before do + @room = Hotel::Room.new( {room_number: 1, price: 200} ) + + @res_1 = Hotel::Reservation.new( { reservation_id: 1, room: @room, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1400 } ) + + @front_desk = Hotel::Reservation_mngr.new() + end + + it "is an instance of Reservation_mngr" do + expect(@front_desk).must_be_kind_of Hotel::Reservation_mngr + end + + it "is set up for specific attributes and data types" do + [:rooms, :reservations].each do |prop| + expect(@front_desk).must_respond_to prop + end + + expect(@front_desk.rooms).must_be_kind_of Array + expect(@front_desk.reservations).must_be_kind_of Array + end + end + + describe "build_room_list" do + before do + @front_desk = Hotel::Reservation_mngr.new() + @room_list = @front_desk.build_room_list + end + + it "returns an array length of 20" do + expect(@room_list.length).must_equal 20 + end + end + + describe "find_room" do + before do + @front_desk = Hotel::Reservation_mngr.new() + end + + it "returns a room that's available" do + room = @front_desk.find_room("01/03/1988", "01/10/1988") + expect(room.room_number).must_equal 1 + end + + it "omits rooms that aren't available" do + skip + res1 = @front_desk.create_reservation("01/03/1988", "01/10/1988") + res2 = @front_desk.create_reservation("01/09/1988", "01/17/1988") + + room = @front_desk.find_room("01/03/1988", "01/14/1988") + expect(room.room_number).must_equal 3 + end + end + + # describe "create_reservation" do + # before do + # @front_desk = Hotel::Reservation_mngr.new() + # end + # end + +end diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index cf7a5e7b5..a242eba20 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -10,7 +10,7 @@ @res_1 = Hotel::Reservation.new({reservation_id: 1, room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) end - it "it is an instance of Reservation" do + it "is an instance of Reservation" do expect(@res_1).must_be_kind_of Hotel::Reservation end diff --git a/spec/room_spec.rb b/spec/room_spec.rb index 08c9011fb..77ed2d721 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -25,6 +25,5 @@ expect(@room.room_number).must_be_kind_of Integer expect(@room.price).must_be_kind_of Integer end - end end From 261d7c6fe5de972e5866ab41bc0ce118f2923ecf Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Sun, 9 Sep 2018 02:14:11 -0700 Subject: [PATCH 06/13] Completed wave 1 --- lib/reservation_mngr.rb | 46 ++++++++++++++++------- spec/reservation_mngr_spec.rb | 71 +++++++++++++++++++++++++++++++---- 2 files changed, 97 insertions(+), 20 deletions(-) diff --git a/lib/reservation_mngr.rb b/lib/reservation_mngr.rb index 88592d7bc..4231180c4 100644 --- a/lib/reservation_mngr.rb +++ b/lib/reservation_mngr.rb @@ -1,14 +1,22 @@ +require 'pry' + require 'time' require 'date' + +require_relative 'reservation' + module Hotel - class Reservation_mngr + class Reservation_mngr < Reservation + attr_reader :rooms, :reservations + attr_accessor :current_res_id def initialize @rooms = build_room_list @reservations = [] + @current_res_id = 1 end def build_room_list @@ -30,18 +38,30 @@ def find_room(check_in, check_out) # return availability end - # def create_reservation(check_in, check_out) - # room = find_room(check_in, check_out) - # - # reservation = Reservation.new(...) - # @reservations << reservation - # return reservation - # end - # - # def get_total(reservation_id) - # - # end + def create_reservation(check_in, check_out) + raise ArgumentError if check_out == nil + raise ArgumentError if check_in == nil + raise ArgumentError if check_out < check_in + raise ArgumentError if check_in > check_out - end + room = find_room(check_in, check_out) + reservation = Hotel::Reservation.new(reservation_id: @current_res_id, room: room, check_in: check_in, check_out: check_out) + + @reservations << reservation + @current_res_id += 1 + return reservation + end + + def get_total(reservation_id) + raise ArgumentError if reservation_id.to_s !~ /\d/ + + @reservations.each do |reservation| + if reservation.reservation_id == reservation_id + return reservation.calculate_cost + end + end + return 1000 + end + end end diff --git a/spec/reservation_mngr_spec.rb b/spec/reservation_mngr_spec.rb index 073ca457e..e509ca2a0 100644 --- a/spec/reservation_mngr_spec.rb +++ b/spec/reservation_mngr_spec.rb @@ -50,18 +50,75 @@ it "omits rooms that aren't available" do skip - res1 = @front_desk.create_reservation("01/03/1988", "01/10/1988") - res2 = @front_desk.create_reservation("01/09/1988", "01/17/1988") + res_1 = @front_desk.create_reservation("01/03/1988", "01/10/1988") + res_2 = @front_desk.create_reservation("01/09/1988", "01/17/1988") room = @front_desk.find_room("01/03/1988", "01/14/1988") + expect(res_1) + expect(res_2) expect(room.room_number).must_equal 3 end end - # describe "create_reservation" do - # before do - # @front_desk = Hotel::Reservation_mngr.new() - # end - # end + describe "create_reservation" do + before do + @room = Hotel::Room.new( {room_number: 1, price: 200} ) + @front_desk = Hotel::Reservation_mngr.new() + end + + it "throws an ArgumentError if check_out is before check_in" do + expect{@front_desk.create_reservation("01/10/2018", "01/09/2018")}.must_raise ArgumentError + end + + it "throws an ArgumentError if check_in is after check_out" do + expect{@front_desk.create_reservation("01/18/1988", "01/17/1988")}.must_raise ArgumentError + end + + it "throws an ArgumentError if check_in is nil" do + expect{@front_desk.create_reservation(nil, "01/17/1988")}.must_raise ArgumentError + end + + it "throws an ArgumentError if check_out is nil" do + expect{@front_desk.create_reservation("01/18/1988", nil)}.must_raise ArgumentError + end + + it "throws an ArgumentError if check_in and check_out are both nil" do + expect{@front_desk.create_reservation(nil, nil)}.must_raise ArgumentError + end + + it "stores reservation instance to class variable - reservations" do + @front_desk.create_reservation("01/10/2018", "01/17/2018") + res = @front_desk.reservations.length + expect(res).must_equal 1 + end + + it "increases reservation_id by 1" do + expect(@front_desk.current_res_id).must_equal 1 + @front_desk.create_reservation("01/10/2018", "01/17/2018") + expect(@front_desk.current_res_id).must_equal 2 + end + + it "returns a reservation" do + expect(@front_desk.create_reservation("01/10/2018", "01/17/2018")).must_be_kind_of Hotel::Reservation + end + end + + describe "get_total" do + before do + @front_desk = Hotel::Reservation_mngr.new() + + @front_desk.create_reservation("01/10/2018", "01/17/2018") + end + + it "throws an ArgumentError if reservation id invalid" do + + expect{@front_desk.get_total("A")}.must_raise ArgumentError + end + + it "returns reservation if id matches" do + expect(@front_desk.get_total(1)).must_equal 1400 + end + + end end From 45f6dd8f0844332a8d57574bf14e27f04c381acd Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Mon, 10 Sep 2018 01:18:22 -0700 Subject: [PATCH 07/13] on last test for wave 2; how to test if all rooms are taken, raise an argument error --- lib/reservation_mngr.rb | 41 ++++++++++++++++++++++------------- spec/reservation_mngr_spec.rb | 34 +++++++++++++++++++---------- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/lib/reservation_mngr.rb b/lib/reservation_mngr.rb index 4231180c4..0eea42223 100644 --- a/lib/reservation_mngr.rb +++ b/lib/reservation_mngr.rb @@ -1,5 +1,3 @@ -require 'pry' - require 'time' require 'date' @@ -16,6 +14,9 @@ class Reservation_mngr < Reservation def initialize @rooms = build_room_list @reservations = [] + if @reservations.length > 20 + raise ArgumentError + end @current_res_id = 1 end @@ -27,27 +28,38 @@ def build_room_list return rooms end - def find_room(check_in, check_out) - return @rooms.first - # availability = [] - # @rooms.length.times do |i| - # if @rooms[i][:check_in] !>= Date.strptime(check_in) && @rooms[i][:check_out] !< Date.strptime(check_out) - # availability << @rooms[i] - # end - # end - # return availability - end - - def create_reservation(check_in, check_out) + def check_dates(check_in, check_out) raise ArgumentError if check_out == nil raise ArgumentError if check_in == nil raise ArgumentError if check_out < check_in raise ArgumentError if check_in > check_out + end + + def find_room(check_in, check_out) + + @rooms.each do |room| + rm_avail = true + @reservations.each do |reservation| + if room.room_number == reservation.room.room_number + if Date.strptime(check_in, '%m/%d/%Y') >= reservation.check_in && Date.strptime(check_out, '%m/%d/%Y') < reservation.check_out + rm_avail = false + break + end + end + end + if rm_avail + return room + end + end + end + def create_reservation(check_in, check_out) + check_dates(check_in, check_out) room = find_room(check_in, check_out) reservation = Hotel::Reservation.new(reservation_id: @current_res_id, room: room, check_in: check_in, check_out: check_out) @reservations << reservation + @current_res_id += 1 return reservation end @@ -60,7 +72,6 @@ def get_total(reservation_id) return reservation.calculate_cost end end - return 1000 end end diff --git a/spec/reservation_mngr_spec.rb b/spec/reservation_mngr_spec.rb index e509ca2a0..3a7e1d573 100644 --- a/spec/reservation_mngr_spec.rb +++ b/spec/reservation_mngr_spec.rb @@ -25,6 +25,10 @@ expect(@front_desk.rooms).must_be_kind_of Array expect(@front_desk.reservations).must_be_kind_of Array end + + it "returns an error if number of reservations exceeds 20" do + expect{@front_desk.reservations}.must_raise ArgumentError + end end describe "build_room_list" do @@ -41,25 +45,33 @@ describe "find_room" do before do @front_desk = Hotel::Reservation_mngr.new() + @room_list = @front_desk.build_room_list + @front_desk.find_room("01/03/2018", "01/10/2018") + @rez = [] end it "returns a room that's available" do - room = @front_desk.find_room("01/03/1988", "01/10/1988") - expect(room.room_number).must_equal 1 + res_1 = @front_desk.create_reservation("01/03/2018", "01/10/2018") + expect(res_1.room.room_number).must_equal 1 end - it "omits rooms that aren't available" do - skip - res_1 = @front_desk.create_reservation("01/03/1988", "01/10/1988") - res_2 = @front_desk.create_reservation("01/09/1988", "01/17/1988") + it "returns next available room" do + @res_1 = @front_desk.create_reservation("01/03/2018", "01/10/2018") + @res_2 = @front_desk.create_reservation("01/03/2018", "01/07/2018") + expect(@res_2.room.room_number).must_equal 2 + end - room = @front_desk.find_room("01/03/1988", "01/14/1988") - expect(res_1) - expect(res_2) - expect(room.room_number).must_equal 3 + it "returns length of array when all rooms reserved" do + 20.times do |i| + @front_desk.create_reservation("01/03/2018", "01/10/2018") + end + rez = @front_desk.reservations + expect(rez.length).must_equal 20 end + end + describe "create_reservation" do before do @room = Hotel::Room.new( {room_number: 1, price: 200} ) @@ -106,7 +118,7 @@ describe "get_total" do before do @front_desk = Hotel::Reservation_mngr.new() - + @front_desk.create_reservation("01/10/2018", "01/17/2018") end From 4e65aa703d88c17dc7eae71c82568801d186b99c Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Mon, 10 Sep 2018 08:43:49 -0700 Subject: [PATCH 08/13] pass most test and completed wave 2; ran simplecov and guard --- Guardfile | 2 +- lib/reservation_mngr.rb | 6 +++--- spec/reservation_mngr_spec.rb | 11 +++++++---- spec/spec_helper.rb | 5 +++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Guardfile b/Guardfile index 6760f9177..fa59fc3ef 100644 --- a/Guardfile +++ b/Guardfile @@ -1,4 +1,4 @@ -guard :minitest, bundler: false, rubygems: false do +guard :minitest, bundler: false, autorun: false, rubygems: false do # with Minitest::Spec watch(%r{^spec/(.*)_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } diff --git a/lib/reservation_mngr.rb b/lib/reservation_mngr.rb index 0eea42223..e0e6e95f0 100644 --- a/lib/reservation_mngr.rb +++ b/lib/reservation_mngr.rb @@ -14,9 +14,6 @@ class Reservation_mngr < Reservation def initialize @rooms = build_room_list @reservations = [] - if @reservations.length > 20 - raise ArgumentError - end @current_res_id = 1 end @@ -59,6 +56,9 @@ def create_reservation(check_in, check_out) reservation = Hotel::Reservation.new(reservation_id: @current_res_id, room: room, check_in: check_in, check_out: check_out) @reservations << reservation + if @reservations.length > 20 + raise ArgumentError + end @current_res_id += 1 return reservation diff --git a/spec/reservation_mngr_spec.rb b/spec/reservation_mngr_spec.rb index 3a7e1d573..30deae1d7 100644 --- a/spec/reservation_mngr_spec.rb +++ b/spec/reservation_mngr_spec.rb @@ -25,10 +25,6 @@ expect(@front_desk.rooms).must_be_kind_of Array expect(@front_desk.reservations).must_be_kind_of Array end - - it "returns an error if number of reservations exceeds 20" do - expect{@front_desk.reservations}.must_raise ArgumentError - end end describe "build_room_list" do @@ -110,6 +106,13 @@ expect(@front_desk.current_res_id).must_equal 2 end + it "returns an error if number of reservations exceeds 20" do + 20.times do + @front_desk.create_reservation("01/03/2018", "01/10/2018") + end + expect{@front_desk.create_reservation("01/03/2018", "01/10/2018")}.must_raise ArgumentError + end + it "returns a reservation" do expect(@front_desk.create_reservation("01/10/2018", "01/17/2018")).must_be_kind_of Hotel::Reservation end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bc02ee97c..0f534761e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,10 @@ - +require 'simplecov' +SimpleCov.start require 'minitest' require 'minitest/autorun' require 'minitest/reporters' -# Add simplecov + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From f93a799f30db4798d5b357d410ac6f57ec991c20 Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Mon, 10 Sep 2018 08:44:40 -0700 Subject: [PATCH 09/13] created a refactor.txt file --- spec/refactor.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/refactor.txt diff --git a/spec/refactor.txt b/spec/refactor.txt new file mode 100644 index 000000000..e37879a08 --- /dev/null +++ b/spec/refactor.txt @@ -0,0 +1,9 @@ +1. Move ArgumentErrors to check_dates method + +2. Refactor find_rooms method - make a new method to minimize nested loops + +3. Build rooms before creating reservation_mngr instances + +4. Change name of "rez" in reservation_mngr test ln 64 + +5. Change name of "@rez" in reservation_mngr test ln 46 From 17b929ba5ad181630e20e57e334dfa6e4dd8029f Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Mon, 10 Sep 2018 08:47:34 -0700 Subject: [PATCH 10/13] wrote test for room initialize room price --- spec/room_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/room_spec.rb b/spec/room_spec.rb index 77ed2d721..b4bcec3db 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -13,7 +13,13 @@ it "throws an argument error with a invalid room_number" do expect{ - Hotel::Room.new({room_number: 0, price: 200}) + Hotel::Room.new({room_number: 1, price: 200}) + }.must_raise ArgumentError + end + + it "throws an argument error if price is not 200" do + expect{ + Hotel::Room.new({room_number: 0, price: 400}) }.must_raise ArgumentError end From db1d8224eeb44882a3cc7dbb0c268b0dd734fc14 Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Mon, 10 Sep 2018 08:49:44 -0700 Subject: [PATCH 11/13] correct test for room price --- spec/room_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/room_spec.rb b/spec/room_spec.rb index b4bcec3db..841ce6fe9 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -13,13 +13,13 @@ it "throws an argument error with a invalid room_number" do expect{ - Hotel::Room.new({room_number: 1, price: 200}) + Hotel::Room.new({room_number: 0, price: 200}) }.must_raise ArgumentError end it "throws an argument error if price is not 200" do expect{ - Hotel::Room.new({room_number: 0, price: 400}) + Hotel::Room.new({room_number: 1, price: 400}) }.must_raise ArgumentError end From c5cb16e14195d6d1fd357a698bfd5fc7dfa07be0 Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Sat, 29 Sep 2018 15:09:35 -0700 Subject: [PATCH 12/13] made changes based on instructor feedback; removed cost from from reservation and left that responsibility solely to reservation manager. Removed reservation_id from attributes - reservation doesn't need an id if all rerservations can be viewed via @reservations or by searching for an available room using room number, check_in, and check_out. Currently working on creating a method to display all available rooms (not in reservations). --- lib/hotel.rb | 3 ++ lib/psuedocode | 70 +++++++++++++++++++++++++++++++++++ lib/reservation.rb | 10 +---- lib/reservation_mngr.rb | 69 +++++++++++++++++++++------------- lib/room.rb | 4 +- spec/reservation_mngr_spec.rb | 49 ++++++++---------------- spec/reservation_spec.rb | 23 ++---------- spec/room_spec.rb | 10 ++++- spec/spec_helper.rb | 1 + 9 files changed, 148 insertions(+), 91 deletions(-) create mode 100644 lib/hotel.rb create mode 100644 lib/psuedocode diff --git a/lib/hotel.rb b/lib/hotel.rb new file mode 100644 index 000000000..8439b5843 --- /dev/null +++ b/lib/hotel.rb @@ -0,0 +1,3 @@ +def hotel + return "this is a hotel" +end diff --git a/lib/psuedocode b/lib/psuedocode new file mode 100644 index 000000000..019010cf7 --- /dev/null +++ b/lib/psuedocode @@ -0,0 +1,70 @@ +RESERVATION_MNGER + +def list_rooms + returns array of all room instances +end + +def find_rooms(room_number) + returns room instance that matches room_number + ? call find_room instead? +end + +def find_available_room(specific_date) + returns an instance of room that is available for a specific date + how do i know it's available? + ask all of the reservations "is this room under any reservations for some specific date?" +end + +def reserve_room(room_number, start_date, end_date) + - takes room instance that matches room number + - make one new reservation for one room, for given start_date and end_date + - give the new reservation instance the room instance from step one + ? - changes availability for a period of time +end + +def list_reservations + - returns array of all reservation instances +end + +def find_reservation(reservation_id) + - returns reservation instance that matches reservation id + ? call find_reservation +end + +def get_total(reservation_id) + - calculates each room and number of nights reserved + - returns total +end + + +ROOM + +def current_status + - returns available or unavailable +end + +def availability + - returns date range of when room is available +end + +def cost(number_of_nights) + - returns cost * number of nights reserved +end + +RESERVATION + +def room_reserved + - what is the room associated with this reservation + - return room instance is associated with this reservation +end + +def reservation_date + - returns date reservation begins and ends + - example: 02/02/2018 - 02/04/2018 + - example: 2 days + ? tricky/fuzzy/needs to be investigated: what data type is this going to be? +end + +def total_room_cost + - calculates rooms_reserved * cost +end diff --git a/lib/reservation.rb b/lib/reservation.rb index 8bfc47b1c..9608453fe 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -3,24 +3,18 @@ module Hotel class Reservation - attr_accessor :reservation_id, :room, :check_in, :check_out, :cost + attr_accessor :room, :check_in, :check_out def initialize(input) - @reservation_id = input[:reservation_id] @room = input[:room] @check_in = Date.strptime(input[:check_in], '%m/%d/%Y') @check_out = Date.strptime(input[:check_out], '%m/%d/%Y') - @cost = calculate_cost end def room_reserved return @room end - def calculate_cost - total_days = (@check_out - @check_in).to_i - return (total_days * @room.price) - end - end + end diff --git a/lib/reservation_mngr.rb b/lib/reservation_mngr.rb index e0e6e95f0..35d0ea85a 100644 --- a/lib/reservation_mngr.rb +++ b/lib/reservation_mngr.rb @@ -1,20 +1,19 @@ require 'time' require 'date' +require 'pry' require_relative 'reservation' module Hotel - class Reservation_mngr < Reservation + class ReservationManager < Reservation attr_reader :rooms, :reservations - attr_accessor :current_res_id def initialize @rooms = build_room_list @reservations = [] - @current_res_id = 1 end def build_room_list @@ -33,43 +32,61 @@ def check_dates(check_in, check_out) end def find_room(check_in, check_out) - - @rooms.each do |room| - rm_avail = true - @reservations.each do |reservation| - if room.room_number == reservation.room.room_number - if Date.strptime(check_in, '%m/%d/%Y') >= reservation.check_in && Date.strptime(check_out, '%m/%d/%Y') < reservation.check_out - rm_avail = false - break - end - end - end - if rm_avail - return room + # find a way to use the find enumerable + # rm_avail = true + # @reservations.each do |reservation| + # if room.room_number == reservation.room.room_number + # if Date.strptime(check_in, '%m/%d/%Y') >= reservation.check_in && Date.strptime(check_out, '%m/%d/%Y') < reservation.check_out + # rm_avail = false + # break + # end + # else + # rm_avail = false + # end + # end + # if rm_avail + # return room + # end + check_in = Date.strptime(check_in, '%m/%d/%Y') + check_out = Date.strptime(check_out, '%m/%d/%Y') + + unavailable = @reservations.collect do |reservation| + if check_in >= reservation.check_in && check_in < reservation.check_out + reservation.room end end + if unavailable.length == 20 + return "No rooms available" + else + return @rooms[unavailable.length] + end end def create_reservation(check_in, check_out) check_dates(check_in, check_out) room = find_room(check_in, check_out) - reservation = Hotel::Reservation.new(reservation_id: @current_res_id, room: room, check_in: check_in, check_out: check_out) + reservation = Hotel::Reservation.new(room: room, check_in: check_in, check_out: check_out) - @reservations << reservation - if @reservations.length > 20 + + if reservation.room.room_number < 1 && reservation.room.room_number > 20 raise ArgumentError end - - @current_res_id += 1 + @reservations << reservation return reservation end - def get_total(reservation_id) - raise ArgumentError if reservation_id.to_s !~ /\d/ - + def get_total(room, check_in, check_out) @reservations.each do |reservation| - if reservation.reservation_id == reservation_id - return reservation.calculate_cost + if reservation.room.nil? || reservation.room.room_number < 1 || reservation.room.room_number > 20 + raise ArgumentError + elsif reservation.room.room_number == room + if check_in != reservation.check_in || check_out != reservation.check_out + raise ArgumentError + else + date = reservation.check_out - reservation.check_in + price = reservation.room.price + return price * date + end end end end diff --git a/lib/room.rb b/lib/room.rb index 261c0175a..4819f44bf 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -6,11 +6,9 @@ class Room attr_accessor :room_number attr_reader :price - ROOM_NUMBERS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] - def initialize(input) @room_number = input[:room_number] - if @room_number < 1 || @room_number > 21 + if @room_number < 1 || @room_number > 20 raise ArgumentError end @price = input[:price] diff --git a/spec/reservation_mngr_spec.rb b/spec/reservation_mngr_spec.rb index 30deae1d7..76e1a189a 100644 --- a/spec/reservation_mngr_spec.rb +++ b/spec/reservation_mngr_spec.rb @@ -2,19 +2,19 @@ require 'date' -describe 'Reservation_mngr class' do +describe 'ReservationManager class' do - describe "Reservation_mngr instantiation" do + describe "ReservationManager instantiation" do before do @room = Hotel::Room.new( {room_number: 1, price: 200} ) - @res_1 = Hotel::Reservation.new( { reservation_id: 1, room: @room, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1400 } ) + @res_1 = Hotel::Reservation.new( { room: @room, check_in: "01/10/1988", check_out: "01/17/1988"} ) - @front_desk = Hotel::Reservation_mngr.new() + @front_desk = Hotel::ReservationManager.new() end - it "is an instance of Reservation_mngr" do - expect(@front_desk).must_be_kind_of Hotel::Reservation_mngr + it "is an instance of ReservationManager" do + expect(@front_desk).must_be_kind_of Hotel::ReservationManager end it "is set up for specific attributes and data types" do @@ -29,7 +29,7 @@ describe "build_room_list" do before do - @front_desk = Hotel::Reservation_mngr.new() + @front_desk = Hotel::ReservationManager.new() @room_list = @front_desk.build_room_list end @@ -40,10 +40,9 @@ describe "find_room" do before do - @front_desk = Hotel::Reservation_mngr.new() + @front_desk = Hotel::ReservationManager.new() @room_list = @front_desk.build_room_list @front_desk.find_room("01/03/2018", "01/10/2018") - @rez = [] end it "returns a room that's available" do @@ -67,11 +66,10 @@ end - describe "create_reservation" do before do @room = Hotel::Room.new( {room_number: 1, price: 200} ) - @front_desk = Hotel::Reservation_mngr.new() + @front_desk = Hotel::ReservationManager.new() end it "throws an ArgumentError if check_out is before check_in" do @@ -100,19 +98,6 @@ expect(res).must_equal 1 end - it "increases reservation_id by 1" do - expect(@front_desk.current_res_id).must_equal 1 - @front_desk.create_reservation("01/10/2018", "01/17/2018") - expect(@front_desk.current_res_id).must_equal 2 - end - - it "returns an error if number of reservations exceeds 20" do - 20.times do - @front_desk.create_reservation("01/03/2018", "01/10/2018") - end - expect{@front_desk.create_reservation("01/03/2018", "01/10/2018")}.must_raise ArgumentError - end - it "returns a reservation" do expect(@front_desk.create_reservation("01/10/2018", "01/17/2018")).must_be_kind_of Hotel::Reservation end @@ -120,20 +105,16 @@ describe "get_total" do before do - @front_desk = Hotel::Reservation_mngr.new() - - @front_desk.create_reservation("01/10/2018", "01/17/2018") + @front_desk = Hotel::ReservationManager.new() + @front_desk.create_reservation("01/10/1988", "01/17/1988") end - it "throws an ArgumentError if reservation id invalid" do + it "calculates total cost of reservation" do + expect(@front_desk.get_total(1, Date.strptime("01/10/1988", '%m/%d/%Y'), Date.strptime("01/17/1988", '%m/%d/%Y') ) ).must_equal 1400 - expect{@front_desk.get_total("A")}.must_raise ArgumentError - end + @front_desk.create_reservation("01/15/1988", "01/20/1988") - it "returns reservation if id matches" do - expect(@front_desk.get_total(1)).must_equal 1400 + expect(@front_desk.get_total(2, Date.strptime("01/15/1988", '%m/%d/%Y'), Date.strptime("01/20/1988", '%m/%d/%Y') ) ).must_equal 1000 end - end - end diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index a242eba20..a39548567 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -7,7 +7,7 @@ describe "Reservation instantiation" do before do @honeymoon_suite = Hotel::Room.new({room_number: 1, price: 200}) - @res_1 = Hotel::Reservation.new({reservation_id: 1, room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) + @res_1 = Hotel::Reservation.new({room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988"}) end it "is an instance of Reservation" do @@ -15,40 +15,25 @@ end it "is set up for specific attributes and data types" do - [:room, :check_in, :check_out, :cost].each do |prop| + [:room, :check_in, :check_out].each do |prop| expect(@res_1).must_respond_to prop end - expect(@res_1.reservation_id).must_be_kind_of Integer expect(@res_1.room).must_be_kind_of Hotel::Room expect(@res_1.check_in).must_be_kind_of Date expect(@res_1.check_out).must_be_kind_of Date - expect(@res_1.cost).must_be_kind_of Integer end end describe 'room_reserved' do before do @honeymoon_suite = Hotel::Room.new({room_number: 1, price: 200}) - @res_2 = Hotel::Reservation.new({reservation_id: 1, room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: 1000}) + @res_2 = Hotel::Reservation.new({room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988"}) end it "returns the room instance associated with this reservation" do - expect(@res_2.room_reserved).must_equal @honeymoon_suite expect(@res_2).must_be_kind_of Hotel::Reservation - end - end - - describe 'calculate_cost' do - before do - @honeymoon_suite = Hotel::Room.new({room_number: 1, price: 200}) - @res_3 = Hotel::Reservation.new({reservation_id: 2, room: @honeymoon_suite, check_in: "01/10/1988", check_out: "01/17/1988", cost: nil}) - end - - it "returns cost of room based on days reserved" do - expect(@res_3.check_in).must_be_kind_of Date - expect(@res_3.check_out).must_be_kind_of Date - expect(@res_3.calculate_cost).must_equal 1400 + expect(@res_2.room_reserved).must_equal @honeymoon_suite end end diff --git a/spec/room_spec.rb b/spec/room_spec.rb index 841ce6fe9..31f2bcf93 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -15,16 +15,24 @@ expect{ Hotel::Room.new({room_number: 0, price: 200}) }.must_raise ArgumentError + + expect{ + Hotel::Room.new({room_number: 21, price: 200}) + }.must_raise ArgumentError end it "throws an argument error if price is not 200" do + expect{ + Hotel::Room.new({room_number: 1, price: 100}) + }.must_raise ArgumentError + expect{ Hotel::Room.new({room_number: 1, price: 400}) }.must_raise ArgumentError end it "is set up for specific attributes and data types" do - [:room_number,:price].each do |prop| + [:room_number, :price].each do |prop| expect(@room).must_respond_to prop end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0f534761e..962ea4094 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ require 'minitest' require 'minitest/autorun' require 'minitest/reporters' +require 'pry' Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 936183153649bd25aad7481aaab2cb3ea4761485 Mon Sep 17 00:00:00 2001 From: Amber Lynn Date: Mon, 1 Oct 2018 08:52:09 -0700 Subject: [PATCH 13/13] completed design-activity. Did not make changes to code --- design-activity.md | 28 ++++++++++++++++++++++++++++ lib/reservation_mngr.rb | 1 + spec/reservation_mngr_spec.rb | 1 + 3 files changed, 30 insertions(+) create mode 100644 design-activity.md diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..418838c7e --- /dev/null +++ b/design-activity.md @@ -0,0 +1,28 @@ +What classes does each implementation include? Are the lists the same? +Write down a sentence to describe each class. + +The first implementation has a CartEntry class, a ShoppingCart class and an Order class with a total_price method. The second implementation has a price method in the CartEntry class that returns a sum based on unit price and quantity; a price method in the ShoppingCart class that collects the price for each entry and stores in variable named sum which will hold the price totals of all entries; there is a total price method in the Order class that takes the price of a ShoppingCart instance and stores into a variable called subtotal. This subtotal is added by itself and multiplied by a SALES_TAX to return a total for all items in cart. +---------- +How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. + +In the first implementation - To create an order instance, a ShoppingCart instance must also be created. They are tied together. This creates a coupling affect. The second implementation allows each class to calculate a sum. With the first class - the price of each item can be calculated based on its quantity. A shopping cart instance does not need to be created just to get the sum. There is also a price method that returns the sum of (the sum of all items). If one were to just want to see that price for an item based on its quantity, that is done entirely separate from the ShoppingCart class. Lastly there is a total price that DOES require information from another classes method to function. However a total price cannot be assessed without having a shopping cart thus this makes sense. +----- +What data does each class store? How (if at all) does this differ between the two implementations? +The second implementation's classes each have a method that calculates a sum. The first implementation - The order class stores dat of a shopping cart instance and calculates the price using the data from the CartEntry class. +----- +What methods does each class have? How (if at all) does this differ between the two implementations? +The first implementation has an instantiation and a total_price while while the second has a price method for each class except the Order class holds the totl price method. The second method removes dependencies on other classes. +----- +Consider the Order#total_price method. In each implementation: +Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order? +Does total_price directly manipulate the instance variables of other classes? +The first implementation delegates the computation through its dependency on lower level classes like ShoppingCart and CartEntry while the second implementation retains that computation within Order. +---- +If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify? The second implementation seems better because you can assign prices per item based on quantity before placing it in a cart. +---- +Which implementation better adheres to the single responsibility principle? +implementation B +---- + +Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? +Once you've responded to the prompts, git add design-activity.md and git commit! diff --git a/lib/reservation_mngr.rb b/lib/reservation_mngr.rb index 35d0ea85a..c2ec75a63 100644 --- a/lib/reservation_mngr.rb +++ b/lib/reservation_mngr.rb @@ -62,6 +62,7 @@ def find_room(check_in, check_out) end end + def create_reservation(check_in, check_out) check_dates(check_in, check_out) room = find_room(check_in, check_out) diff --git a/spec/reservation_mngr_spec.rb b/spec/reservation_mngr_spec.rb index 76e1a189a..1e0372767 100644 --- a/spec/reservation_mngr_spec.rb +++ b/spec/reservation_mngr_spec.rb @@ -66,6 +66,7 @@ end + describe "create_reservation" do before do @room = Hotel::Room.new( {room_number: 1, price: 200} )