From a2c2c4de7b1568d68c3bf16d814357854df1be93 Mon Sep 17 00:00:00 2001 From: Dan Roberts Date: Thu, 25 Jul 2019 15:57:31 -0700 Subject: [PATCH 01/20] Build design scaffolding --- README.md | 1 - lib/date_range.rb | 20 +++++++++ lib/hotel_controller.rb | 24 +++++++++++ lib/reservation.rb | 11 +++++ spec/date_range_spec.rb | 78 +++++++++++++++++++++++++++++++++++ spec/hotel_controller_spec.rb | 42 +++++++++++++++++++ spec/reservation_spec.rb | 12 ++++++ spec/spec_helper.rb | 13 ++++-- 8 files changed, 197 insertions(+), 4 deletions(-) create mode 100644 lib/date_range.rb create mode 100644 lib/hotel_controller.rb create mode 100644 lib/reservation.rb create mode 100644 spec/date_range_spec.rb create mode 100644 spec/hotel_controller_spec.rb create mode 100644 spec/reservation_spec.rb diff --git a/README.md b/README.md index 07dc42bcf..db6077382 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ Reinforce and practice all of the Ruby and programming concepts we've covered in This is a [stage 3](https://github.com/Ada-Developers-Academy/pedagogy/blob/master/rule-of-three.md), individual project. - ## Introduction Your company has been contracted to build a booking system for a small hotel. This system will be used by employees working at the front desk, and will not be available to the general public. diff --git a/lib/date_range.rb b/lib/date_range.rb new file mode 100644 index 000000000..da2197f22 --- /dev/null +++ b/lib/date_range.rb @@ -0,0 +1,20 @@ +module Hotel + class DateRange + attr_accessor :start_date, :end_date + + def initialize(start_date, end_date) + end + + def overlap?(other) + return false + end + + def include?(date) + return false + end + + def nights + return 3 + end + end +end diff --git a/lib/hotel_controller.rb b/lib/hotel_controller.rb new file mode 100644 index 000000000..accca6de4 --- /dev/null +++ b/lib/hotel_controller.rb @@ -0,0 +1,24 @@ +module Hotel + class HotelController + # Wave 1 + def rooms + # You might want to replace this method with an attr_reader + return [] + end + + def reserve_room(start_date, end_date) + # start_date and end_date should be instances of class Date + return Reservation.new(start_date, end_date, nil) + end + + def reservations(date) + return [] + end + + # Wave 2 + def available_rooms(start_date, end_date) + # start_date and end_date should be instances of class Date + return [] + end + end +end diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..7587837e7 --- /dev/null +++ b/lib/reservation.rb @@ -0,0 +1,11 @@ +module Hotel + class Reservation + # Feel free to change this method signature as needed. Make sure to update the tests! + def initialize(start_date, end_date, room) + end + + def cost + return 3 + end + end +end diff --git a/spec/date_range_spec.rb b/spec/date_range_spec.rb new file mode 100644 index 000000000..7c155a0b1 --- /dev/null +++ b/spec/date_range_spec.rb @@ -0,0 +1,78 @@ +require_relative "spec_helper" + +describe Hotel::DateRange do + describe "consructor" do + it "Can be initialized with two dates" do + start_date = Date.new(2017, 01, 01) + end_date = start_date + 3 + + range = Hotel::DateRange.new(start_date, end_date) + + expect(range.start_date).must_equal start_date + expect(range.end_date).must_equal end_date + end + + xit "is an an error for negative-lenght ranges" do + end + + xit "is an error to create a 0-length range" do + end + end + + describe "overlap?" do + before do + start_date = Date.new(2017, 01, 01) + end_date = start_date + 3 + + @range = Hotel::DateRange.new(start_date, end_date) + end + + it "returns true for the same range" do + start_date = @range.start_date + end_date = @range.end_date + test_range = Hotel::DateRange.new(start_date, end_date) + + expect(@range.overlap?(test_range)).must_equal true + end + + xit "returns true for a contained range" do + end + + xit "returns true for a range that overlaps in front" do + end + + xit "returns true for a range that overlaps in the back" do + end + + xit "returns true for a containing range" do + end + + xit "returns false for a range starting on the end_date date" do + end + + xit "returns false for a range ending on the start_date date" do + end + + xit "returns false for a range completely before" do + end + + xit "returns false for a date completely after" do + end + end + + xdescribe "include?" do + it "reutrns false if the date is clearly out" do + end + + it "returns true for dates in the range" do + end + + it "returns false for the end_date date" do + end + end + + xdescribe "nights" do + it "returns the correct number of nights" do + end + end +end diff --git a/spec/hotel_controller_spec.rb b/spec/hotel_controller_spec.rb new file mode 100644 index 000000000..5f6cbe264 --- /dev/null +++ b/spec/hotel_controller_spec.rb @@ -0,0 +1,42 @@ +require_relative "spec_helper" + +describe Hotel::HotelController do + before do + @hotel_controller = Hotel::HotelController.new + @date = Date.parse("2020-08-04") + end + describe "wave 1" do + describe "rooms" do + it "returns a list" do + rooms = @hotel_controller.rooms + expect(rooms).must_be_kind_of Array + end + end + describe "reserve_room" do + it "takes two Date objects and returns a Reservation" do + start_date = @date + end_date = start_date + 3 + + reservation = @hotel_controller.reserve_room(start_date, end_date) + + expect(reservation).must_be_kind_of Hotel::Reservation + end + end + + describe "reservations" do + it "takes a Date and returns a list of Reservations" do + reservation_list = @hotel_controller.reservations(@date) + + expect(reservation_list).must_be_kind_of Array + reservation_list.each do |res| + res.must_be_kind_of Reservation + end + end + end + end + + describe "wave 2" do + describe "available_rooms" do + end + end +end diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb new file mode 100644 index 000000000..a3be669c0 --- /dev/null +++ b/spec/reservation_spec.rb @@ -0,0 +1,12 @@ +require_relative "spec_helper" + +describe Hotel::Reservation do + describe "cost" do + it "returns a number" do + start_date = Date.new(2017, 01, 01) + end_date = start_date + 3 + reservation = Hotel::Reservation.new(start_date, end_date, nil) + expect(reservation.cost).must_be_kind_of Numeric + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d1e3fdc8..f4a246774 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,15 @@ -require 'minitest' -require 'minitest/autorun' -require 'minitest/reporters' # Add simplecov +require "date" + +require "minitest" +require "minitest/autorun" +require "minitest/reporters" +require "minitest/skip_dsl" + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # Require_relative your lib files here! +require_relative "../lib/hotel_controller.rb" +require_relative "../lib/reservation.rb" +require_relative "../lib/date_range.rb" From df7c9b8a5ef7ed5ad1668f131c9a12502b7346e0 Mon Sep 17 00:00:00 2001 From: Dan Roberts Date: Thu, 25 Jul 2019 16:12:22 -0700 Subject: [PATCH 02/20] Update notes about design scaffolding --- design-scaffolding-notes.md | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 design-scaffolding-notes.md diff --git a/design-scaffolding-notes.md b/design-scaffolding-notes.md new file mode 100644 index 000000000..250bacd3b --- /dev/null +++ b/design-scaffolding-notes.md @@ -0,0 +1,38 @@ +# Hotel Design Scaffolding + +## Purpose + +This scaffolding is intended for students who are feeling overwhelmed by the open-ended nature of the Hotel project. Its goal is to answer some of the initial questions about how project files should be laid out, so that students can focus on designing the object interactions and complex Ruby logic that are the core learning goals of the project. The hope is to do so without removing too much of the interesting design work. + +This document and the associated code is intended to be student-facing - if you have a student you think would benefit from this, send them a link! + +### What it includes + +- Three class stubs, `HotelController`, `Reservation` and `DateRange` +- Stubs for public methods of each class from waves 1 and 2, as described in the user stories +- "Interface" tests for each class method that invoke it with the right parameters and verify the return type +- Full test stubs for the `DateRange` class + +### What it does not include + +- Opinions about how classes should interact or data should be stored +- Opinions about whether there should be a `Room` class, or whether it should know about `Reservation`s +- Private helper methods to keep code organized + +Students should feel free to modify any code as they see fit, including changing method signatures, adding new classes and methods, reordering things, not looking at the `DateRange` tests because they want to give it a shot on their own, etc. + +## How to use this code + +Design scaffolding code lives on the `design-scaffolding` branch. + +You can use this code either as inspiration, or as a starting point. If using it as an inspiration, it follows our standard project layout, with product code under `lib/` and tests under `spec/`. + +If you choose to use the code on this branch as a starting point, follow these steps to start your project: + +``` +$ git clone +$ cd hotel +$ git merge design-scaffolding +``` + +You can try to merge in the design scaffolding after you've started, but you'll probably end up with merge conflicts. See an instructor if you're not able to resolve them yourself. \ No newline at end of file From a673135ffa12e9d39db8e0dbd8a3f7c32307ab49 Mon Sep 17 00:00:00 2001 From: Dan Roberts Date: Thu, 25 Jul 2019 16:25:51 -0700 Subject: [PATCH 03/20] Add interface test for HotelController#available_rooms --- spec/hotel_controller_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/hotel_controller_spec.rb b/spec/hotel_controller_spec.rb index 5f6cbe264..daf78c0b3 100644 --- a/spec/hotel_controller_spec.rb +++ b/spec/hotel_controller_spec.rb @@ -37,6 +37,14 @@ describe "wave 2" do describe "available_rooms" do + it "takes two dates and returns a list" do + start_date = @date + end_date = start_date + 3 + + room_list = @hotel_controller.available_rooms(start_date, end_date) + + expect(room_list).must_be_kind_of Array + end end end end From d5489c477d86ced2d300979fe4d76bcf94ca1fb9 Mon Sep 17 00:00:00 2001 From: Dan Roberts Date: Mon, 29 Jul 2019 12:36:36 -0700 Subject: [PATCH 04/20] Correct branch name for merge instructions --- design-scaffolding-notes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/design-scaffolding-notes.md b/design-scaffolding-notes.md index 250bacd3b..141f71585 100644 --- a/design-scaffolding-notes.md +++ b/design-scaffolding-notes.md @@ -32,7 +32,7 @@ If you choose to use the code on this branch as a starting point, follow these s ``` $ git clone $ cd hotel -$ git merge design-scaffolding +$ git merge origin/design-scaffolding ``` -You can try to merge in the design scaffolding after you've started, but you'll probably end up with merge conflicts. See an instructor if you're not able to resolve them yourself. \ No newline at end of file +You can try to merge in the design scaffolding after you've started, but you'll probably end up with merge conflicts. See an instructor if you're not able to resolve them yourself. From b454eb19d613f4a9d2286c05828993014bbac19b Mon Sep 17 00:00:00 2001 From: Kaida Masaki Date: Thu, 5 Sep 2019 10:48:32 -0700 Subject: [PATCH 05/20] spec -> test --- Guardfile | 6 +++--- README.md | 4 ++-- Rakefile | 2 +- design-scaffolding-notes.md | 2 +- spec/date_range_spec.rb => test/date_range_test.rb | 2 +- .../hotel_controller_test.rb | 2 +- spec/reservation_spec.rb => test/reservation_test.rb | 2 +- spec/spec_helper.rb => test/test_helper.rb | 0 8 files changed, 10 insertions(+), 10 deletions(-) rename spec/date_range_spec.rb => test/date_range_test.rb (98%) rename spec/hotel_controller_spec.rb => test/hotel_controller_test.rb (97%) rename spec/reservation_spec.rb => test/reservation_test.rb (90%) rename spec/spec_helper.rb => test/test_helper.rb (100%) diff --git a/Guardfile b/Guardfile index fa59fc3ef..020b42bd9 100644 --- a/Guardfile +++ b/Guardfile @@ -1,6 +1,6 @@ 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' } + watch(%r{^test/(.*)_test\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } + watch(%r{^test/test_helper\.rb$}) { 'test' } end diff --git a/README.md b/README.md index ed9c1abc0..0e6bd85d4 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ This project is both a culmination of our Intro to Ruby unit and our first stage ## Getting Started -We will use the same project structure we used for the previous project. Library code (such as classes) should be in files in the `lib` folder, and tests should be in files in the `spec` folder. +We will use the same project structure we used for the previous project. Library code (such as classes) should be in files in the `lib` folder, and tests should be in files in the `test` folder. 1. Fork this repository in GitHub 1. Clone the repository to your computer @@ -139,7 +139,7 @@ If you are not familiar with what a block of hotel rooms, here is a brief descri ### Testing Requirements -- Utilize the spec helper file +- Utilize the test helper file - Run tests automatically whenever files are added or changed using the `guard` command - The final project submission should have **95% code coverage** using `simplecov` diff --git a/Rakefile b/Rakefile index 372ce806f..0c2d13fe8 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ require 'rake/testtask' Rake::TestTask.new do |t| t.libs = ["lib"] t.warning = true - t.test_files = FileList['spec/*_spec.rb'] + t.test_files = FileList['test/*_test.rb'] end task default: :test diff --git a/design-scaffolding-notes.md b/design-scaffolding-notes.md index 141f71585..143651531 100644 --- a/design-scaffolding-notes.md +++ b/design-scaffolding-notes.md @@ -25,7 +25,7 @@ Students should feel free to modify any code as they see fit, including changing Design scaffolding code lives on the `design-scaffolding` branch. -You can use this code either as inspiration, or as a starting point. If using it as an inspiration, it follows our standard project layout, with product code under `lib/` and tests under `spec/`. +You can use this code either as inspiration, or as a starting point. If using it as an inspiration, it follows our standard project layout, with product code under `lib/` and tests under `test/`. If you choose to use the code on this branch as a starting point, follow these steps to start your project: diff --git a/spec/date_range_spec.rb b/test/date_range_test.rb similarity index 98% rename from spec/date_range_spec.rb rename to test/date_range_test.rb index 7c155a0b1..70bd65115 100644 --- a/spec/date_range_spec.rb +++ b/test/date_range_test.rb @@ -1,4 +1,4 @@ -require_relative "spec_helper" +require_relative "test_helper" describe Hotel::DateRange do describe "consructor" do diff --git a/spec/hotel_controller_spec.rb b/test/hotel_controller_test.rb similarity index 97% rename from spec/hotel_controller_spec.rb rename to test/hotel_controller_test.rb index daf78c0b3..bd50dece0 100644 --- a/spec/hotel_controller_spec.rb +++ b/test/hotel_controller_test.rb @@ -1,4 +1,4 @@ -require_relative "spec_helper" +require_relative "test_helper" describe Hotel::HotelController do before do diff --git a/spec/reservation_spec.rb b/test/reservation_test.rb similarity index 90% rename from spec/reservation_spec.rb rename to test/reservation_test.rb index a3be669c0..ec4204774 100644 --- a/spec/reservation_spec.rb +++ b/test/reservation_test.rb @@ -1,4 +1,4 @@ -require_relative "spec_helper" +require_relative "test_helper" describe Hotel::Reservation do describe "cost" do diff --git a/spec/spec_helper.rb b/test/test_helper.rb similarity index 100% rename from spec/spec_helper.rb rename to test/test_helper.rb From 5717d12568cd5740a4968112cfcd6f2a122ce0a7 Mon Sep 17 00:00:00 2001 From: dee <30602862+tildeee@users.noreply.github.com> Date: Tue, 25 Feb 2020 10:59:56 -0800 Subject: [PATCH 06/20] conforms the text to imply more of an activity --- design-scaffolding-notes.md | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/design-scaffolding-notes.md b/design-scaffolding-notes.md index 143651531..8bdd8abe8 100644 --- a/design-scaffolding-notes.md +++ b/design-scaffolding-notes.md @@ -1,10 +1,18 @@ # Hotel Design Scaffolding -## Purpose +## How to Read This Scaffolding to Create a Second Draft -This scaffolding is intended for students who are feeling overwhelmed by the open-ended nature of the Hotel project. Its goal is to answer some of the initial questions about how project files should be laid out, so that students can focus on designing the object interactions and complex Ruby logic that are the core learning goals of the project. The hope is to do so without removing too much of the interesting design work. +This scaffolding is one solution that answers some of the initial questions about how project files can be laid out. -This document and the associated code is intended to be student-facing - if you have a student you think would benefit from this, send them a link! +Use GitHub.com to explore the files that exist on this repo. + - What classes exist? + - Why? What are they named, what do they represent, and what state and behavior do they have? + - What tests exist? + - What parts of this design inspires you, and you want to steal? + - What parts of this design are you unsure about, and need to consider again later? + - What parts of this design do you think you can do without? + +Spend **no more than 1 hour** answering those questions and adjusting your project's first draft design. After one hour, get started; don't forget that a useful skill for the programmer is the ability to get started, and adjust in small ways often. ### What it includes @@ -27,12 +35,15 @@ Design scaffolding code lives on the `design-scaffolding` branch. You can use this code either as inspiration, or as a starting point. If using it as an inspiration, it follows our standard project layout, with product code under `lib/` and tests under `test/`. -If you choose to use the code on this branch as a starting point, follow these steps to start your project: +If you choose to use the code on this branch as a starting point, you can either: -``` -$ git clone -$ cd hotel -$ git merge origin/design-scaffolding -``` +1. Copy and paste each file from this project into your existing `hotel` folder +2. Or start your project anew with the following steps: -You can try to merge in the design scaffolding after you've started, but you'll probably end up with merge conflicts. See an instructor if you're not able to resolve them yourself. + ``` + $ git clone + $ cd hotel + $ git merge origin/design-scaffolding + ``` + + - Note: You can try to merge in the design scaffolding after you've started, but you'll probably end up with merge conflicts. See an instructor if you're not able to resolve them yourself. From e7381218b450d3d17866d033abfef4ccee3b1ce8 Mon Sep 17 00:00:00 2001 From: dee <30602862+tildeee@users.noreply.github.com> Date: Tue, 25 Feb 2020 11:06:37 -0800 Subject: [PATCH 07/20] direct link to this repo and branch --- design-scaffolding-notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design-scaffolding-notes.md b/design-scaffolding-notes.md index 8bdd8abe8..8efb3d487 100644 --- a/design-scaffolding-notes.md +++ b/design-scaffolding-notes.md @@ -4,7 +4,7 @@ This scaffolding is one solution that answers some of the initial questions about how project files can be laid out. -Use GitHub.com to explore the files that exist on this repo. +Use [this view of our branch on GitHub.com](https://github.com/AdaGold/hotel/tree/design-scaffolding) to explore the files that exist on this repo. - What classes exist? - Why? What are they named, what do they represent, and what state and behavior do they have? - What tests exist? From fa73fb634db95ce7f925c076ecc55cae9146c695 Mon Sep 17 00:00:00 2001 From: Haben Date: Tue, 3 Mar 2020 18:53:57 -0800 Subject: [PATCH 08/20] added tests --- test/date_range_test.rb | 176 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 161 insertions(+), 15 deletions(-) diff --git a/test/date_range_test.rb b/test/date_range_test.rb index 70bd65115..b03fd3709 100644 --- a/test/date_range_test.rb +++ b/test/date_range_test.rb @@ -12,13 +12,27 @@ expect(range.end_date).must_equal end_date end - xit "is an an error for negative-lenght ranges" do + it "is an an error for negative-lenght ranges" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = start_date - 3 + #act #assert + + expect {Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError + end - xit "is an error to create a 0-length range" do + it "is an error to create a 0-length range" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = start_date + #Act #assert + expect {Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError end end +############################################# + describe "overlap?" do before do start_date = Date.new(2017, 01, 01) @@ -30,49 +44,181 @@ it "returns true for the same range" do start_date = @range.start_date end_date = @range.end_date - test_range = Hotel::DateRange.new(start_date, end_date) - expect(@range.overlap?(test_range)).must_equal true + expect(@range.overlap?(start_date, end_date)).must_equal true end - xit "returns true for a contained range" do + it "returns true for a contained range" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 05) + test_start_date = Date.new(2017, 01, 03) + test_end_date = Date.new(2017, 01, 04) + #act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end - xit "returns true for a range that overlaps in front" do + it "returns true for a range that overlaps in front" do + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 05) + test_start_date = Date.new(2017, 01, 01) + test_end_date = Date.new(2017, 01, 8) + #act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal true + end + it "returns true for a range that overlaps when the new_start_date is in the middle" do + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 05) + test_start_date = Date.new(2017, 01, 03) + test_end_date = Date.new(2017, 01, 8) + #act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end - xit "returns true for a range that overlaps in the back" do + it "returns true for a range that overlaps when the new_end_date is before end date" do + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 05) + test_start_date = Date.new(2016, 12, 30) + test_end_date = Date.new(2017, 01, 04) + #act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end - xit "returns true for a containing range" do + it "returns true for a range that overlaps in the back" do + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 05) + test_start_date = Date.new(2017, 01, 03) + test_end_date = Date.new(2017, 01, 05) + #act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end - xit "returns false for a range starting on the end_date date" do + it "returns true for a containing range" do m bnbnnbnbbnb vbv + start_date = Date.new(2017, 01, 03) + end_date = Date.new(2017, 01, 04) + test_start_date = Date.new(2017, 01, 01) + test_end_date = Date.new(2017, 01, 05) + #act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end - xit "returns false for a range ending on the start_date date" do + it "returns true for a range starting on the end_date date" do # check later + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 05) + test_start_date = Date.new(2017, 01, 05) + test_end_date = Date.new(2017, 01, 8) + #act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end - xit "returns false for a range completely before" do + + it "returns false for a range ending on the start_date date" do + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 05) + test_start_date = Date.new(2016, 12, 28) + test_end_date = Date.new(2017, 01, 01) + #act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal false end - xit "returns false for a date completely after" do + it "returns false for a range completely before" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 03) + test_start_date = Date.new(2016, 12, 25) + test_end_date = Date.new(2016, 12, 30) + # act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal false + end + + it "returns false for a date completely after" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 03) + test_start_date = Date.new(2018, 07, 2) + test_end_date = Date.new(2018, 07, 06) + # act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal false end end - xdescribe "include?" do + +################################################### + + describe "include?" do it "reutrns false if the date is clearly out" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 03) + test_date = Date.new(2017, 01, 07) + #act + range = Hotel::DateRange.new(start_date, end_date) + range.overlap?(test_date) + + #assert + expect(doesInclude).must_equal false end it "returns true for dates in the range" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 03) + test_date = Date.new(2017, 01, 02) + #act + range = Hotel::DateRange.new(start_date, end_date) + range.overlap?(test_date) + + #assert + expect(doesInclude).must_equal true end it "returns false for the end_date date" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 03) + test_date = Date.new(2017, 01, 03) + #act + range = Hotel::DateRange.new(start_date, end_date) + doesInclude = range.include?(test_date) + + #assert + expect(doesInclude).must_equal false end end + - xdescribe "nights" do + describe "nights" do it "returns the correct number of nights" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = start_date + 3 + #act + range = Hotel::DateRange.new(start_date, end_date) + nights = range.nights + + #assert + expect(nights).must_equal 3 end end -end + +end \ No newline at end of file From d06db3fccbdc9fb30d905373b2b6bd2199dabd6f Mon Sep 17 00:00:00 2001 From: Haben Date: Tue, 3 Mar 2020 18:54:33 -0800 Subject: [PATCH 09/20] changed method names --- test/hotel_controller_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/hotel_controller_test.rb b/test/hotel_controller_test.rb index 4a6b7af98..845267784 100644 --- a/test/hotel_controller_test.rb +++ b/test/hotel_controller_test.rb @@ -2,7 +2,7 @@ describe Hotel::HotelController do before do - @hotel_controller = Hotel::HotelController.new(20) + @hotel_controller = Hotel::HotelController.new @date = Date.parse("2020-08-04") end describe "wave 1" do @@ -25,7 +25,7 @@ describe "reservations" do it "takes a Date and returns a list of Reservations" do - reservation_list = @hotel_controller.reservations(@date) + reservation_list = @hotel_controller.show_reservations_for_date(@date) expect(reservation_list).must_be_kind_of Array reservation_list.each do |res| @@ -36,12 +36,12 @@ end describe "wave 2" do - describe "available_rooms" do + describe "find_available_rooms" do it "takes two dates and returns a list" do start_date = @date end_date = start_date + 3 - room_list = @hotel_controller.available_rooms(start_date, end_date) + room_list = @hotel_controller.find_available_rooms(start_date, end_date) expect(room_list).must_be_kind_of Array end From 34aefad83c5179eacaf0a0bb2ac1cbd046a35d7a Mon Sep 17 00:00:00 2001 From: Haben Date: Tue, 3 Mar 2020 18:56:53 -0800 Subject: [PATCH 10/20] added methods --- lib/reservation.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 3bcf0ae7f..3bc1b85de 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,11 +1,15 @@ module Hotel class Reservation + attr_reader :date_range # Feel free to change this method signature as needed. Make sure to update the tests! def initialize(start_date, end_date, room_number) + @date_range = DateRange.new(start_date, end_date) + @room_number = room_number end - + + #get the total cost for a given reservation def cost - return 3 + return @date_range.nights * 200 end end end From 0fcbfb763960848258720a9553cce8ba0c32d2b3 Mon Sep 17 00:00:00 2001 From: Haben Date: Tue, 3 Mar 2020 18:57:22 -0800 Subject: [PATCH 11/20] wrote methods --- lib/hotel_controller.rb | 71 ++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/lib/hotel_controller.rb b/lib/hotel_controller.rb index d2d1aa52e..2ae0ca5f4 100644 --- a/lib/hotel_controller.rb +++ b/lib/hotel_controller.rb @@ -1,39 +1,74 @@ module Hotel class HotelController # Wave 1 - attr_reader :reservation, :rooms + attr_reader :reservations, :rooms - - def initialize(number_of_rooms) - @reservation = [] + # I can access the list of all of the rooms in the hotel + def initialize + @reservations = [] @rooms = [] #create a list of rooms - number_of_rooms.times do |room| + room_number = 1 + 20.times do # 20 rooms from requirements #20 times... do... - @rooms << room + @rooms << room_number + room_number = room_number + 1 end - end - - def rooms - # You might want to replace this method with an attr_reader - return [] +# access the list of reservations for a specified room and a given date range + def list_reservations_for_room(room, start_date, end_date) + list = [] + @reservations.each do |reservation| + if room == reservation.room_number + if reservation.date_range.overlap?(start_date, end_date) + list.add(reservation) + end + end + end + return list end def reserve_room(start_date, end_date) # start_date and end_date should be instances of class Date + # looks through room numbers and get reservations for the date in question until we find one with no reservations + available = find_available_rooms(start_date, end_date) + # check for available rooms - return Reservation.new(start_date, end_date, nil) + if available.length > 0 + return Reservation.new(start_date, end_date, available[0]) + else + raise ArgumentError "No rooms available." + end end - - def reservations(date) - return [] + # access the list of reservations for a specific date, + # so that I can track reservations by date + def show_reservations_for_date(date) + # go through reservations and add the ones whose range include the given date + list = [] + @reservations.each do |reservation| + if reservation.date_range.include?(date) + list.add(reservation) + end + end + return list end # Wave 2 - def available_rooms(start_date, end_date) + def find_available_rooms(start_date, end_date) # start_date and end_date should be instances of class Date - return [] + rooms = [] + room_number = 1 + while room_number <= 20 + reservations = list_reservations_for_room(start_date, end_date, room_number) + + if (reservations.length() == 0) # rooms that are empty + rooms << room_number + end + + room_number += 1 + end + + return rooms end end -end +end \ No newline at end of file From 1a101e33541d355b4edaf9620095a483e8b0de39 Mon Sep 17 00:00:00 2001 From: Haben Date: Tue, 3 Mar 2020 18:57:38 -0800 Subject: [PATCH 12/20] wrote methods --- lib/date_range.rb | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index da2197f22..824ca2ec8 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -3,18 +3,34 @@ class DateRange attr_accessor :start_date, :end_date def initialize(start_date, end_date) + # if start date is on or after end Date, raise exception + if start_date >= end_date + raise ArgumentError, " Invalid Date Range." + + end + + @start_date = start_date + @end_date = end_date end - - def overlap?(other) - return false + # check if date selected overlaps with the date_range + def overlap?(new_start_date, new_end_date) + if (start_date <= new_end_date && end_date >= new_start_date) # double check + return true + else + return false + end end - - def include?(date) - return false +# check if new_date is between start_date and end_date + def include?(new_date) + if start_date <= new_date && end_date > new_date # double check + return true + else + return false + end end def nights - return 3 + return end_date - start_date end end end From 1f69b45337d916cb9b05226f4353343593904c95 Mon Sep 17 00:00:00 2001 From: Haben Date: Wed, 4 Mar 2020 15:21:32 -0800 Subject: [PATCH 13/20] wave -2- All the tests in date_range_test are passing --- .gitignore | 1 + test/date_range_test.rb | 36 ++++++++++++++++++------------------ test/test_helper.rb | 5 +++++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 5e1422c9c..c0ac3dc53 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc +coverage diff --git a/test/date_range_test.rb b/test/date_range_test.rb index b03fd3709..096e7a448 100644 --- a/test/date_range_test.rb +++ b/test/date_range_test.rb @@ -62,7 +62,7 @@ it "returns true for a range that overlaps in front" do start_date = Date.new(2017, 01, 01) - end_date = Date.new(2017, 01, 05) + end_date = Date.new(2017, 01, 04) test_start_date = Date.new(2017, 01, 01) test_end_date = Date.new(2017, 01, 8) #act @@ -72,7 +72,7 @@ end it "returns true for a range that overlaps when the new_start_date is in the middle" do start_date = Date.new(2017, 01, 01) - end_date = Date.new(2017, 01, 05) + end_date = Date.new(2017, 01, 04) test_start_date = Date.new(2017, 01, 03) test_end_date = Date.new(2017, 01, 8) #act @@ -83,9 +83,9 @@ it "returns true for a range that overlaps when the new_end_date is before end date" do start_date = Date.new(2017, 01, 01) - end_date = Date.new(2017, 01, 05) + end_date = Date.new(2017, 01, 03) test_start_date = Date.new(2016, 12, 30) - test_end_date = Date.new(2017, 01, 04) + test_end_date = Date.new(2017, 01, 03) #act @range = Hotel::DateRange.new(start_date, end_date) #assert @@ -103,7 +103,7 @@ expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end - it "returns true for a containing range" do m bnbnnbnbbnb vbv + it "returns true for a containing range" do start_date = Date.new(2017, 01, 03) end_date = Date.new(2017, 01, 04) test_start_date = Date.new(2017, 01, 01) @@ -126,7 +126,7 @@ end - it "returns false for a range ending on the start_date date" do + it "returns true for a range ending on the start_date date" do start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 05) test_start_date = Date.new(2016, 12, 28) @@ -134,7 +134,7 @@ #act @range = Hotel::DateRange.new(start_date, end_date) #assert - expect(@range.overlap?(test_start_date, test_end_date)).must_equal false + expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end it "returns false for a range completely before" do @@ -166,43 +166,43 @@ ################################################### describe "include?" do - it "reutrns false if the date is clearly out" do + it "returns false if the date is clearly out" do #arrange start_date = Date.new(2017, 01, 01) - end_date = Date.new(2017, 01, 03) + end_date = Date.new(2017, 01, 04) test_date = Date.new(2017, 01, 07) #act range = Hotel::DateRange.new(start_date, end_date) - range.overlap?(test_date) + does_include = range.include?(test_date) #assert - expect(doesInclude).must_equal false + expect(does_include).must_equal false end it "returns true for dates in the range" do #arrange start_date = Date.new(2017, 01, 01) - end_date = Date.new(2017, 01, 03) + end_date = Date.new(2017, 01, 04) test_date = Date.new(2017, 01, 02) #act range = Hotel::DateRange.new(start_date, end_date) - range.overlap?(test_date) + does_include = range.include?(test_date) #assert - expect(doesInclude).must_equal true + expect(does_include).must_equal true end it "returns false for the end_date date" do #arrange start_date = Date.new(2017, 01, 01) - end_date = Date.new(2017, 01, 03) - test_date = Date.new(2017, 01, 03) + end_date = Date.new(2017, 01, 04) + test_date = Date.new(2017, 01, 04) #act range = Hotel::DateRange.new(start_date, end_date) - doesInclude = range.include?(test_date) + does_include = range.include?(test_date) #assert - expect(doesInclude).must_equal false + expect(does_include).must_equal false end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 80ce5e245..9a5b80d19 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,6 +2,11 @@ require "minitest" require "minitest/autorun" require "minitest/reporters" +require "simplecov" + +SimpleCov.start do + add_filter 'test/' +end Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 0cbd2f99ca2552b6a80beb0b1b7410a997293a61 Mon Sep 17 00:00:00 2001 From: Haben Date: Wed, 4 Mar 2020 15:52:46 -0800 Subject: [PATCH 14/20] edited find_available_rooms --- lib/hotel_controller.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/hotel_controller.rb b/lib/hotel_controller.rb index 2ae0ca5f4..51fdf3406 100644 --- a/lib/hotel_controller.rb +++ b/lib/hotel_controller.rb @@ -37,7 +37,7 @@ def reserve_room(start_date, end_date) if available.length > 0 return Reservation.new(start_date, end_date, available[0]) else - raise ArgumentError "No rooms available." + raise ArgumentError, "No available rooms." end end # access the list of reservations for a specific date, @@ -56,19 +56,16 @@ def show_reservations_for_date(date) # Wave 2 def find_available_rooms(start_date, end_date) # start_date and end_date should be instances of class Date - rooms = [] - room_number = 1 - while room_number <= 20 - reservations = list_reservations_for_room(start_date, end_date, room_number) + available_rooms = [] + # iterate through the rooms to find available room + @rooms.each_with_index do |room, index| + reservations = list_reservations_for_room(start_date, end_date, index + 1) - if (reservations.length() == 0) # rooms that are empty - rooms << room_number + if(reservations.length() == 0) # rooms that are empty + available_rooms << index + 1 end - - room_number += 1 end - - return rooms + return available_rooms end end end \ No newline at end of file From 16bdf27a5f850e6d71b6776c1cfccc829a67a5b7 Mon Sep 17 00:00:00 2001 From: Haben Date: Wed, 4 Mar 2020 15:53:22 -0800 Subject: [PATCH 15/20] modified date_range overlap method --- lib/date_range.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index 824ca2ec8..f9a8e4c9c 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -14,23 +14,15 @@ def initialize(start_date, end_date) end # check if date selected overlaps with the date_range def overlap?(new_start_date, new_end_date) - if (start_date <= new_end_date && end_date >= new_start_date) # double check - return true - else - return false - end + return(start_date <= new_end_date && end_date >= new_start_date) # double check end # check if new_date is between start_date and end_date def include?(new_date) - if start_date <= new_date && end_date > new_date # double check - return true - else - return false - end + return start_date <= new_date && end_date > new_date # double check end def nights - return end_date - start_date + return end_date - start_date end end end From 75b78940671b5b66a0f160e06bc639409492fc5c Mon Sep 17 00:00:00 2001 From: Haben Date: Wed, 4 Mar 2020 17:45:16 -0800 Subject: [PATCH 16/20] added tests to reservation_test --- test/reservation_test.rb | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/test/reservation_test.rb b/test/reservation_test.rb index ec4204774..00a0b0491 100644 --- a/test/reservation_test.rb +++ b/test/reservation_test.rb @@ -1,12 +1,42 @@ require_relative "test_helper" -describe Hotel::Reservation do +describe "Hotel::Reservation" do + describe "reservation" do + it "can be initialized with two dates and room number" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = start_date + 3 + room_number = 1 + #act + reservation = Hotel::Reservation.new(start_date, end_date, room_number) + # assert + expect(reservation.start_date).must_equal start_date + expect(reservation.end_date).must_equal end_date + expect(reservation.room_number).must_equal room_number + end + end +end + +########################## describe "cost" do it "returns a number" do + # arrange start_date = Date.new(2017, 01, 01) end_date = start_date + 3 - reservation = Hotel::Reservation.new(start_date, end_date, nil) + # act + reservation = Hotel::Reservation.new(start_date, end_date, 5) + #arrange expect(reservation.cost).must_be_kind_of Numeric end + + it "returns the correct amount for nights spent" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = start_date + 3 + #act + reservation = Hotel::Reservation.new(start_date, end_date, 4) + #assert + expect(reservation.cost).must_equal 600 + end end -end + From d004a72330bdfd3ac293547bf781afa7e10089fa Mon Sep 17 00:00:00 2001 From: Haben Date: Wed, 4 Mar 2020 17:45:55 -0800 Subject: [PATCH 17/20] added attr_readers to reservation --- lib/reservation.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/reservation.rb b/lib/reservation.rb index 3bc1b85de..249741caf 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,13 +1,16 @@ module Hotel class Reservation - attr_reader :date_range - # Feel free to change this method signature as needed. Make sure to update the tests! + attr_reader :date_range, :start_date, :end_date, :room_number + + # initizlize def initialize(start_date, end_date, room_number) @date_range = DateRange.new(start_date, end_date) @room_number = room_number + @start_date = start_date + @end_date = end_date end - #get the total cost for a given reservation + # get the total cost for a given reservation def cost return @date_range.nights * 200 end From e9ca15a98b7e4986542938d95b83b52a75a19982 Mon Sep 17 00:00:00 2001 From: Haben Date: Wed, 4 Mar 2020 17:46:18 -0800 Subject: [PATCH 18/20] arranged simplcov in the right order --- test/test_helper.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 9a5b80d19..52f8012b5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,12 +1,13 @@ # Add simplecov -require "minitest" -require "minitest/autorun" -require "minitest/reporters" require "simplecov" SimpleCov.start do add_filter 'test/' end +require "minitest" +require "minitest/autorun" +require "minitest/reporters" + Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From eaf32b837d4976fed954f960f8948e51c707c2d9 Mon Sep 17 00:00:00 2001 From: Haben Date: Fri, 6 Mar 2020 14:14:28 -0800 Subject: [PATCH 19/20] added more tests --- lib/date_range.rb | 6 +-- lib/hotel_controller.rb | 18 +++++---- lib/reservation.rb | 1 + test/date_range_test.rb | 29 +++++++++++++- test/hotel_controller_test.rb | 73 +++++++++++++++++++++++++++++++++-- test/reservation_test.rb | 16 +++++++- 6 files changed, 126 insertions(+), 17 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index f9a8e4c9c..c43a70ac7 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -14,11 +14,11 @@ def initialize(start_date, end_date) end # check if date selected overlaps with the date_range def overlap?(new_start_date, new_end_date) - return(start_date <= new_end_date && end_date >= new_start_date) # double check + return(start_date <= new_end_date && end_date >= new_start_date) end -# check if new_date is between start_date and end_date + # check if new_date is between start_date and end_date def include?(new_date) - return start_date <= new_date && end_date > new_date # double check + return start_date <= new_date && end_date > new_date end def nights diff --git a/lib/hotel_controller.rb b/lib/hotel_controller.rb index 51fdf3406..6d4fad909 100644 --- a/lib/hotel_controller.rb +++ b/lib/hotel_controller.rb @@ -17,11 +17,11 @@ def initialize end # access the list of reservations for a specified room and a given date range def list_reservations_for_room(room, start_date, end_date) - list = [] + list = [] # returns an array of reservations that falls within the date range @reservations.each do |reservation| if room == reservation.room_number if reservation.date_range.overlap?(start_date, end_date) - list.add(reservation) + list << reservation end end end @@ -35,7 +35,9 @@ def reserve_room(start_date, end_date) # check for available rooms if available.length > 0 - return Reservation.new(start_date, end_date, available[0]) + newly_created_reservation = Reservation.new(start_date, end_date, available[0]) + reservations << newly_created_reservation + return newly_created_reservation else raise ArgumentError, "No available rooms." end @@ -47,7 +49,7 @@ def show_reservations_for_date(date) list = [] @reservations.each do |reservation| if reservation.date_range.include?(date) - list.add(reservation) + list << reservation end end return list @@ -58,11 +60,11 @@ def find_available_rooms(start_date, end_date) # start_date and end_date should be instances of class Date available_rooms = [] # iterate through the rooms to find available room - @rooms.each_with_index do |room, index| - reservations = list_reservations_for_room(start_date, end_date, index + 1) - + @rooms.each do |room| + reservations = list_reservations_for_room(room, start_date, end_date) + if(reservations.length() == 0) # rooms that are empty - available_rooms << index + 1 + available_rooms << room end end return available_rooms diff --git a/lib/reservation.rb b/lib/reservation.rb index 249741caf..7e86acca7 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -8,6 +8,7 @@ def initialize(start_date, end_date, room_number) @room_number = room_number @start_date = start_date @end_date = end_date + end # get the total cost for a given reservation diff --git a/test/date_range_test.rb b/test/date_range_test.rb index 096e7a448..c71d0c221 100644 --- a/test/date_range_test.rb +++ b/test/date_range_test.rb @@ -12,7 +12,7 @@ expect(range.end_date).must_equal end_date end - it "is an an error for negative-lenght ranges" do + it "is an an error for negative-length ranges" do #arrange start_date = Date.new(2017, 01, 01) end_date = start_date - 3 @@ -29,6 +29,20 @@ #Act #assert expect {Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError end + it "is an invalid date range if start date is greater than end date" do + #arrange + start_date = Date.new(2017, 01, 04) + end_date = Date.new(2017, 01, 01) + #Act #assert + expect {Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError + end + it "is invalid if start date is same as end date" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 01) + #Act #assert + expect {Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError + end end ############################################# @@ -47,6 +61,19 @@ expect(@range.overlap?(start_date, end_date)).must_equal true end + + it "return true if date selected overlaps with the date_range" do + #arrange + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 01, 05) + test_start_date = Date.new(2017, 01, 01) + test_end_date = Date.new(2017, 01, 05) + #act + @range = Hotel::DateRange.new(start_date, end_date) + #assert + expect(@range.overlap?(test_start_date, test_end_date)).must_equal true + end + it "returns true for a contained range" do #arrange diff --git a/test/hotel_controller_test.rb b/test/hotel_controller_test.rb index 845267784..58653a2eb 100644 --- a/test/hotel_controller_test.rb +++ b/test/hotel_controller_test.rb @@ -5,25 +5,74 @@ @hotel_controller = Hotel::HotelController.new @date = Date.parse("2020-08-04") end - describe "wave 1" do + describe "hotelcontroller" do describe "rooms" do it "returns a list" do rooms = @hotel_controller.rooms expect(rooms).must_be_kind_of Array end end + end + describe "list_reservations_for_room" do + it "returns a list of reservations that fall with in the given date range for a specific room." do + + # Arrange : add a new Reservation for room #2 from March 1, March 5 + start_date = Date.new(2017, 03, 01) + end_date = Date.new(2017, 03, 05) + room = 2 + + @hotel_controller.reservations << Hotel::Reservation.new(start_date, end_date, room) + + # Arrange : add a new Reservation for room #2 from March 10, March 15 + start_date = Date.new(2017, 03, 10) + end_date = Date.new(2017, 03, 15) + room = 2 + + @hotel_controller.reservations << Hotel::Reservation.new(start_date, end_date, room) + + # Arrange : add a new Reservation for room #2 from March 20, March 23 + start_date = Date.new(2017, 03, 20) + end_date = Date.new(2017, 03, 23) + room = 2 + + @hotel_controller.reservations << Hotel::Reservation.new(start_date, end_date, room) + + # act + all_found_reservations = @hotel_controller.list_reservations_for_room(2, Date.new(2017, 03, 01), Date.new(2017, 03, 31)) + + #assert + expect(all_found_reservations.length).must_equal 3 + end + end + describe "reserve_room" do it "takes two Date objects and returns a Reservation" do + # arrange start_date = @date end_date = start_date + 3 - + # act reservation = @hotel_controller.reserve_room(start_date, end_date) - + # assert expect(reservation).must_be_kind_of Hotel::Reservation end + + it "return false if there are no availalbe rooms" do + # arrange + start_date = Date.new(2017, 01, 01) + end_date = Date.new(2017, 02, 01) + + 20.times do # create a list of 20 resereved rooms + @hotel_controller.reserve_room(start_date, end_date) # act + end + + # assert + expect{(@hotel_controller.reserve_room(start_date, end_date))}.must_raise ArgumentError + end end + describe "reservations" do + it "takes a Date and returns a list of Reservations" do reservation_list = @hotel_controller.show_reservations_for_date(@date) @@ -32,8 +81,24 @@ res.must_be_kind_of Reservation end end + end - end + + describe "show_reservations_for_date" do + it "show reservations whose range include the given date" do + #arrange + @hotel_controller.reserve_room(Date.new(2017, 02, 20), Date.new(2017, 03, 03)) + @hotel_controller.reserve_room(Date.new(2017, 03, 01), Date.new(2017, 03, 05)) + + #act + reserved = @hotel_controller.show_reservations_for_date(Date.new(2017, 03, 01)) + + #assert + expect(reserved.length).must_equal 2 + end + + end + describe "wave 2" do describe "find_available_rooms" do diff --git a/test/reservation_test.rb b/test/reservation_test.rb index 00a0b0491..7635a4f3a 100644 --- a/test/reservation_test.rb +++ b/test/reservation_test.rb @@ -8,11 +8,14 @@ end_date = start_date + 3 room_number = 1 #act - reservation = Hotel::Reservation.new(start_date, end_date, room_number) + reservation = Hotel::Reservation.new(start_date, end_date, room_number) + date_range = Hotel::DateRange.new(start_date, end_date) + # assert expect(reservation.start_date).must_equal start_date expect(reservation.end_date).must_equal end_date expect(reservation.room_number).must_equal room_number + end end end @@ -38,5 +41,16 @@ #assert expect(reservation.cost).must_equal 600 end + + + it "returns total cost for a given date range" do + #arrange + + new_reservation = Hotel::Reservation.new(Date.new(2017,01,01),Date.new(2017,01,03),2) + #act + total_cost = new_reservation.cost + #assert + expect(total_cost).must_equal 400 + end end From c54f6291350ae3902fbaeba14bcc014d89cf5eb9 Mon Sep 17 00:00:00 2001 From: Haben Date: Fri, 6 Mar 2020 14:24:28 -0800 Subject: [PATCH 20/20] completed wave 2 --- lib/date_range.rb | 2 +- lib/hotel_controller.rb | 2 +- test/date_range_test.rb | 73 ++++++++++++++++++----------------- test/hotel_controller_test.rb | 12 +++--- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/lib/date_range.rb b/lib/date_range.rb index c43a70ac7..d48a0e4eb 100644 --- a/lib/date_range.rb +++ b/lib/date_range.rb @@ -3,7 +3,7 @@ class DateRange attr_accessor :start_date, :end_date def initialize(start_date, end_date) - # if start date is on or after end Date, raise exception + # if start date is on or after end Date, raise an exception if start_date >= end_date raise ArgumentError, " Invalid Date Range." diff --git a/lib/hotel_controller.rb b/lib/hotel_controller.rb index 6d4fad909..bea58a578 100644 --- a/lib/hotel_controller.rb +++ b/lib/hotel_controller.rb @@ -43,7 +43,7 @@ def reserve_room(start_date, end_date) end end # access the list of reservations for a specific date, - # so that I can track reservations by date + # so that it can track reservations by date def show_reservations_for_date(date) # go through reservations and add the ones whose range include the given date list = [] diff --git a/test/date_range_test.rb b/test/date_range_test.rb index c71d0c221..760486f03 100644 --- a/test/date_range_test.rb +++ b/test/date_range_test.rb @@ -17,7 +17,6 @@ start_date = Date.new(2017, 01, 01) end_date = start_date - 3 #act #assert - expect {Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError end @@ -29,6 +28,7 @@ #Act #assert expect {Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError end + it "is an invalid date range if start date is greater than end date" do #arrange start_date = Date.new(2017, 01, 04) @@ -36,6 +36,7 @@ #Act #assert expect {Hotel::DateRange.new(start_date, end_date)}.must_raise ArgumentError end + it "is invalid if start date is same as end date" do #arrange start_date = Date.new(2017, 01, 01) @@ -76,35 +77,37 @@ it "returns true for a contained range" do - #arrange + # arrange start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 05) test_start_date = Date.new(2017, 01, 03) test_end_date = Date.new(2017, 01, 04) - #act + # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end it "returns true for a range that overlaps in front" do + # arrange start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 04) test_start_date = Date.new(2017, 01, 01) test_end_date = Date.new(2017, 01, 8) - #act + # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end it "returns true for a range that overlaps when the new_start_date is in the middle" do + # arrange start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 04) test_start_date = Date.new(2017, 01, 03) test_end_date = Date.new(2017, 01, 8) - #act + # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end @@ -113,9 +116,9 @@ end_date = Date.new(2017, 01, 03) test_start_date = Date.new(2016, 12, 30) test_end_date = Date.new(2017, 01, 03) - #act + # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end @@ -124,9 +127,9 @@ end_date = Date.new(2017, 01, 05) test_start_date = Date.new(2017, 01, 03) test_end_date = Date.new(2017, 01, 05) - #act + # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end @@ -135,20 +138,20 @@ end_date = Date.new(2017, 01, 04) test_start_date = Date.new(2017, 01, 01) test_end_date = Date.new(2017, 01, 05) - #act + # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end - it "returns true for a range starting on the end_date date" do # check later + it "returns true for a range starting on the end_date date" do start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 05) test_start_date = Date.new(2017, 01, 05) test_end_date = Date.new(2017, 01, 8) - #act + # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end @@ -158,33 +161,33 @@ end_date = Date.new(2017, 01, 05) test_start_date = Date.new(2016, 12, 28) test_end_date = Date.new(2017, 01, 01) - #act + # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal true end it "returns false for a range completely before" do - #arrange + # arrange start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 03) test_start_date = Date.new(2016, 12, 25) test_end_date = Date.new(2016, 12, 30) # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal false end it "returns false for a date completely after" do - #arrange + # arrange start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 03) test_start_date = Date.new(2018, 07, 2) test_end_date = Date.new(2018, 07, 06) # act @range = Hotel::DateRange.new(start_date, end_date) - #assert + # assert expect(@range.overlap?(test_start_date, test_end_date)).must_equal false end end @@ -194,41 +197,41 @@ describe "include?" do it "returns false if the date is clearly out" do - #arrange + # arrange start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 04) test_date = Date.new(2017, 01, 07) - #act + # act range = Hotel::DateRange.new(start_date, end_date) does_include = range.include?(test_date) - #assert + # assert expect(does_include).must_equal false end it "returns true for dates in the range" do - #arrange + # arrange start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 04) test_date = Date.new(2017, 01, 02) - #act + # act range = Hotel::DateRange.new(start_date, end_date) does_include = range.include?(test_date) - #assert + # assert expect(does_include).must_equal true end it "returns false for the end_date date" do - #arrange + # arrange start_date = Date.new(2017, 01, 01) end_date = Date.new(2017, 01, 04) test_date = Date.new(2017, 01, 04) - #act + # act range = Hotel::DateRange.new(start_date, end_date) does_include = range.include?(test_date) - #assert + # assert expect(does_include).must_equal false end end @@ -236,14 +239,14 @@ describe "nights" do it "returns the correct number of nights" do - #arrange + # arrange start_date = Date.new(2017, 01, 01) end_date = start_date + 3 - #act + # act range = Hotel::DateRange.new(start_date, end_date) nights = range.nights - #assert + # assert expect(nights).must_equal 3 end end diff --git a/test/hotel_controller_test.rb b/test/hotel_controller_test.rb index 58653a2eb..2ab57d5de 100644 --- a/test/hotel_controller_test.rb +++ b/test/hotel_controller_test.rb @@ -16,31 +16,29 @@ describe "list_reservations_for_room" do it "returns a list of reservations that fall with in the given date range for a specific room." do - # Arrange : add a new Reservation for room #2 from March 1, March 5 + # arrange : add a new Reservation for room #2 from March 1, March 5 start_date = Date.new(2017, 03, 01) end_date = Date.new(2017, 03, 05) room = 2 @hotel_controller.reservations << Hotel::Reservation.new(start_date, end_date, room) - # Arrange : add a new Reservation for room #2 from March 10, March 15 + # arrange : add a new Reservation for room #2 from March 10, March 15 start_date = Date.new(2017, 03, 10) end_date = Date.new(2017, 03, 15) room = 2 @hotel_controller.reservations << Hotel::Reservation.new(start_date, end_date, room) - # Arrange : add a new Reservation for room #2 from March 20, March 23 + # arrange : add a new Reservation for room #2 from March 20, March 23 start_date = Date.new(2017, 03, 20) end_date = Date.new(2017, 03, 23) room = 2 @hotel_controller.reservations << Hotel::Reservation.new(start_date, end_date, room) - - # act + # act all_found_reservations = @hotel_controller.list_reservations_for_room(2, Date.new(2017, 03, 01), Date.new(2017, 03, 31)) - - #assert + # assert expect(all_found_reservations.length).must_equal 3 end end