From 67165341817cdb5418be9f420d10ff96f05fdc11 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Tue, 4 Sep 2018 11:25:56 -0700
Subject: [PATCH 01/16] initialized guard, initial tests pass

---
 lib/hotel.rb       | 0
 spec/hotel_spec.rb | 1 +
 2 files changed, 1 insertion(+)
 create mode 100644 lib/hotel.rb
 create mode 100644 spec/hotel_spec.rb

diff --git a/lib/hotel.rb b/lib/hotel.rb
new file mode 100644
index 000000000..e69de29bb
diff --git a/spec/hotel_spec.rb b/spec/hotel_spec.rb
new file mode 100644
index 000000000..ae9c220ea
--- /dev/null
+++ b/spec/hotel_spec.rb
@@ -0,0 +1 @@
+require_relative 'spec_helper'

From 96bc8b653533ffb00e1b79b00f28809ffb450ace Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Tue, 4 Sep 2018 16:22:45 -0700
Subject: [PATCH 02/16] load rooms and create instance of reservation

---
 Guardfile                   |  3 +--
 lib/.keep                   |  0
 lib/booking_system.rb       | 23 +++++++++++++++++++++++
 lib/hotel.rb                |  0
 lib/reservation.rb          | 27 +++++++++++++++++++++++++++
 spec/booking_system_spec.rb | 13 +++++++++++++
 spec/hotel_spec.rb          |  1 -
 spec/reservation_spec.rb    | 17 +++++++++++++++++
 spec/spec_helper.rb         |  3 ++-
 9 files changed, 83 insertions(+), 4 deletions(-)
 delete mode 100644 lib/.keep
 create mode 100644 lib/booking_system.rb
 delete mode 100644 lib/hotel.rb
 create mode 100644 lib/reservation.rb
 create mode 100644 spec/booking_system_spec.rb
 delete mode 100644 spec/hotel_spec.rb
 create mode 100644 spec/reservation_spec.rb

diff --git a/Guardfile b/Guardfile
index 6760f9177..471693a4d 100644
--- a/Guardfile
+++ b/Guardfile
@@ -1,5 +1,4 @@
-guard :minitest, bundler: false, rubygems: false do
-  # with Minitest::Spec
+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" }
   watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
diff --git a/lib/.keep b/lib/.keep
deleted file mode 100644
index e69de29bb..000000000
diff --git a/lib/booking_system.rb b/lib/booking_system.rb
new file mode 100644
index 000000000..fe314e4e6
--- /dev/null
+++ b/lib/booking_system.rb
@@ -0,0 +1,23 @@
+module Hotel
+  class BookingSystem
+    attr_accessor :rooms
+
+    def initialize
+      @rooms = load_rooms
+    end
+
+    def load_rooms
+      rooms = []
+      i = 1
+      20.times do
+        rooms <<
+        {
+          room_num: i,
+          status: :AVAILABLE
+        }
+        i += 1
+      end
+      return rooms
+    end
+  end
+end
diff --git a/lib/hotel.rb b/lib/hotel.rb
deleted file mode 100644
index e69de29bb..000000000
diff --git a/lib/reservation.rb b/lib/reservation.rb
new file mode 100644
index 000000000..7922ad8d2
--- /dev/null
+++ b/lib/reservation.rb
@@ -0,0 +1,27 @@
+module Hotel
+  class Reservation
+    attr_accessor :id, :room, :start_date, :end_date, :price_per_night, :total_cost
+    all_ids = []
+
+    def initialize(reservation)
+      @id = id
+      @room = room
+      @start_date = start_date
+      @end_date = end_date
+      @price_per_night = price_per_night
+    end
+
+    # def self.generate_id
+    #   id = rand(1..100000)
+    #   if all_ids.include?(id)
+    #     raise ArgumentError, "id already exists"
+    #   else all_ids << id
+    #   end
+    #   return id
+    # end
+
+    def choose_room
+    end
+
+  end
+end
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
new file mode 100644
index 000000000..5ab431baf
--- /dev/null
+++ b/spec/booking_system_spec.rb
@@ -0,0 +1,13 @@
+require_relative 'spec_helper'
+require 'date'
+require 'pry'
+
+describe "BookingSystem class" do
+  describe "load rooms" do
+    it "loads rooms in an array" do
+      @rooms = Hotel::BookingSystem.new.load_rooms
+      # binding.pry
+      expect(@rooms).must_be_kind_of Array
+    end
+  end
+end
diff --git a/spec/hotel_spec.rb b/spec/hotel_spec.rb
deleted file mode 100644
index ae9c220ea..000000000
--- a/spec/hotel_spec.rb
+++ /dev/null
@@ -1 +0,0 @@
-require_relative 'spec_helper'
diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb
new file mode 100644
index 000000000..b375f9a9b
--- /dev/null
+++ b/spec/reservation_spec.rb
@@ -0,0 +1,17 @@
+require_relative 'spec_helper'
+require 'date'
+
+describe "Reservation class" do
+
+  describe "Reservation instantiation" do
+    before do
+      @reservation = Hotel::Reservation.new(id: 5, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), price_per_night: 200)
+    end
+
+    it "is an instance of Reservation" do
+      expect(@reservation).must_be_kind_of Hotel::Reservation
+    end
+
+
+  end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 4d1e3fdc8..e9eb98c1b 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -5,4 +5,5 @@
 
 Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
 
-# Require_relative your lib files here!
+require_relative '../lib/reservation'
+require_relative '../lib/booking_system'

From 56c493ed754cd640e88a86c4bc3e87d422530a26 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Wed, 5 Sep 2018 14:02:30 -0700
Subject: [PATCH 03/16] implement make_reservation method, tests pass

---
 lib/booking_system.rb       | 37 +++++++++++++++++++++++++++++++------
 lib/reservation.rb          |  7 ++-----
 spec/booking_system_spec.rb | 21 +++++++++++++++++++++
 spec/reservation_spec.rb    |  5 ++---
 4 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index fe314e4e6..fa3c4899a 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -1,23 +1,48 @@
 module Hotel
   class BookingSystem
-    attr_accessor :rooms
+    attr_accessor :rooms, :reservations
 
     def initialize
       @rooms = load_rooms
+      @reservations = []
     end
 
     def load_rooms
       rooms = []
       i = 1
       20.times do
-        rooms <<
-        {
-          room_num: i,
-          status: :AVAILABLE
-        }
+        rooms << i
         i += 1
       end
       return rooms
     end
+
+    def make_reservation(start_date, end_date)
+      assigned_room = 1
+      reservation = Hotel::Reservation.new(id: 1, room: assigned_room, start_date: start_date, end_date: end_date, price_per_night: 200)
+      @reservations << reservation
+    end
+
+    def assign_available_room(new_d1, new_d2)
+      @reservations.each do |reservation|
+        old_d1 = @reservation.start_date
+        old_d2 = @reservation.end_date
+        unless new_d1.between?(old_d1, old_d2) && new_d2.between?(old_d1, old_d2)
+        return @reservation.room
+        end
+      end
+    end
+
+    #
+    # def find_reservation(id)
+    #   return @reservations.find { |reservation| reservation.id == id }
+    # end
+    #
+    # def total_cost(id)
+    #   find_reservation(id)
+    #   nights = @reservation.end_date - @reservation.start_date
+    #   total_cost = nights * @reservation.price_per_night
+    #   return total_cost
+    # end
   end
 end
diff --git a/lib/reservation.rb b/lib/reservation.rb
index 7922ad8d2..d5250a170 100644
--- a/lib/reservation.rb
+++ b/lib/reservation.rb
@@ -1,9 +1,8 @@
 module Hotel
   class Reservation
     attr_accessor :id, :room, :start_date, :end_date, :price_per_night, :total_cost
-    all_ids = []
 
-    def initialize(reservation)
+    def initialize(id:, room:, start_date:, end_date:, price_per_night:)
       @id = id
       @room = room
       @start_date = start_date
@@ -11,6 +10,7 @@ def initialize(reservation)
       @price_per_night = price_per_night
     end
 
+
     # def self.generate_id
     #   id = rand(1..100000)
     #   if all_ids.include?(id)
@@ -20,8 +20,5 @@ def initialize(reservation)
     #   return id
     # end
 
-    def choose_room
-    end
-
   end
 end
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index 5ab431baf..e8e10da6d 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -3,6 +3,7 @@
 require 'pry'
 
 describe "BookingSystem class" do
+
   describe "load rooms" do
     it "loads rooms in an array" do
       @rooms = Hotel::BookingSystem.new.load_rooms
@@ -10,4 +11,24 @@
       expect(@rooms).must_be_kind_of Array
     end
   end
+
+  describe "make reservation" do
+    before do
+      @system = Hotel::BookingSystem.new
+    end
+    it "makes a reservation" do
+      @system.make_reservation(Date.new(2018,1,1), Date.new(2018,1,5))
+      expect(@system.reservations.length).must_equal 1
+      binding.pry
+
+    end
+
+  end
+
+  describe "assign_available_room" do
+    it "finds the first available room" do
+    end
+
+  end
+
 end
diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb
index b375f9a9b..4c10029a1 100644
--- a/spec/reservation_spec.rb
+++ b/spec/reservation_spec.rb
@@ -1,5 +1,6 @@
 require_relative 'spec_helper'
 require 'date'
+require 'pry'
 
 describe "Reservation class" do
 
@@ -8,10 +9,8 @@
       @reservation = Hotel::Reservation.new(id: 5, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), price_per_night: 200)
     end
 
-    it "is an instance of Reservation" do
+    it "is an reservation of Reservation" do
       expect(@reservation).must_be_kind_of Hotel::Reservation
     end
-
-
   end
 end

From 6f7affed1c23a23fd08bf3989132ac23a4c0e884 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Wed, 5 Sep 2018 16:46:04 -0700
Subject: [PATCH 04/16] serach reservation method and tests in progress

---
 lib/booking_system.rb       | 26 +++++++++++++++----
 spec/booking_system_spec.rb | 50 ++++++++++++++++++++++++++++++-------
 2 files changed, 62 insertions(+), 14 deletions(-)

diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index fa3c4899a..346eec76a 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -10,25 +10,41 @@ def initialize
     def load_rooms
       rooms = []
       i = 1
+
       20.times do
         rooms << i
         i += 1
       end
+
+      # @reservations = rooms.map do |room|
+      #   room = Hotel::Reservation.new(id: nil, room: room, start_date: nil, end_date: nil, price_per_night: 200)
+      # end
       return rooms
     end
 
     def make_reservation(start_date, end_date)
-      assigned_room = 1
+      assigned_room = assign_available_room(start_date, end_date)
       reservation = Hotel::Reservation.new(id: 1, room: assigned_room, start_date: start_date, end_date: end_date, price_per_night: 200)
       @reservations << reservation
     end
 
     def assign_available_room(new_d1, new_d2)
       @reservations.each do |reservation|
-        old_d1 = @reservation.start_date
-        old_d2 = @reservation.end_date
-        unless new_d1.between?(old_d1, old_d2) && new_d2.between?(old_d1, old_d2)
-        return @reservation.room
+        old_d1 = reservation.start_date
+        old_d2 = reservation.end_date
+        if new_d1.between?(old_d1, old_d2) == false && new_d2.between?(old_d1, old_d2) == false && old_d1.between?(new_d1, new_d2) == false && old_d2.between?(new_d1, new_d2) == false
+        return reservation.room
+        end
+      end
+    end
+
+    def search_reservations(specific_date)
+      reservations_within_date = []
+      @reservations.each do |reservation|
+        if specific_date.between?(reservation.start_date, reservation.end_date)
+          reservations_within_date << reservation
+          binding.pry
+          return reservations_within_date
         end
       end
     end
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index e8e10da6d..3822262db 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -4,31 +4,63 @@
 
 describe "BookingSystem class" do
 
+  before do
+    @system = Hotel::BookingSystem.new
+  end
+
   describe "load rooms" do
     it "loads rooms in an array" do
-      @rooms = Hotel::BookingSystem.new.load_rooms
+      @rooms = @system.load_rooms
       # binding.pry
       expect(@rooms).must_be_kind_of Array
     end
+
+    # it "loads each room as an instance of Reservation" do
+    #   @rooms = @system.load_rooms
+    #   expect(@rooms[0]).must_be_instance_of Hotel::Reservation
+    # end
   end
 
   describe "make reservation" do
-    before do
-      @system = Hotel::BookingSystem.new
-    end
     it "makes a reservation" do
       @system.make_reservation(Date.new(2018,1,1), Date.new(2018,1,5))
+      reservation = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
       expect(@system.reservations.length).must_equal 1
-      binding.pry
-
     end
 
   end
 
-  describe "assign_available_room" do
-    it "finds the first available room" do
-    end
+  describe "assign room" do
+    it "assigns the first available room" do
+
+      # @system.make_reservation(Date.new(2018, 1, 1), Date.new(2018, 1, 5))
+
+      reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 7), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      @system.reservations << reservation1
+
+      # @system.make_reservation(Date.new(2018, 1, 6), Date.new(2018, 1, 7))
 
+      reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      @system.reservations << reservation2
+
+
+      reservation3 = Hotel::Reservation.new(id: 3, room: @system.assign_available_room(Date.new(2018, 1, 6), Date.new(2018, 1, 9)), start_date: Date.new(2018, 1, 6), end_date: Date.new(2018, 1, 9), price_per_night: 200)
+      @system.reservations << reservation3
+
+      expect(reservation3.room).must_equal 2
+    end
   end
 
+  describe "search reservation" do
+    it "searches for reservations that fall on a specific date" do
+
+      reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      @system.reservations << reservation1
+
+      reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      @system.reservations << reservation2
+
+      expect(@system.search_reservations(Date.new(2018, 1, 4))).must_be_instance_of Array
+    end
+  end
 end

From e52bc349fd416d9f901fa7eb74fbfb361f38a034 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Fri, 7 Sep 2018 11:02:07 -0700
Subject: [PATCH 05/16] search reservation method all tests passing

---
 lib/booking_system.rb       | 20 +++++++++---
 spec/booking_system_spec.rb | 65 ++++++++++++++++++++++++++++++++++---
 2 files changed, 77 insertions(+), 8 deletions(-)

diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index 346eec76a..43ba4413d 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -38,17 +38,29 @@ def assign_available_room(new_d1, new_d2)
       end
     end
 
-    def search_reservations(specific_date)
+    def search_reservations(start_date_2, end_date_2)
       reservations_within_date = []
       @reservations.each do |reservation|
-        if specific_date.between?(reservation.start_date, reservation.end_date)
+        if reservation.start_date < end_date_2 && start_date_2 <= reservation.end_date
           reservations_within_date << reservation
-          binding.pry
-          return reservations_within_date
+          # binding.pry
         end
       end
+      return reservations_within_date
     end
 
+    # def assign_available_room(start_date_2)
+    #   reservations_within_date = []
+    #   @reservations.each do |reservation|
+    #     if reservation.start_date < end_date_2 && start_date_2 <= reservation.end_date
+    #     elsif reservations_within_date << reservation
+    #       # binding.pry
+    #     end
+    #     return reservations_within_date
+    #   end
+    # end
+    #
+    #
     #
     # def find_reservation(id)
     #   return @reservations.find { |reservation| reservation.id == id }
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index 3822262db..55c777e10 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -52,15 +52,72 @@
   end
 
   describe "search reservation" do
-    it "searches for reservations that fall on a specific date" do
-
+    before do
       reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
       @system.reservations << reservation1
 
-      reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
       @system.reservations << reservation2
+    end
+    it "returns an array of reservations" do
+
+      # reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      # @system.reservations << reservation1
+      #
+      # reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 3), price_per_night: 200)
+      # @system.reservations << reservation2
 
-      expect(@system.search_reservations(Date.new(2018, 1, 4))).must_be_instance_of Array
+      # reservation3 = Hotel::Reservation.new(id: 3, room: 3, start_date: Date.new(2018, 1, 4), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      # @system.reservations << reservation3
+
+      expect(@system.search_reservations(Date.new(2018, 1, 4), Date.new(2018, 1, 8))).must_be_instance_of Array
+    end
+
+    it "returns reservations that fall within a specific date" do
+
+      # reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      # @system.reservations << reservation1
+
+      expect(@system.search_reservations(Date.new(2018, 1, 4), Date.new(2018, 1, 8))[0].id).must_equal 1
+
+    end
+
+    it "returns reservations that are on the same date" do
+      # reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      # @system.reservations << reservation1
+      #
+      # reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      # @system.reservations << reservation2
+      #
+      # reservation3 = Hotel::Reservation.new(id: 3, room: 3, start_date: Date.new(2018, 1, 4), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      # @system.reservations << reservation3
+
+      expect(@system.search_reservations(Date.new(2018, 1, 4), Date.new(2018, 1, 8)).length).must_equal 2
     end
   end
 end
+
+# Hi! In Edges we talked about interesting test cases for date overlaps this afternoon. Here is a full list of all the cases I’ll be looking for when I give feedback:
+#
+# Two date ranges *do* overlap if range A compared to range B:
+# - Same dates
+# - Overlaps in the front
+# - Overlaps in the back
+# - Completely contained
+# - Completely containing
+#
+# Two date ranges are *not* overlapping if range A compared to range B:
+# - Completely before
+# - Completely after
+# - Ends on the checkin date
+# - Starts on the checkout date (edited)
+#
+#
+# start1 = 9
+# end1 = 12
+# start2 = 8
+# end2 = 15
+#
+# (StartDate1 < EndDate2) and (StartDate2 <= EndDate1)
+#
+# true true

From 3850726b6b02ff32b17f959243c1fe2dfaffa9cb Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Fri, 7 Sep 2018 12:13:30 -0700
Subject: [PATCH 06/16] implement more tests for search reservations by date,
 all tests passing

---
 lib/booking_system.rb       |  8 ++++--
 spec/booking_system_spec.rb | 53 ++++++++++++++++++++-----------------
 2 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index 43ba4413d..cf0cf786a 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -41,14 +41,18 @@ def assign_available_room(new_d1, new_d2)
     def search_reservations(start_date_2, end_date_2)
       reservations_within_date = []
       @reservations.each do |reservation|
-        if reservation.start_date < end_date_2 && start_date_2 <= reservation.end_date
+        if
+          reservation.start_date < end_date_2 && start_date_2 < reservation.end_date
           reservations_within_date << reservation
-          # binding.pry
         end
       end
+      # binding.pry
       return reservations_within_date
     end
 
+    # def total_cost(id)
+
+
     # def assign_available_room(start_date_2)
     #   reservations_within_date = []
     #   @reservations.each do |reservation|
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index 55c777e10..a4f492a92 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -51,50 +51,53 @@
     end
   end
 
-  describe "search reservation" do
+  describe "search reservation dates" do
     before do
+
       reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
       @system.reservations << reservation1
 
-      reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 7), end_date: Date.new(2018, 1, 15), price_per_night: 200)
       @system.reservations << reservation2
+
     end
     it "returns an array of reservations" do
 
-      # reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
-      # @system.reservations << reservation1
-      #
-      # reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 3), price_per_night: 200)
-      # @system.reservations << reservation2
+      expect(@system.search_reservations(Date.new(2018, 1, 4), Date.new(2018, 1, 8))).must_be_instance_of Array
+    end
 
-      # reservation3 = Hotel::Reservation.new(id: 3, room: 3, start_date: Date.new(2018, 1, 4), end_date: Date.new(2018, 1, 8), price_per_night: 200)
-      # @system.reservations << reservation3
+    it "returns reservations that overlap on the existing reservation start date" do
+
+      expect(@system.search_reservations(Date.new(2017, 12, 30), Date.new(2018, 1, 5))[0].id).must_equal 1
 
-      expect(@system.search_reservations(Date.new(2018, 1, 4), Date.new(2018, 1, 8))).must_be_instance_of Array
     end
 
-    it "returns reservations that fall within a specific date" do
+    it "returns reservations that overlap on the existing reservation end" do
+
+      expect(@system.search_reservations(Date.new(2018, 1, 10), Date.new(2018, 1, 20))[0].id).must_equal 2
+
+    end
 
-      # reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
-      # @system.reservations << reservation1
+    it "returns multiple reservations that are on the same date" do
 
-      expect(@system.search_reservations(Date.new(2018, 1, 4), Date.new(2018, 1, 8))[0].id).must_equal 1
+      expect(@system.search_reservations(Date.new(2018, 1, 7), Date.new(2018, 1, 15)).length).must_equal 2
 
     end
 
-    it "returns reservations that are on the same date" do
-      # reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
-      # @system.reservations << reservation1
-      #
-      # reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
-      # @system.reservations << reservation2
-      #
-      # reservation3 = Hotel::Reservation.new(id: 3, room: 3, start_date: Date.new(2018, 1, 4), end_date: Date.new(2018, 1, 8), price_per_night: 200)
-      # @system.reservations << reservation3
-
-      expect(@system.search_reservations(Date.new(2018, 1, 4), Date.new(2018, 1, 8)).length).must_equal 2
+    it "does not return reservations that end on the new reservation's start date" do
+
+      expect(@system.search_reservations(Date.new(2018, 1, 15), Date.new(2018, 1, 20)).length).must_equal 0
+
+    end
+
+    it "does not return reservations that start on the new reservation's end date" do
+
+      expect(@system.search_reservations(Date.new(2017, 12, 20), Date.new(2018, 1, 1)).length).must_equal 0
+
     end
+
   end
+
 end
 
 # Hi! In Edges we talked about interesting test cases for date overlaps this afternoon. Here is a full list of all the cases I’ll be looking for when I give feedback:

From f7ed4a76229392caea05af8455f4dfe555e0ecb1 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Fri, 7 Sep 2018 12:26:44 -0700
Subject: [PATCH 07/16] implement find reservation and total cost method, tests
 pass

---
 lib/booking_system.rb       | 21 +++++++++++----------
 spec/booking_system_spec.rb | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index cf0cf786a..728597f66 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -66,15 +66,16 @@ def search_reservations(start_date_2, end_date_2)
     #
     #
     #
-    # def find_reservation(id)
-    #   return @reservations.find { |reservation| reservation.id == id }
-    # end
-    #
-    # def total_cost(id)
-    #   find_reservation(id)
-    #   nights = @reservation.end_date - @reservation.start_date
-    #   total_cost = nights * @reservation.price_per_night
-    #   return total_cost
-    # end
+    def find_reservation(id)
+      reservation = @reservations.find { |reservation| reservation.id == id }
+      return reservation
+    end
+
+    def total_cost(id)
+      reservation = find_reservation(id)
+      nights = reservation.end_date - reservation.start_date
+      total_cost = nights * reservation.price_per_night
+      return total_cost
+    end
   end
 end
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index a4f492a92..e1594d803 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -98,6 +98,25 @@
 
   end
 
+  describe "find reservation method with id" do
+    it "returns the corresponding reservation given id" do
+      reservation = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      @system.reservations << reservation
+
+      expect(@system.find_reservation(1))[0].id.must_equal 1
+    end
+  end
+
+  describe "total cost of reservation" do
+    it "finds the total cost of reservation given id" do
+
+      reservation = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      @system.reservations << reservation
+
+      expect(@system.total_cost(1)).must_equal 800
+    end
+  end
+
 end
 
 # Hi! In Edges we talked about interesting test cases for date overlaps this afternoon. Here is a full list of all the cases I’ll be looking for when I give feedback:

From eaacfbb977dd4173d8220b3df8936011b8f6c146 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Fri, 7 Sep 2018 15:13:50 -0700
Subject: [PATCH 08/16] refactor assign available rooms method

---
 lib/booking_system.rb       | 34 +++++++++++-----------------------
 spec/booking_system_spec.rb | 16 +++++++++++++++-
 2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index 728597f66..173e7ff4f 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -23,19 +23,23 @@ def load_rooms
     end
 
     def make_reservation(start_date, end_date)
-      assigned_room = assign_available_room(start_date, end_date)
-      reservation = Hotel::Reservation.new(id: 1, room: assigned_room, start_date: start_date, end_date: end_date, price_per_night: 200)
+      reservation = Hotel::Reservation.new(id: 1, room: assign_available_room(start_date, end_date), start_date: start_date, end_date: end_date, price_per_night: 200)
       @reservations << reservation
+      # binding.pry
     end
 
-    def assign_available_room(new_d1, new_d2)
+    def assign_available_room(start_date_2, end_date_2)
+      booked_rooms = []
+      available_rooms = []
       @reservations.each do |reservation|
-        old_d1 = reservation.start_date
-        old_d2 = reservation.end_date
-        if new_d1.between?(old_d1, old_d2) == false && new_d2.between?(old_d1, old_d2) == false && old_d1.between?(new_d1, new_d2) == false && old_d2.between?(new_d1, new_d2) == false
-        return reservation.room
+        if
+          reservation.start_date < end_date_2 && start_date_2 < reservation.end_date
+          booked_rooms << reservation.room
         end
       end
+      all_rooms = load_rooms
+      available_rooms = all_rooms - booked_rooms
+      return available_rooms[0]
     end
 
     def search_reservations(start_date_2, end_date_2)
@@ -50,22 +54,6 @@ def search_reservations(start_date_2, end_date_2)
       return reservations_within_date
     end
 
-    # def total_cost(id)
-
-
-    # def assign_available_room(start_date_2)
-    #   reservations_within_date = []
-    #   @reservations.each do |reservation|
-    #     if reservation.start_date < end_date_2 && start_date_2 <= reservation.end_date
-    #     elsif reservations_within_date << reservation
-    #       # binding.pry
-    #     end
-    #     return reservations_within_date
-    #   end
-    # end
-    #
-    #
-    #
     def find_reservation(id)
       reservation = @reservations.find { |reservation| reservation.id == id }
       return reservation
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index e1594d803..26a49fb92 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -46,7 +46,6 @@
 
       reservation3 = Hotel::Reservation.new(id: 3, room: @system.assign_available_room(Date.new(2018, 1, 6), Date.new(2018, 1, 9)), start_date: Date.new(2018, 1, 6), end_date: Date.new(2018, 1, 9), price_per_night: 200)
       @system.reservations << reservation3
-
       expect(reservation3.room).must_equal 2
     end
   end
@@ -143,3 +142,18 @@
 # (StartDate1 < EndDate2) and (StartDate2 <= EndDate1)
 #
 # true true
+
+
+# def search_reservations(start_date_2, end_date_2)
+#   reservations_within_date = []
+#   empty_rooms_within_date = []
+#   @reservations.each do |reservation|
+#     if
+#       reservation.start_date < end_date_2 && start_date_2 < reservation.end_date
+#       reservations_within_date << reservation
+#     else
+#       empty_rooms_within_date << reservation.room
+#     end
+#     # binding.pry
+#   end
+# end

From 5d5c4a3d14acde2435a9d315b5b5fbfc32c66ab5 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Sat, 8 Sep 2018 14:31:28 -0700
Subject: [PATCH 09/16] implement generate id and check method, tests pass

---
 lib/block.rb                | 20 ++++++++++++++++++++
 lib/booking_system.rb       | 20 +++++++++++++++-----
 lib/reservation.rb          | 11 -----------
 spec/block_spec.rb          | 16 ++++++++++++++++
 spec/booking_system_spec.rb | 24 +++++++++++++++++++-----
 spec/reservation_spec.rb    |  2 +-
 spec/spec_helper.rb         |  1 +
 7 files changed, 72 insertions(+), 22 deletions(-)
 create mode 100644 lib/block.rb
 create mode 100644 spec/block_spec.rb

diff --git a/lib/block.rb b/lib/block.rb
new file mode 100644
index 000000000..35255cabe
--- /dev/null
+++ b/lib/block.rb
@@ -0,0 +1,20 @@
+module Hotel
+  class Block < BookingSystem
+    attr_accessor :block_id, :number_of_rooms, :assigned_rooms
+
+    def initialize(id:, number_of_rooms:, assigned_rooms:, start_date:, end_date:, discounted_price:)
+      @id = id
+      @number_of_rooms = number_of_rooms
+      @assigned_rooms = assigned_rooms
+      @start_date = start_date
+      @end_date = end_date
+      @discounted_price = discounted_price
+    end
+
+    def assign_rooms(start_date, end_date)
+      open_rooms 
+
+      # return
+    end
+  end
+end
diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index 173e7ff4f..e482f108d 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -5,6 +5,7 @@ class BookingSystem
     def initialize
       @rooms = load_rooms
       @reservations = []
+      @all_ids = []
     end
 
     def load_rooms
@@ -15,15 +16,11 @@ def load_rooms
         rooms << i
         i += 1
       end
-
-      # @reservations = rooms.map do |room|
-      #   room = Hotel::Reservation.new(id: nil, room: room, start_date: nil, end_date: nil, price_per_night: 200)
-      # end
       return rooms
     end
 
     def make_reservation(start_date, end_date)
-      reservation = Hotel::Reservation.new(id: 1, room: assign_available_room(start_date, end_date), start_date: start_date, end_date: end_date, price_per_night: 200)
+      reservation = Hotel::Reservation.new(id: generate_id, room: assign_available_room(start_date, end_date), start_date: start_date, end_date: end_date, price_per_night: 200)
       @reservations << reservation
       # binding.pry
     end
@@ -59,6 +56,19 @@ def find_reservation(id)
       return reservation
     end
 
+    def generate_id
+      id = rand(1..100000)
+      check_id(id)
+      @all_ids << id
+      return id
+    end
+
+    def check_id(id)
+      if @all_ids.include?(id)
+        raise ArgumentError, "id already exists"
+      end
+    end
+
     def total_cost(id)
       reservation = find_reservation(id)
       nights = reservation.end_date - reservation.start_date
diff --git a/lib/reservation.rb b/lib/reservation.rb
index d5250a170..28be098cc 100644
--- a/lib/reservation.rb
+++ b/lib/reservation.rb
@@ -9,16 +9,5 @@ def initialize(id:, room:, start_date:, end_date:, price_per_night:)
       @end_date = end_date
       @price_per_night = price_per_night
     end
-
-
-    # def self.generate_id
-    #   id = rand(1..100000)
-    #   if all_ids.include?(id)
-    #     raise ArgumentError, "id already exists"
-    #   else all_ids << id
-    #   end
-    #   return id
-    # end
-
   end
 end
diff --git a/spec/block_spec.rb b/spec/block_spec.rb
new file mode 100644
index 000000000..556cfb53d
--- /dev/null
+++ b/spec/block_spec.rb
@@ -0,0 +1,16 @@
+require_relative 'spec_helper'
+require 'date'
+require 'pry'
+
+describe "Block class" do
+
+  describe "Block instantiation" do
+    before do
+      @block = Hotel::Block.new(id: 3, number_of_rooms: 3, assigned_rooms: [3, 4, 5], start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), discounted_price: 150)
+    end
+
+    it "is an instance of block" do
+      expect(@block).must_be_kind_of Hotel::Block
+    end
+  end
+end
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index 26a49fb92..8ade0c5b9 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -14,11 +14,6 @@
       # binding.pry
       expect(@rooms).must_be_kind_of Array
     end
-
-    # it "loads each room as an instance of Reservation" do
-    #   @rooms = @system.load_rooms
-    #   expect(@rooms[0]).must_be_instance_of Hotel::Reservation
-    # end
   end
 
   describe "make reservation" do
@@ -116,6 +111,25 @@
     end
   end
 
+  describe "generate_id" do
+    it "generates an integer id" do
+      expect(@system.generate_id).must_be_kind_of Integer
+    end
+
+    it "assigns id to reservation" do
+      reservation1 = Hotel::Reservation.new(id: @system.generate_id, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      @system.reservations << reservation1
+
+      expect(reservation1.id).must_be_kind_of Integer
+    end
+
+    it "raises an Argument Error if id is not unique" do
+      # binding.pry
+      reservation1 = Hotel::Reservation.new(id: @system.generate_id, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      @system.reservations << reservation1
+      expect { @system.check_id(reservation1.id) }.must_raise ArgumentError
+    end
+  end
 end
 
 # Hi! In Edges we talked about interesting test cases for date overlaps this afternoon. Here is a full list of all the cases I’ll be looking for when I give feedback:
diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb
index 4c10029a1..a6ad8478b 100644
--- a/spec/reservation_spec.rb
+++ b/spec/reservation_spec.rb
@@ -9,7 +9,7 @@
       @reservation = Hotel::Reservation.new(id: 5, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), price_per_night: 200)
     end
 
-    it "is an reservation of Reservation" do
+    it "is an instance of Reservation" do
       expect(@reservation).must_be_kind_of Hotel::Reservation
     end
   end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e9eb98c1b..3c4055ce1 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -7,3 +7,4 @@
 
 require_relative '../lib/reservation'
 require_relative '../lib/booking_system'
+require_relative '../lib/block'

From 4ac7d30c20fb8ccfbaae21d5002597e9d76eeeae Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Sat, 8 Sep 2018 15:41:13 -0700
Subject: [PATCH 10/16] initiate block class

---
 lib/block.rb                | 19 ++++++++++---------
 lib/booking_system.rb       | 17 +++++++++++++----
 spec/block_spec.rb          | 14 +++++++++++++-
 spec/booking_system_spec.rb |  7 +++++++
 4 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/lib/block.rb b/lib/block.rb
index 35255cabe..db3d65a4c 100644
--- a/lib/block.rb
+++ b/lib/block.rb
@@ -1,9 +1,9 @@
 module Hotel
-  class Block < BookingSystem
-    attr_accessor :block_id, :number_of_rooms, :assigned_rooms
+  class Block
+    attr_accessor :block_id, :number_of_rooms, :assigned_rooms, :start_date, :end_date, :discounted_price
 
-    def initialize(id:, number_of_rooms:, assigned_rooms:, start_date:, end_date:, discounted_price:)
-      @id = id
+    def initialize(block_id:,  number_of_rooms:, assigned_rooms:, start_date:, end_date:, discounted_price:)
+      @block_id = block_id
       @number_of_rooms = number_of_rooms
       @assigned_rooms = assigned_rooms
       @start_date = start_date
@@ -11,10 +11,11 @@ def initialize(id:, number_of_rooms:, assigned_rooms:, start_date:, end_date:, d
       @discounted_price = discounted_price
     end
 
-    def assign_rooms(start_date, end_date)
-      open_rooms 
-
-      # return
-    end
+    # def assign_available_room(start_date, end_date)
+    #   if @number_of_rooms > 5
+    #     raise ArgumentError, "Cannot block more than 5 rooms"
+    #   end
+    #   return available_rooms[0..(@number_of_rooms.to_i - 1)]
+    # end
   end
 end
diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index e482f108d..ac5a2b1bd 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -6,6 +6,7 @@ def initialize
       @rooms = load_rooms
       @reservations = []
       @all_ids = []
+      @blocks = []
     end
 
     def load_rooms
@@ -25,12 +26,20 @@ def make_reservation(start_date, end_date)
       # binding.pry
     end
 
-    def assign_available_room(start_date_2, end_date_2)
+    def make_block(start_date, end_date, number_of_rooms)
+      if number_of_rooms > 5
+        raise ArgumentError, "Cannot reserve more than 5 rooms"
+      end
+      block = Hotel::Block.new(block_id: generate_id, number_of_rooms: number_of_rooms, assigned_rooms: idksofar, tart_date: start_date, end_date: end_date, discounted_price: 150)
+      @blocks << block
+    end
+
+    def assign_available_room(start_date, end_date)
       booked_rooms = []
       available_rooms = []
       @reservations.each do |reservation|
         if
-          reservation.start_date < end_date_2 && start_date_2 < reservation.end_date
+          reservation.start_date < end_date && start_date < reservation.end_date
           booked_rooms << reservation.room
         end
       end
@@ -39,11 +48,11 @@ def assign_available_room(start_date_2, end_date_2)
       return available_rooms[0]
     end
 
-    def search_reservations(start_date_2, end_date_2)
+    def search_reservations(start_date, end_date)
       reservations_within_date = []
       @reservations.each do |reservation|
         if
-          reservation.start_date < end_date_2 && start_date_2 < reservation.end_date
+          reservation.start_date < end_date && start_date < reservation.end_date
           reservations_within_date << reservation
         end
       end
diff --git a/spec/block_spec.rb b/spec/block_spec.rb
index 556cfb53d..e894fd9ae 100644
--- a/spec/block_spec.rb
+++ b/spec/block_spec.rb
@@ -6,11 +6,23 @@
 
   describe "Block instantiation" do
     before do
-      @block = Hotel::Block.new(id: 3, number_of_rooms: 3, assigned_rooms: [3, 4, 5], start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), discounted_price: 150)
+      @block = Hotel::Block.new(block_id: nil,  number_of_rooms: nil, assigned_rooms: nil, start_date: nil, end_date: nil, discounted_price: nil)
     end
 
     it "is an instance of block" do
       expect(@block).must_be_kind_of Hotel::Block
     end
   end
+
+  # describe "assign available rooms" do
+  #   before do
+  #     @block = Hotel::Block.new(id: 3, number_of_rooms: 3, assigned_rooms: @block.assign_available_room((Date.new(2018, 1, 1)), (Date.new(2018, 1, 2))), start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), discounted_price: 150)
+  #   end
+  #
+  #   it "creates an array of available rooms" do
+  #     expect(@block.assigned_rooms).must_be_kind_of Array
+  #   end
+  # end
+  #
+
 end
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index 8ade0c5b9..01adcbe90 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -130,6 +130,13 @@
       expect { @system.check_id(reservation1.id) }.must_raise ArgumentError
     end
   end
+
+  describe "block tests" do
+    it "raises ArgumentError if more than 5 rooms booked" do
+      expect { @system.make_block((Date.new(2018, 1, 1)), (Date.new(2018, 1, 2)), 6) }.must_raise ArgumentError
+    end
+  end
+
 end
 
 # Hi! In Edges we talked about interesting test cases for date overlaps this afternoon. Here is a full list of all the cases I’ll be looking for when I give feedback:

From d5e7a4b74eca545c166f10131a2e509d6b51cdc4 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Sat, 8 Sep 2018 17:30:48 -0700
Subject: [PATCH 11/16] implement block_reservaton class and methods

---
 lib/block.rb                |  5 ++-
 lib/block_reservation.rb    | 14 ++++++++
 lib/booking_system.rb       | 48 +++++++++++++++++--------
 lib/reservation.rb          |  6 ++--
 spec/block_spec.rb          | 14 +-------
 spec/booking_system_spec.rb | 70 +++++++++++++++++++++++++------------
 spec/reservation_spec.rb    |  2 +-
 spec/spec_helper.rb         |  1 +
 8 files changed, 104 insertions(+), 56 deletions(-)
 create mode 100644 lib/block_reservation.rb

diff --git a/lib/block.rb b/lib/block.rb
index db3d65a4c..d1ae5376a 100644
--- a/lib/block.rb
+++ b/lib/block.rb
@@ -1,11 +1,10 @@
 module Hotel
   class Block
-    attr_accessor :block_id, :number_of_rooms, :assigned_rooms, :start_date, :end_date, :discounted_price
+    attr_accessor :block_id, :number_of_rooms, :start_date, :end_date, :discounted_price
 
-    def initialize(block_id:,  number_of_rooms:, assigned_rooms:, start_date:, end_date:, discounted_price:)
+    def initialize(block_id:,  number_of_rooms:, start_date:, end_date:, discounted_price:)
       @block_id = block_id
       @number_of_rooms = number_of_rooms
-      @assigned_rooms = assigned_rooms
       @start_date = start_date
       @end_date = end_date
       @discounted_price = discounted_price
diff --git a/lib/block_reservation.rb b/lib/block_reservation.rb
new file mode 100644
index 000000000..d0f12afe8
--- /dev/null
+++ b/lib/block_reservation.rb
@@ -0,0 +1,14 @@
+module Hotel
+  class BlockReservation
+    attr_accessor :block_id, :reservation_id, :room, :start_date, :end_date, :discounted_price
+
+    def initialize(block_id:,  reservation_id:, room:, start_date:, end_date:, discounted_price:)
+      @block_id = block_id
+      @reservation_id = reservation_id
+      @room = room
+      @start_date = start_date
+      @end_date = end_date
+      @discounted_price = discounted_price
+    end
+  end
+end
diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index ac5a2b1bd..85125d924 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -1,6 +1,6 @@
 module Hotel
   class BookingSystem
-    attr_accessor :rooms, :reservations
+    attr_accessor :rooms, :reservations, :all_ids, :blocks
 
     def initialize
       @rooms = load_rooms
@@ -21,7 +21,7 @@ def load_rooms
     end
 
     def make_reservation(start_date, end_date)
-      reservation = Hotel::Reservation.new(id: generate_id, room: assign_available_room(start_date, end_date), start_date: start_date, end_date: end_date, price_per_night: 200)
+      reservation = Hotel::Reservation.new(reservation_id: generate_id, room: assign_available_room(start_date, end_date), start_date: start_date, end_date: end_date, price_per_night: 200)
       @reservations << reservation
       # binding.pry
     end
@@ -30,8 +30,22 @@ def make_block(start_date, end_date, number_of_rooms)
       if number_of_rooms > 5
         raise ArgumentError, "Cannot reserve more than 5 rooms"
       end
-      block = Hotel::Block.new(block_id: generate_id, number_of_rooms: number_of_rooms, assigned_rooms: idksofar, tart_date: start_date, end_date: end_date, discounted_price: 150)
+
+      id = generate_id
+
+      block = Hotel::Block.new(block_id: id, number_of_rooms: number_of_rooms, start_date: start_date, end_date: end_date, discounted_price: 150)
       @blocks << block
+
+      number_of_rooms.times do
+        block_reservation = Hotel::BlockReservation.new(block_id: id,  reservation_id: nil, room: assign_available_room(start_date, end_date), start_date: start_date, end_date: end_date, discounted_price: 150)
+        @reservations << block_reservation
+      end
+    end
+
+    def make_block_reservation(block_id)
+      block_reservation = find_block_reservation(block_id)
+      block_reservation.reservation_id = generate_id
+      return block_reservation
     end
 
     def assign_available_room(start_date, end_date)
@@ -60,26 +74,32 @@ def search_reservations(start_date, end_date)
       return reservations_within_date
     end
 
-    def find_reservation(id)
-      reservation = @reservations.find { |reservation| reservation.id == id }
+    def find_reservation(reservation_id)
+      reservation = @reservations.find { |reservation| reservation.reservation_id == reservation_id }
       return reservation
     end
 
+    def find_block_reservation(block_id)
+      block_reservation = @reservations.find { |block_reservation| block_reservation.block_id == block_id }
+      return block_reservation
+    end
+
+
     def generate_id
-      id = rand(1..100000)
-      check_id(id)
-      @all_ids << id
-      return id
+      reservation_id = rand(1..100000)
+      check_id(reservation_id)
+      @all_ids << reservation_id
+      return reservation_id
     end
 
-    def check_id(id)
-      if @all_ids.include?(id)
-        raise ArgumentError, "id already exists"
+    def check_id(reservation_id)
+      if @all_ids.include?(reservation_id)
+        raise ArgumentError, "reservation_id already exists"
       end
     end
 
-    def total_cost(id)
-      reservation = find_reservation(id)
+    def total_cost(reservation_id)
+      reservation = find_reservation(reservation_id)
       nights = reservation.end_date - reservation.start_date
       total_cost = nights * reservation.price_per_night
       return total_cost
diff --git a/lib/reservation.rb b/lib/reservation.rb
index 28be098cc..02b6461b3 100644
--- a/lib/reservation.rb
+++ b/lib/reservation.rb
@@ -1,9 +1,9 @@
 module Hotel
   class Reservation
-    attr_accessor :id, :room, :start_date, :end_date, :price_per_night, :total_cost
+    attr_accessor :reservation_id, :room, :start_date, :end_date, :price_per_night, :total_cost
 
-    def initialize(id:, room:, start_date:, end_date:, price_per_night:)
-      @id = id
+    def initialize(reservation_id:, room:, start_date:, end_date:, price_per_night:)
+      @reservation_id = reservation_id
       @room = room
       @start_date = start_date
       @end_date = end_date
diff --git a/spec/block_spec.rb b/spec/block_spec.rb
index e894fd9ae..c04338f11 100644
--- a/spec/block_spec.rb
+++ b/spec/block_spec.rb
@@ -6,23 +6,11 @@
 
   describe "Block instantiation" do
     before do
-      @block = Hotel::Block.new(block_id: nil,  number_of_rooms: nil, assigned_rooms: nil, start_date: nil, end_date: nil, discounted_price: nil)
+      @block = Hotel::Block.new(block_id: nil,  number_of_rooms: nil, start_date: nil, end_date: nil, discounted_price: nil)
     end
 
     it "is an instance of block" do
       expect(@block).must_be_kind_of Hotel::Block
     end
   end
-
-  # describe "assign available rooms" do
-  #   before do
-  #     @block = Hotel::Block.new(id: 3, number_of_rooms: 3, assigned_rooms: @block.assign_available_room((Date.new(2018, 1, 1)), (Date.new(2018, 1, 2))), start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), discounted_price: 150)
-  #   end
-  #
-  #   it "creates an array of available rooms" do
-  #     expect(@block.assigned_rooms).must_be_kind_of Array
-  #   end
-  # end
-  #
-
 end
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index 01adcbe90..6b345e7e0 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -19,7 +19,7 @@
   describe "make reservation" do
     it "makes a reservation" do
       @system.make_reservation(Date.new(2018,1,1), Date.new(2018,1,5))
-      reservation = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      reservation = Hotel::Reservation.new(reservation_id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
       expect(@system.reservations.length).must_equal 1
     end
 
@@ -30,16 +30,16 @@
 
       # @system.make_reservation(Date.new(2018, 1, 1), Date.new(2018, 1, 5))
 
-      reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 7), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      reservation1 = Hotel::Reservation.new(reservation_id: 1, room: 1, start_date: Date.new(2018, 1, 7), end_date: Date.new(2018, 1, 8), price_per_night: 200)
       @system.reservations << reservation1
 
       # @system.make_reservation(Date.new(2018, 1, 6), Date.new(2018, 1, 7))
 
-      reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      reservation2 = Hotel::Reservation.new(reservation_id: 2, room: 2, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
       @system.reservations << reservation2
 
 
-      reservation3 = Hotel::Reservation.new(id: 3, room: @system.assign_available_room(Date.new(2018, 1, 6), Date.new(2018, 1, 9)), start_date: Date.new(2018, 1, 6), end_date: Date.new(2018, 1, 9), price_per_night: 200)
+      reservation3 = Hotel::Reservation.new(reservation_id: 3, room: @system.assign_available_room(Date.new(2018, 1, 6), Date.new(2018, 1, 9)), start_date: Date.new(2018, 1, 6), end_date: Date.new(2018, 1, 9), price_per_night: 200)
       @system.reservations << reservation3
       expect(reservation3.room).must_equal 2
     end
@@ -48,10 +48,10 @@
   describe "search reservation dates" do
     before do
 
-      reservation1 = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+      reservation1 = Hotel::Reservation.new(reservation_id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
       @system.reservations << reservation1
 
-      reservation2 = Hotel::Reservation.new(id: 2, room: 2, start_date: Date.new(2018, 1, 7), end_date: Date.new(2018, 1, 15), price_per_night: 200)
+      reservation2 = Hotel::Reservation.new(reservation_id: 2, room: 2, start_date: Date.new(2018, 1, 7), end_date: Date.new(2018, 1, 15), price_per_night: 200)
       @system.reservations << reservation2
 
     end
@@ -62,13 +62,13 @@
 
     it "returns reservations that overlap on the existing reservation start date" do
 
-      expect(@system.search_reservations(Date.new(2017, 12, 30), Date.new(2018, 1, 5))[0].id).must_equal 1
+      expect(@system.search_reservations(Date.new(2017, 12, 30), Date.new(2018, 1, 5))[0].reservation_id).must_equal 1
 
     end
 
     it "returns reservations that overlap on the existing reservation end" do
 
-      expect(@system.search_reservations(Date.new(2018, 1, 10), Date.new(2018, 1, 20))[0].id).must_equal 2
+      expect(@system.search_reservations(Date.new(2018, 1, 10), Date.new(2018, 1, 20))[0].reservation_id).must_equal 2
 
     end
 
@@ -92,19 +92,19 @@
 
   end
 
-  describe "find reservation method with id" do
-    it "returns the corresponding reservation given id" do
-      reservation = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+  describe "find reservation method with reservation_id" do
+    it "returns the corresponding reservation given reservation_id" do
+      reservation = Hotel::Reservation.new(reservation_id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
       @system.reservations << reservation
 
-      expect(@system.find_reservation(1))[0].id.must_equal 1
+      expect(@system.find_reservation(1))[0].reservation_id.must_equal 1
     end
   end
 
   describe "total cost of reservation" do
-    it "finds the total cost of reservation given id" do
+    it "finds the total cost of reservation given reservation_id" do
 
-      reservation = Hotel::Reservation.new(id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      reservation = Hotel::Reservation.new(reservation_id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
       @system.reservations << reservation
 
       expect(@system.total_cost(1)).must_equal 800
@@ -112,22 +112,22 @@
   end
 
   describe "generate_id" do
-    it "generates an integer id" do
+    it "generates an integer reservation_id" do
       expect(@system.generate_id).must_be_kind_of Integer
     end
 
-    it "assigns id to reservation" do
-      reservation1 = Hotel::Reservation.new(id: @system.generate_id, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+    it "assigns reservation_id to reservation" do
+      reservation1 = Hotel::Reservation.new(reservation_id: @system.generate_id, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
       @system.reservations << reservation1
 
-      expect(reservation1.id).must_be_kind_of Integer
+      expect(reservation1.reservation_id).must_be_kind_of Integer
     end
 
-    it "raises an Argument Error if id is not unique" do
+    it "raises an Argument Error if reservation_id is not unique" do
       # binding.pry
-      reservation1 = Hotel::Reservation.new(id: @system.generate_id, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      reservation1 = Hotel::Reservation.new(reservation_id: @system.generate_id, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
       @system.reservations << reservation1
-      expect { @system.check_id(reservation1.id) }.must_raise ArgumentError
+      expect { @system.check_id(reservation1.reservation_id) }.must_raise ArgumentError
     end
   end
 
@@ -135,10 +135,36 @@
     it "raises ArgumentError if more than 5 rooms booked" do
       expect { @system.make_block((Date.new(2018, 1, 1)), (Date.new(2018, 1, 2)), 6) }.must_raise ArgumentError
     end
-  end
 
+    it "creates a block" do
+      @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 5)
+
+      expect(@system.blocks.length).must_equal 1
+    end
+
+    it "creates x number of reservations for x rooms in the block (x = 5)" do
+      @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 5)
+
+      expect(@system.reservations.length).must_equal 5
+    end
+
+    it "finds a block reservation given the block id" do
+      block_reservation = Hotel::BlockReservation.new(block_id: 20,  reservation_id: nil, room: 2, start_date: Date.new(2018,1,1), end_date: Date.new(2018,1,5), discounted_price: 150)
+      @system.reservations << block_reservation
+
+      expect(@system.find_block_reservation(20)).must_equal block_reservation
+    end
+
+    it "changes reservation_id from nil to integer when making a block_reservation" do
+      block_reservation = Hotel::BlockReservation.new(block_id: 20,  reservation_id: nil, room: 2, start_date: Date.new(2018,1,1), end_date: Date.new(2018,1,5), discounted_price: 150)
+      @system.reservations << block_reservation
+
+      expect((@system.make_block_reservation(20)).reservation_id).must_be_kind_of Integer
+    end
+  end
 end
 
+
 # Hi! In Edges we talked about interesting test cases for date overlaps this afternoon. Here is a full list of all the cases I’ll be looking for when I give feedback:
 #
 # Two date ranges *do* overlap if range A compared to range B:
diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb
index a6ad8478b..207ddb927 100644
--- a/spec/reservation_spec.rb
+++ b/spec/reservation_spec.rb
@@ -6,7 +6,7 @@
 
   describe "Reservation instantiation" do
     before do
-      @reservation = Hotel::Reservation.new(id: 5, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), price_per_night: 200)
+      @reservation = Hotel::Reservation.new(reservation_id: 5, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), price_per_night: 200)
     end
 
     it "is an instance of Reservation" do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 3c4055ce1..27045076e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -8,3 +8,4 @@
 require_relative '../lib/reservation'
 require_relative '../lib/booking_system'
 require_relative '../lib/block'
+require_relative '../lib/block_reservation'

From 1139f5c13f07f6a3f4d95248b6550100104d8674 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Sat, 8 Sep 2018 18:09:14 -0700
Subject: [PATCH 12/16] add search for empty rooms in block and tests

---
 lib/block.rb                |  6 ++--
 lib/block_reservation.rb    |  6 ++--
 lib/booking_system.rb       | 17 ++++++++----
 spec/block_spec.rb          |  2 +-
 spec/booking_system_spec.rb | 55 +++++++++++++++++++++++++------------
 5 files changed, 56 insertions(+), 30 deletions(-)

diff --git a/lib/block.rb b/lib/block.rb
index d1ae5376a..1aa689895 100644
--- a/lib/block.rb
+++ b/lib/block.rb
@@ -1,13 +1,13 @@
 module Hotel
   class Block
-    attr_accessor :block_id, :number_of_rooms, :start_date, :end_date, :discounted_price
+    attr_accessor :block_id, :number_of_rooms, :start_date, :end_date, :price_per_night
 
-    def initialize(block_id:,  number_of_rooms:, start_date:, end_date:, discounted_price:)
+    def initialize(block_id:,  number_of_rooms:, start_date:, end_date:, price_per_night:)
       @block_id = block_id
       @number_of_rooms = number_of_rooms
       @start_date = start_date
       @end_date = end_date
-      @discounted_price = discounted_price
+      @price_per_night = price_per_night
     end
 
     # def assign_available_room(start_date, end_date)
diff --git a/lib/block_reservation.rb b/lib/block_reservation.rb
index d0f12afe8..49c8eff58 100644
--- a/lib/block_reservation.rb
+++ b/lib/block_reservation.rb
@@ -1,14 +1,14 @@
 module Hotel
   class BlockReservation
-    attr_accessor :block_id, :reservation_id, :room, :start_date, :end_date, :discounted_price
+    attr_accessor :block_id, :reservation_id, :room, :start_date, :end_date, :price_per_night
 
-    def initialize(block_id:,  reservation_id:, room:, start_date:, end_date:, discounted_price:)
+    def initialize(block_id:,  reservation_id:, room:, start_date:, end_date:, price_per_night:)
       @block_id = block_id
       @reservation_id = reservation_id
       @room = room
       @start_date = start_date
       @end_date = end_date
-      @discounted_price = discounted_price
+      @price_per_night = price_per_night
     end
   end
 end
diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index 85125d924..dd0401a0e 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -33,17 +33,17 @@ def make_block(start_date, end_date, number_of_rooms)
 
       id = generate_id
 
-      block = Hotel::Block.new(block_id: id, number_of_rooms: number_of_rooms, start_date: start_date, end_date: end_date, discounted_price: 150)
+      block = Hotel::Block.new(block_id: id, number_of_rooms: number_of_rooms, start_date: start_date, end_date: end_date, price_per_night: 150)
       @blocks << block
 
       number_of_rooms.times do
-        block_reservation = Hotel::BlockReservation.new(block_id: id,  reservation_id: nil, room: assign_available_room(start_date, end_date), start_date: start_date, end_date: end_date, discounted_price: 150)
+        block_reservation = Hotel::BlockReservation.new(block_id: id,  reservation_id: nil, room: assign_available_room(start_date, end_date), start_date: start_date, end_date: end_date, price_per_night: 150)
         @reservations << block_reservation
       end
     end
 
     def make_block_reservation(block_id)
-      block_reservation = find_block_reservation(block_id)
+      block_reservation = find_empty_block_reservation(block_id)
       block_reservation.reservation_id = generate_id
       return block_reservation
     end
@@ -79,11 +79,18 @@ def find_reservation(reservation_id)
       return reservation
     end
 
-    def find_block_reservation(block_id)
-      block_reservation = @reservations.find { |block_reservation| block_reservation.block_id == block_id }
+    def find_empty_block_reservation(block_id)
+      block_reservation = @reservations.find { |block_reservation| block_reservation.block_id == block_id && block_reservation.reservation_id == nil}
+      if block_reservation == nil
+        raise ArgumentError, "all rooms in block have been reserved"
+      end
       return block_reservation
     end
 
+    # def find_block(block_id)
+    #   block = @reservations.find_all { |block_reservation| block_reservation.block_id == block_id }
+    #   return block
+    # end
 
     def generate_id
       reservation_id = rand(1..100000)
diff --git a/spec/block_spec.rb b/spec/block_spec.rb
index c04338f11..91bb53299 100644
--- a/spec/block_spec.rb
+++ b/spec/block_spec.rb
@@ -6,7 +6,7 @@
 
   describe "Block instantiation" do
     before do
-      @block = Hotel::Block.new(block_id: nil,  number_of_rooms: nil, start_date: nil, end_date: nil, discounted_price: nil)
+      @block = Hotel::Block.new(block_id: nil,  number_of_rooms: nil, start_date: nil, end_date: nil, price_per_night: nil)
     end
 
     it "is an instance of block" do
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index 6b345e7e0..5de305c80 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -132,35 +132,54 @@
   end
 
   describe "block tests" do
-    it "raises ArgumentError if more than 5 rooms booked" do
-      expect { @system.make_block((Date.new(2018, 1, 1)), (Date.new(2018, 1, 2)), 6) }.must_raise ArgumentError
-    end
+    describe "make_block method" do
+      it "raises ArgumentError if more than 5 rooms booked" do
+        expect { @system.make_block((Date.new(2018, 1, 1)), (Date.new(2018, 1, 2)), 6) }.must_raise ArgumentError
+      end
 
-    it "creates a block" do
-      @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 5)
+      it "creates a block" do
+        @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 5)
 
-      expect(@system.blocks.length).must_equal 1
-    end
+        expect(@system.blocks.length).must_equal 1
+      end
 
-    it "creates x number of reservations for x rooms in the block (x = 5)" do
-      @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 5)
+      it "creates x number of reservations for x rooms in the block (x = 5)" do
+        @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 5)
 
-      expect(@system.reservations.length).must_equal 5
+        expect(@system.reservations.length).must_equal 5
+      end
     end
 
-    it "finds a block reservation given the block id" do
-      block_reservation = Hotel::BlockReservation.new(block_id: 20,  reservation_id: nil, room: 2, start_date: Date.new(2018,1,1), end_date: Date.new(2018,1,5), discounted_price: 150)
-      @system.reservations << block_reservation
+    describe "find_empty_block_reservation" do
+      it "finds an empty block reservation given the block id" do
+        block_reservation = Hotel::BlockReservation.new(block_id: 20,  reservation_id: nil, room: 2, start_date: Date.new(2018,1,1), end_date: Date.new(2018,1,5), price_per_night: 150)
+        @system.reservations << block_reservation
+
+        expect(@system.find_empty_block_reservation(20)).must_equal block_reservation
+      end
+
+      it "will raise argument error if all rooms in block have been reserved" do
+        block_reservation = Hotel::BlockReservation.new(block_id: 20,  reservation_id: 5, room: 2, start_date: Date.new(2018,1,1), end_date: Date.new(2018,1,5), price_per_night: 150)
+        @system.reservations << block_reservation
 
-      expect(@system.find_block_reservation(20)).must_equal block_reservation
+        expect { @system.find_empty_block_reservation(20) }.must_raise ArgumentError
+      end
     end
 
-    it "changes reservation_id from nil to integer when making a block_reservation" do
-      block_reservation = Hotel::BlockReservation.new(block_id: 20,  reservation_id: nil, room: 2, start_date: Date.new(2018,1,1), end_date: Date.new(2018,1,5), discounted_price: 150)
-      @system.reservations << block_reservation
+    describe "make_block_reservation" do
 
-      expect((@system.make_block_reservation(20)).reservation_id).must_be_kind_of Integer
+      it "changes reservation_id from nil to integer when making a block_reservation" do
+        block_reservation = Hotel::BlockReservation.new(block_id: 20,  reservation_id: nil, room: 2, start_date: Date.new(2018,1,1), end_date: Date.new(2018,1,5), price_per_night: 150)
+        @system.reservations << block_reservation
+
+        expect((@system.make_block_reservation(20)).reservation_id).must_be_kind_of Integer
+      end
     end
+
+    # describe "find_block" do
+    #   it "finds all rooms in a block in an array" do
+    #     @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 5)
+
   end
 end
 

From 8555dd5550d6e9f9f5098287f6042631976c9c3c Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Mon, 10 Sep 2018 10:14:09 -0700
Subject: [PATCH 13/16] cleanup

---
 lib/booking_system.rb       |  5 ++++-
 spec/booking_system_spec.rb | 23 ++++++++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index dd0401a0e..c73d5bd0e 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -59,6 +59,9 @@ def assign_available_room(start_date, end_date)
       end
       all_rooms = load_rooms
       available_rooms = all_rooms - booked_rooms
+      if available_rooms[0] == nil
+        raise ArgumentError, "No rooms available"
+      end
       return available_rooms[0]
     end
 
@@ -109,7 +112,7 @@ def total_cost(reservation_id)
       reservation = find_reservation(reservation_id)
       nights = reservation.end_date - reservation.start_date
       total_cost = nights * reservation.price_per_night
-      return total_cost
+      return total_cost.to_f.round(2)
     end
   end
 end
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index 5de305c80..a0fb05376 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -43,6 +43,18 @@
       @system.reservations << reservation3
       expect(reservation3.room).must_equal 2
     end
+
+    it "raises argument error if no rooms are available" do
+
+      20.times do
+        reservation = Hotel::Reservation.new(reservation_id: 1, room: @system.assign_available_room((Date.new(2018, 1, 1)), (Date.new(2018, 1, 8))), start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 8), price_per_night: 200)
+        @system.reservations << reservation
+
+        # @booking_system.make_reservation((Date.new(2018, 1, 6)), (Date.new(2018, 1, 6)))
+      end
+      # binding.pry
+      expect {@system.make_reservation((Date.new(2018, 1, 1)), (Date.new(2018, 1, 8)))}.must_raise ArgumentError
+    end
   end
 
   describe "search reservation dates" do
@@ -176,10 +188,15 @@
       end
     end
 
-    # describe "find_block" do
-    #   it "finds all rooms in a block in an array" do
-    #     @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 5)
+    describe "total cost of reservation" do
+      it "accounts for the discounted price when calculating total cost" do
+
+        @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 1)
+        id = @system.reservations[0].reservation_id
 
+        expect(@system.total_cost(id)).must_equal 600
+      end
+    end
   end
 end
 

From 93d59e47ad9487a6507ac9bbf55a4403a12bbd53 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Mon, 10 Sep 2018 10:18:57 -0700
Subject: [PATCH 14/16] refactors

---
 refactors.txt | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100644 refactors.txt

diff --git a/refactors.txt b/refactors.txt
new file mode 100644
index 000000000..e2a9373ec
--- /dev/null
+++ b/refactors.txt
@@ -0,0 +1,4 @@
+Refactors:
+- consolidate block and block_reservation classes
+- rename block method names to be more descriptive
+- add more tests for edge cases

From 0d191934b5b13697b39c3e68a09c4b05566e95f9 Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Mon, 1 Oct 2018 00:08:43 -0700
Subject: [PATCH 15/16] design-activity

---
 design-activity.md | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 design-activity.md

diff --git a/design-activity.md b/design-activity.md
new file mode 100644
index 000000000..94ccac299
--- /dev/null
+++ b/design-activity.md
@@ -0,0 +1,21 @@
+**What classes does each implementation include? Are the lists the same?**
+Both Implementations include the classes CartEntry, ShoppingCart, and Order.
+**Write down a sentence to describe each class.**
+- In both A and B, CartEntry creates an instance of an item or entry, which has the attributes unit_price and quantity.
+- In A, ShoppingCart contains an array of all entries. In B, it contains an array of all entries and calculates the total price of the cart.
+- In both, Order calculates the total price of the ShoppingCart including tax.
+**How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper.**
+- Each class refers to data stored in other classes- total relies on items in shopping cart, tax, etc.
+**What data does each class store? How (if at all) does this differ between the two implementations?**
+- CartEntry stores unit_price and quantity. ShoppingCart stores entries, and in B, the price of the cart as well. Order stores the cart, the value of the sales tax, and the total price of the order.
+**What methods does each class have? How (if at all) does this differ between the two implementations?**
+- CartEntry initializes the item in both, but in B it also calculates the price of the item. ShoppingCart initializes the entries array, and in B it additionally calculates the price of the entire cart. Order calculates the total price.
+**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?**
+- In A, computing the price is the responsibility of Order- although CartEntry stores the price and quantity as well as calculates the price * quantity, order repeats this method. In B, ShoppingCart is responsible for calculating the price of the cart, which makes more sense because it is an attribute of the cart itself, while the order should be responsible for multiplying that price by the SALES_TAX and returning that.
+**Does total_price directly manipulate the instance variables of other classes?**
+**If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify?**
+- A would be easier to modify because the price is only calculated once, in the Order class. We could add code to the effect of "if quantity is larger than x, price is $y".
+**Which implementation better adheres to the single responsibility principle?**
+- A, because each class serves one purpose, but they still rely on and interact with other classes. Also, there is no repeated code.
+**Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?**

From dfdb23d809abd21c76b843ffb5e0382f6191e8df Mon Sep 17 00:00:00 2001
From: Naheed Arang <arang.na@gmail.com>
Date: Mon, 1 Oct 2018 10:02:42 -0700
Subject: [PATCH 16/16] refactor total_cost method

---
 design-activity.md          |  4 ++++
 lib/booking_system.rb       |  6 ------
 lib/reservation.rb          |  7 +++++++
 spec/booking_system_spec.rb | 17 ++++-------------
 spec/reservation_spec.rb    | 14 ++++++++++++++
 5 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/design-activity.md b/design-activity.md
index 94ccac299..32407eaae 100644
--- a/design-activity.md
+++ b/design-activity.md
@@ -19,3 +19,7 @@ Both Implementations include the classes CartEntry, ShoppingCart, and Order.
 **Which implementation better adheres to the single responsibility principle?**
 - A, because each class serves one purpose, but they still rely on and interact with other classes. Also, there is no repeated code.
 **Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?**
+
+**Refactors**
+
+I had my total cost method in my BookingSystem class, while it should have been in the Reservation class. This can be copied into the Reservation class, but the references to this method will have to be changed to @reservation instead of @system in the tests as well as wherever this is referenced in other methods. 
diff --git a/lib/booking_system.rb b/lib/booking_system.rb
index c73d5bd0e..c6aaf2402 100644
--- a/lib/booking_system.rb
+++ b/lib/booking_system.rb
@@ -108,11 +108,5 @@ def check_id(reservation_id)
       end
     end
 
-    def total_cost(reservation_id)
-      reservation = find_reservation(reservation_id)
-      nights = reservation.end_date - reservation.start_date
-      total_cost = nights * reservation.price_per_night
-      return total_cost.to_f.round(2)
-    end
   end
 end
diff --git a/lib/reservation.rb b/lib/reservation.rb
index 02b6461b3..ed41bf72e 100644
--- a/lib/reservation.rb
+++ b/lib/reservation.rb
@@ -3,11 +3,18 @@ class Reservation
     attr_accessor :reservation_id, :room, :start_date, :end_date, :price_per_night, :total_cost
 
     def initialize(reservation_id:, room:, start_date:, end_date:, price_per_night:)
+      @system = Hotel::BookingSystem.new
       @reservation_id = reservation_id
       @room = room
       @start_date = start_date
       @end_date = end_date
       @price_per_night = price_per_night
     end
+    def total_cost(reservation_id)
+      reservation = @system.find_reservation(reservation_id)
+      nights = reservation.end_date - reservation.start_date
+      total_cost = nights * reservation.price_per_night
+      return total_cost.to_f.round(2)
+    end
   end
 end
diff --git a/spec/booking_system_spec.rb b/spec/booking_system_spec.rb
index a0fb05376..e5f7f13b3 100644
--- a/spec/booking_system_spec.rb
+++ b/spec/booking_system_spec.rb
@@ -6,6 +6,7 @@
 
   before do
     @system = Hotel::BookingSystem.new
+    @reservation = Hotel::Reservation.new(reservation_id: nil, room: nil, start_date: nil, end_date: nil, price_per_night: 200)
   end
 
   describe "load rooms" do
@@ -116,10 +117,10 @@
   describe "total cost of reservation" do
     it "finds the total cost of reservation given reservation_id" do
 
-      reservation = Hotel::Reservation.new(reservation_id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
-      @system.reservations << reservation
+      @reservation = Hotel::Reservation.new(reservation_id: 1, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 5), price_per_night: 200)
+      @system.reservations << @reservation
 
-      expect(@system.total_cost(1)).must_equal 800
+      expect(@reservation.total_cost(1)).must_equal 800
     end
   end
 
@@ -187,16 +188,6 @@
         expect((@system.make_block_reservation(20)).reservation_id).must_be_kind_of Integer
       end
     end
-
-    describe "total cost of reservation" do
-      it "accounts for the discounted price when calculating total cost" do
-
-        @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 1)
-        id = @system.reservations[0].reservation_id
-
-        expect(@system.total_cost(id)).must_equal 600
-      end
-    end
   end
 end
 
diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb
index 207ddb927..eadaa66d1 100644
--- a/spec/reservation_spec.rb
+++ b/spec/reservation_spec.rb
@@ -3,6 +3,10 @@
 require 'pry'
 
 describe "Reservation class" do
+  before do
+    @reservation = Hotel::Reservation.new(reservation_id: 1, room: nil, start_date: Date.today, end_date: Date.today, price_per_night: 200)
+    @system = Hotel::BookingSystem.new
+  end
 
   describe "Reservation instantiation" do
     before do
@@ -13,4 +17,14 @@
       expect(@reservation).must_be_kind_of Hotel::Reservation
     end
   end
+  describe "total cost of reservation" do
+    it "accounts for the discounted price when calculating total cost" do
+      @reservation = Hotel::Reservation.new(reservation_id: 5, room: 1, start_date: Date.new(2018, 1, 1), end_date: Date.new(2018, 1, 2), price_per_night: 200)
+
+      @system.make_block((Date.new(2018,1,1)), (Date.new(2018,1,5)), 1)
+      id = @system.reservations[0].reservation_id
+
+      expect(@reservation.total_cost(id)).must_equal 600
+    end
+  end
 end