forked from AdaGold/hotel
-
Notifications
You must be signed in to change notification settings - Fork 46
maryams_hotel #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marshi23
wants to merge
10
commits into
Ada-C10:master
Choose a base branch
from
marshi23:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
maryams_hotel #45
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a767ab2
intial file set up spec files running
marshi23 69157c8
class straucture design
marshi23 d59cc4e
creating a method to return a list of rooms by date
marshi23 c8e5bbf
methods updates
marshi23 a47396c
adjusting to refactor Hotel#Reservation tests, Reservation and Room t…
marshi23 080b736
creating tests Hotel#makereservation small progress
marshi23 787be5b
made some fixes
marshi23 c5f92fe
create working tests fix how room gets reservation and available? met…
marshi23 1dcd858
design-activity created and amswered
marshi23 bf64a4d
design writing
marshi23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| What classes does each implementation include? Are the lists the same? | ||
| Write down a sentence to describe each class. | ||
|
|
||
| Implementation A | ||
| CartEntry class: initializes unit price and quantity variables | ||
| ShoppingCart class: initializes an array of entries | ||
| Order class: initializes a new shopping cart, calculates total price using cart entries and uses the unit price and quantity of each cart entry. | ||
|
|
||
|
|
||
| Implementation B | ||
| CartEntry class: initializes unit price and quantity variables, calculates the price of each cart entry | ||
| ShoppingCart class: initializes an array of entries, calculates price (cart total) using the sum of prices for all cart entries | ||
| Order class: initializes a new shopping cart, calculates total price, by adding sales tax and shopping cart price. | ||
|
|
||
| The two implementations have the same list of classes. But the classes do different things, in implementation B. Calculations for prices and done within individual classes unlike A which does all the calculations in the Order class. | ||
|
|
||
| How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. | ||
|
|
||
| ShoppingCart is populated with an array of CartEntry instances, it also calls the CartEntry method price and used in defining ShoppingCart#price. | ||
|
|
||
| Order is populated with an instance of ShoppingCart. It has a method total price that calls the ShoppingCart#price method. | ||
|
|
||
|
|
||
| What data does each class store? How (if at all) does this differ between the two implementations? | ||
|
|
||
|
|
||
| CartEntry contains two integers variables (I'm assuming unit price and quantity will be integers). The class does not store data, it creates a CartEntry. | ||
|
|
||
| ShoppingCart has an array stored in the @entires variable that stores instances of CartEntry. | ||
|
|
||
| Order contains the @cart variable which is an instance of ShoppingCart. The class does not store any data | ||
|
|
||
| What methods does each class have? How (if at all) does this differ between the two implementations? | ||
|
|
||
| Implementation A | ||
| CartEntry has no methods | ||
| ShoppingCart has no methods | ||
| Order has total_price method | ||
|
|
||
| Implementation B | ||
| CartEntry has a price method | ||
| ShoppingCart has a price method | ||
| Order has a total_price method | ||
|
|
||
|
|
||
| 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? | ||
|
|
||
| Implementation A | ||
| The price logic is retained in Order | ||
|
|
||
| Implementation B | ||
| The price logic is delegated to lower level classes | ||
|
|
||
| Does total_price directly manipulate the instance variables of other classes? | ||
|
|
||
| total_price does not 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? | ||
|
|
||
| Implementation B will be easier to modify because it is loosely couple. | ||
|
|
||
| Which implementation better adheres to the single responsibility principle? | ||
|
|
||
| Implementation B | ||
|
|
||
|
|
||
| Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? | ||
|
|
||
| Implementation B is more loosely coupled because classes are responsible for their prices unlike in Implementation A. | ||
|
|
||
| I think it would lessen dependencies if each room does not know about all the reservations it has. I made it like this as a way to check if a room is available for a given date range. If I can think of a better design for how rooms are available, rooms won't need to know reservations. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| class BlockReservation | ||
| def initialize(number of rooms, start_time, end_time, rate) | ||
| number of rooms = integer | ||
| rate = integer | ||
| start_time - Time object | ||
| end_time - Time object | ||
|
|
||
| id = integer - how will this be generated | ||
| block_reservations = [{}] | ||
| rooms - [array of room intance to accomate blocks] | ||
| cost - integer | ||
| #client -hash of client details | ||
| end | ||
|
|
||
|
|
||
| # def make_block_reservation(start_time, end_time) | ||
| # find room with stauts == avaible | ||
| # reservarions_list << BlockReservation.new(reservation_data) | ||
| # end | ||
|
|
||
| def self.all | ||
|
|
||
| block_reservations << all | ||
| returns list of all block reservations | ||
| end | ||
|
|
||
| def list_block_reservations_by_date(date) | ||
| check block_reservations for reservation with start_time == date | ||
| end | ||
|
|
||
|
|
||
| def reservation_cost | ||
| cost == difference in days between end_time start_time * rate | ||
| end | ||
|
|
||
|
|
||
| end | ||
|
|
||
| block_reservation_data = { | ||
| number_of_rooms: 1, | ||
| rate: 150.00, | ||
| start_time: 03-23-2019, | ||
| end_time: 03-26-2019, | ||
| rooms: room, | ||
| cost: 0 | ||
| } | ||
|
|
||
| BlockRevservation.new(block_reservation_data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| class Reservation | ||
| attr_reader :check_in, :check_out, :cost, :date_range, :room | ||
| def initialize(check_in, check_out, room) | ||
| @check_in = check_in | ||
| @check_out = check_out | ||
| @date_range = check_out..check_in | ||
| @cost = reservation_cost | ||
| @room = room | ||
|
|
||
| raise ArgumentError if check_in >= check_out | ||
|
|
||
| # @block_reservation = block_reservation | ||
| # @id = id | ||
| # @client = client | ||
| end | ||
|
|
||
| def nights | ||
| nights = check_out - check_in | ||
| return nights | ||
| end | ||
|
|
||
| def reservation_cost | ||
| cost = nights * 200 | ||
| return cost | ||
| end | ||
|
|
||
| def during?(check_out, check_in) | ||
| @date_range.include?(check_out) | ||
| end | ||
|
|
||
| # def make_block_reservation(number of rooms, start_time, end_time, rate) | ||
| # raise error of number of rooms > 5 | ||
| # assign 1 - 5 availble rooms to reservation | ||
| # cost = calculates using discouted cost | ||
| # end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| require 'date' | ||
| class ReservationManager | ||
| attr_reader :reservations, :rooms | ||
| # attr_accessor | ||
| def initialize(reservations = [], rooms = []) | ||
| @reservations = reservations | ||
| @rooms = generate_rooms | ||
| # @block_reservations = block_reservations | ||
| end | ||
|
|
||
| def generate_rooms | ||
| rooms = 20.times.map do |number| | ||
| Room.new(number) | ||
| end | ||
| return rooms | ||
| end | ||
|
|
||
| def make_reservation(check_in = Date.new(check_in), check_out = Date.new(check_out)) | ||
| room = rooms_available(check_in, check_out).first | ||
| reservation = Reservation.new(check_in, check_out, room) | ||
| @reservations << reservation | ||
| room.reserve(reservation) | ||
| return reservation | ||
| end | ||
|
|
||
| def rooms_available(check_in, check_out) | ||
| free_rooms = @rooms.select do |room| | ||
| room.available?(check_in, check_out) | ||
| end | ||
| return free_rooms | ||
| end | ||
|
|
||
| # rethinking design | ||
| # def rooms_available(check_in, check_out) | ||
| # free_rooms = @rooms.select do |room| | ||
| # room.room_availble?(check_in, check_out) | ||
| # end | ||
| # return free_rooms | ||
| # end | ||
|
|
||
| def find_reservation(check_out, check_in) | ||
| @reservations.each do |reservation| | ||
| return reservation if reservation.during?(check_out, check_in) | ||
| return "Reservation not found" | ||
| end | ||
| end | ||
|
|
||
| # def list_reservations(check_out, check_in) | ||
| # end | ||
|
|
||
| # def reserve_block | ||
| # end | ||
|
|
||
| # def cancel_reservations | ||
| # end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| class Room | ||
| # This class seems to mostly serve as a a container for reservations, which might be better served as a feature of your Hotel class. | ||
| attr_reader :room_number, :dates | ||
| attr_accessor :status, :reservations | ||
| def initialize(room_number, status = :available, reservations = []) | ||
| @room_number = room_number | ||
| @status = status # valid_status = [:available, :reserved, :blocked] | ||
| @reservations = reservations | ||
| # rethinking design | ||
| @dates_range = check_in..check_out | ||
|
|
||
| raise ArgumentError if room_number > 20 | ||
| end | ||
|
|
||
| def reserve(reservation) | ||
| @reservations << reservation | ||
| end | ||
|
|
||
| def available?(check_in, check_out) | ||
| @reservations.each do |reservation| | ||
| reservation.during?(check_in, check_out) | ||
| end | ||
| end | ||
|
|
||
| def room_availble?(check_in, check_out) | ||
| @date_range.include?(check_out) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| require_relative 'spec_helper' | ||
| require 'minitest' | ||
| require 'minitest/autorun' | ||
| require 'minitest/reporters' | ||
| require 'pry' | ||
| require 'date' | ||
|
|
||
| Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new | ||
|
|
||
| require_relative '../lib/reservation_manager.rb' | ||
| require_relative '../lib/room.rb' | ||
| require_relative '../lib/reservation.rb' | ||
|
|
||
| describe "ReservationManagers Class" do | ||
|
|
||
| describe "Initializer" do | ||
| before do | ||
| @reservation_manager = ReservationManager.new | ||
| end | ||
|
|
||
| it "returns an instance of ReservationManager" do | ||
| expect(@reservation_manager).must_be_kind_of ReservationManager | ||
| end | ||
|
|
||
| it "initializes the correct data structure" do | ||
| expect(@reservation_manager.rooms).must_be_kind_of Array | ||
| expect(@reservation_manager.reservations).must_be_kind_of Array | ||
| end | ||
|
|
||
| it "creates 20 rooms on initiation" do | ||
| expect(@reservation_manager.rooms.length).must_equal 20 | ||
| end | ||
| end | ||
|
|
||
| describe "ReservationManager#make_reservation" do | ||
| before do | ||
| @reservation_manager = ReservationManager.new | ||
| end | ||
|
|
||
| it "creates a reservation" do | ||
| reservation = @reservation_manager.make_reservation(2018923, 2018926) | ||
|
|
||
| expect(reservation).must_be_kind_of Reservation | ||
| reservation.check_in.must_equal 2018923 | ||
|
|
||
| reservation_1 = @reservation_manager.make_reservation(2018910, 2018911) | ||
|
|
||
| end | ||
| # | ||
| # it "adds reservation to list of reservarions made" do | ||
| # | ||
| # @reservation_manager.make_reservation(2018923, 2018926) | ||
| # expect(@reservation_manager.reservations.length).must_equal 1 | ||
| # end | ||
| end | ||
|
|
||
| # TODO: | ||
| # That you can make a reservation | ||
| # That if you have a reservation in a date range, the next room is selected. | ||
| # If all rooms are booked, an error is produced. | ||
| # If a reservation ends on the new booking date, the room can be reserved. | ||
|
|
||
| # describe "Hotel#find_reservation(date)" do | ||
| # it "find a reservation using the date" do | ||
| # hotel = Hotel.new | ||
| # hotel.make_reservation(2018923, 2018926) | ||
| # reservation_2 = hotel.make_reservation(20181023, 20181028) | ||
| # | ||
| # expect(hotel.find_reservation(2018923)).must_be_kind_of Reservation | ||
| # expect(hotel.find_reservation(20181023)).must_equal reservation_2 | ||
| # end | ||
| # | ||
| # it "finds the correct reservation using the date" do | ||
| # hotel = Hotel.new | ||
| # hotel.make_reservation(2018923, 2018926) | ||
| # reservation_2 = hotel.make_reservation(20181023, 20181028) | ||
| # | ||
| # expect(hotel.find_reservation(2018923)).must_be_kind_of Reservation | ||
| # expect(hotel.find_reservation(20181023)).must_equal reservation_2 | ||
| # end | ||
| # end | ||
|
|
||
| # describe "Hotel#list_rooms_available(start_date, end_date)" do | ||
| # before do | ||
| # @hotel = Hotel.new | ||
| # @hotel.make_reservation(2018923, 2018926) | ||
| # reservation_2 = @hotel.make_reservation(20181023, 20181028) | ||
| # end | ||
| # | ||
| # it "finds room dates" do | ||
| # binding.pry | ||
| # expect(@hotel.list_rooms_available(2018923, 201892)) | ||
| # end | ||
| # end | ||
| # describe "Hotel#find_available_rooms(check_in, check_out)" do | ||
| # before do | ||
| # hotel = Hotel.new | ||
| # reservation_1 = hotel.make_reservation(2018923, 2018926) | ||
| # reservation_2 = hotel.make_reservation(2018923, 2018928) | ||
| # reservation_3 = hotel.make_reservation(2018925, 2018101) | ||
| # binding.pry | ||
| # end | ||
| # | ||
| # it "returns all rooms that are availble for given dates" do | ||
| # # binding.pry | ||
| # expect(hotel.find_available_rooms(2018923, 2018926)) | ||
| # end | ||
| # # | ||
| # end | ||
|
|
||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| require_relative 'spec_helper' | ||
| require 'minitest' | ||
| require 'minitest/autorun' | ||
| require 'minitest/reporters' | ||
| require 'pry' | ||
|
|
||
| Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new | ||
|
|
||
| require_relative '../lib/room.rb' | ||
| require_relative '../lib/reservation.rb' | ||
| require_relative '../lib/hotel.rb' | ||
|
|
||
|
|
||
| describe "Reservation Class" do | ||
| describe "initializer" do | ||
| before do | ||
| room = Room.new(2) | ||
| @reservation = Reservation.new(2018923, 2018926, room) | ||
| end | ||
|
|
||
| it "returns an instance of Reservation" do | ||
| expect(@reservation).must_be_kind_of Reservation | ||
| end | ||
|
|
||
| it "raises error when given invalid dates" do | ||
| room = Room.new(2) | ||
| expect {(Reservation.new(2018926, 2018923, room))}.must_raise ArgumentError | ||
| end | ||
|
|
||
| it "calculates the reservation cost correctly" do | ||
| expect(@reservation.cost).must_equal 600 | ||
| end | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's public, you should also test the Plus the |
||
| end | ||
| # TODO: Test for nights and during? methods | ||
|
|
||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class seems to mostly serve as a a container for reservations, which might be better served as a feature of your
Hotelclass.