Docstring, document, and code changes to conform to pylinting.

This commit is contained in:
BethanyG
2021-09-06 09:22:50 -07:00
committed by BethanyG
parent 08ad05c618
commit bd9eeff50b
4 changed files with 123 additions and 87 deletions

View File

@@ -1,76 +1,103 @@
# Instructions
The exercise has 6 challenges to complete.
You are the Maître D' of a hotel restaurant. Your task is to manage the seating arrangements for the dining room according to the number of seats available today, number of reservations, and the "walk in" guests currently waiting to be seated. For the purposes of this exercise, seating is assigned by first available empty seat.
You are the Maître D' of a hotel restaurant.
Your task is to manage the seating arrangements for the dining room according to the number of seats available today, number of reservations, and the "walk in" guests currently waiting to be seated.
For the purposes of this exercise, seating is assigned by first available empty seat.
For this exercise, you have 6 different dining room organization challenges to complete.
You have 6 different dining room organization challenges to complete.
## 1. Make Today's Seating Chart
Define the `new_seating_chart()` function that takes a size argument representing the number of seats that will be set in the dining room today. If no `size` is given, the function should return a seating chart with 22 seats. Seat values should have a placeholder of `None` to indicate they are available to assign to a guest.
Define the `new_seating_chart(<size=22>)` function that takes a size argument representing the number of seats that will be set in the dining room today.
If no `size` is given, the function should return a seating chart with 22 seats.
Seat values should have a placeholder of `None` to indicate they are available to assign to a guest.
## 2. Arrange Reservations
Define the `arrange_reservations()` function with 1 parameter for a list of guest names. This represents the number of people who've reserved places in the dining room today.
Define the `arrange_reservations(<guest_names>)` function with 1 parameter for a list of guest names.
This represents the number of people who have places reserved in the dining room today.
This function should return a `dict` seating chart of default size (22 seats), with guests assigned to seats in the order they appear on the reservation list.
All unassigned seats should be set to `None`.
If there are no guests, an "empty" seating chart with all `None` placeholders should be returned.
This function should return a `dict` seating chart of default size (22 seats), with guests assigned to seats in the order they appear on the reservation list. All unassigned seats should be set to `None`. If there are no guests, an "empty" seating chart with all `None` placeholders should be returned.
```python
arrange_reservatons(guests=["Walter", "Frank", "Jenny", "Carol", "Alice", "George"])
#=> {1: 'Walter', 2: 'Frank', 3: 'Jenny', 4: 'Carol', 5: 'Alice', 6: 'George', 7: None, 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: None, 19: None, 20: None, 21: None, 22: None}
>>> arrange_reservations(guests=["Walter", "Frank", "Jenny", "Carol", "Alice", "George"])
...
{1: 'Walter', 2: 'Frank', 3: 'Jenny', 4: 'Carol', 5: 'Alice', 6: 'George', 7: None, 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: None, 19: None, 20: None, 21: None, 22: None}
```
## 3. Find All the "Empty" Seats
Define the `find_all_available_seats(seats)` function that takes 1 parameter (_a seating chart dictionary_) and returns a `list` of seat numbers that are available for guests that are currently waiting.
Define the `find_all_available_seats(<seats>)` function that takes 1 parameter (_a seating chart dictionary_) and returns a `list` of seat numbers that are available for guests that are currently waiting.
If a seat is empty, It will be of `None` value in the dictionary. Occupied seats will have the name of the guest.
```python
seats = {1: None, 2: 'Frank', 3: 'Jenny', 4: None, 5: 'Alice', 6: 'George', 7: None, 8: 'Carol', 9: None, 10: None, 11: None, 12: 'Walter'}
find_all_available_seats(seats)
#>>>[1,4,7,9,10,11]
>>> seats = {1: None, 2: 'Frank', 3: 'Jenny', 4: None, 5: 'Alice', 6: 'George', 7: None, 8: 'Carol', 9: None, 10: None, 11: None, 12: 'Walter'}
>>> find_all_available_seats(seats)
[1,4,7,9,10,11]
```
## 4. Current Empty Seating Capacity
Define the `curr_empty_seat_capacity()` function that takes 1 parameter. The first parameter will list all the seats.
You need to find out what is the total number of seats that are empty.
Define the `current_empty_seat_capacity(<seats>)` function that takes 1 parameter - the `dict` of existing seat reservations.
The function should return the total number of seats that are empty.
```python
curr_empty_seat_capacity(seats={1: "Occupied", 2: None, 3: "Occupied"})
# => 1
can_accomodate_seats(seats={1: "Occupied", 2: None, 3: None})
# => 2
>>> curr_empty_seat_capacity({1: "Occupied", 2: None, 3: "Occupied"})
1
>>> curr_empty_seat_capacity({1: "Occupied", 2: None, 3: None})
2
```
## 5. Should we wait?
Define the `accommodate_waiting_guests(seats, guests)` function that takes two parameters. The first parameter will be a seating chart `dict`. The second parameter will be a `list` of guests who have "walked in" unexpectedly.
Define the `accommodate_waiting_guests(<seats>, <guests>)` function that takes two parameters.
The first parameter will be a seating chart `dict`.
The second parameter will be a `list` of guests who have "walked in" unexpectedly.
You'll first need to find out how many seats are available and whether or not you can even give the unannounced guests seats at this time.
If you do not have enough seats, return `False`.
If you do not have enough seats, return the seating chart `dict` unaltered.
If seats _are_ available, assign the guests places on the seating chart, and return it updated.
**Tip:** You can use previously defined functions to do the calculations for you.
If seats are available, you will want to give the guests places on the seating chart, and return it updated.
Tip: You can use previously defined functions to do the calculations for you.
```python
starting_reservations = {1: 'Carol', 2: 'Alice', 3: 'George', 4: None, 5: None, 6: None, 7: 'Frank', 8: 'Walter'}
accomodate_guests(starting_reservations, ["Mort", "Suze", "Phillip", "Tony"])
#>>>False
starting_reservations = {1: None, 2: None, 3: None, 4: 'Carol', 5: 'Alice', 6: 'George', 7: None, 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: 'Frank', 19: 'Jenny', 20: None, 21: None, 22: 'Walter'}
accomodate_guests(starting_reservations, ["Mort", "Suze", "Phillip", "Tony"])
#>>>{1: 'Mort', 2: 'Suze', 3: 'Phillip', 4: 'Carol', 5: 'Alice', 6: 'George', 7: 'Tony', 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: 'Frank', 19: 'Jenny', 20: None, 21: None, 22: 'Walter'}
# Guests cannot be accommodated.
>>> starting_reservations = {1: 'Carol', 2: 'Alice', 3: 'George', 4: None, 5: None, 6: None, 7: 'Frank', 8: 'Walter'}
>>> accommodate_guests(starting_reservations, ["Mort", "Suze", "Phillip", "Tony"])
...
{1: 'Carol', 2: 'Alice', 3: 'George', 4: None, 5: None, 6: None, 7: 'Frank', 8: 'Walter'}
# Guests can be accommodated.
>>> starting_reservations = {1: None, 2: None, 3: None, 4: 'Carol', 5: 'Alice', 6: 'George', 7: None, 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: 'Frank', 19: 'Jenny', 20: None, 21: None, 22: 'Walter'}
>>> accommodate_guests(starting_reservations, ["Mort", "Suze", "Phillip", "Tony"])
...
{1: 'Mort', 2: 'Suze', 3: 'Phillip', 4: 'Carol', 5: 'Alice', 6: 'George', 7: 'Tony', 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: 'Frank', 19: 'Jenny', 20: None, 21: None, 22: 'Walter'}
```
## 6. Empty Seats
Define the `empty_seats()` function that takes two parameters. The first parameter will be a seating chart dictionary. The second parameter is a list of seat numbers you need to "free up" or empty -- that is, you need to assign the seat number value to `None`.
Define the `empty_seats(<seats>, <seat_numbers>)` function that takes two parameters.
The first parameter will be a seating chart dictionary.
The second parameter is a list of seat numbers you need to "free up" or empty -- that is, you need to assign the seat number value to `None`.
Return the `dict` of seats sent as the parameter after updating the empty seat values.
Return the `dict` of seats after updating the "to empty" seat values.
```python
empty_seats(seats={1: "Alice", 2: None, 3: "Bob", 4: "George", 5: "Gloria"}, seat_numbers=[5,3,1])
# => {1: None, 2: None, 3: None, 4: "George", 5: None}
>>> empty_seats(seats={1: "Alice", 2: None, 3: "Bob", 4: "George", 5: "Gloria"}, seat_numbers=[5,3,1])
{1: None, 2: None, 3: None, 4: "George", 5: None}
```

View File

@@ -1,21 +1,20 @@
def new_seating_chart(size=22):
'''
"""Create a new seating chart.
:param size: int - number if seats in the seating chart.
:return: dict - with number of seats specified, and placeholder values.
'''
"""
return {number: None for number in range(1, size+1) }
return {number: None for number in range(1, size + 1)}
def arrange_reservations(guests=None):
'''
"""Assign guests to seats.
:param guest_list: list - list of guest names for reservations.
:return: dict - Default sized dictionary with guests assigned seats,
and placeholders for empty seats.
'''
"""
seats = new_seating_chart()
@@ -26,11 +25,11 @@ def arrange_reservations(guests=None):
def find_all_available_seats(seats):
'''
"""Find and return seat numbers that are unassigned.
:param seats: dict - seating chart.
:return: list - list of seat numbers available for reserving..
'''
"""
available = []
for seat_num, value in seats.items():
@@ -39,12 +38,12 @@ def find_all_available_seats(seats):
return available
def curr_empty_seat_capacity(seats):
'''
def current_empty_seat_capacity(seats):
"""Find the number of seats that are currently empty.
:param seats: dict - dictionary of reserved seats.
:return: int - number of seats empty.
'''
"""
count = 0
for value in seats.values():
@@ -54,34 +53,32 @@ def curr_empty_seat_capacity(seats):
def accommodate_waiting_guests(seats, guests):
'''
"""Asses if guest can be accommodated. Update seating if they can be.
:param seats: dict - seating chart dictionary.
:param guests: list - walk-in guests
:return: dict - updated seating chart with available spaces filled.
'''
"""
curr_empty_seats = curr_empty_seat_capacity(seats)
curr_empty_seats = current_empty_seat_capacity(seats)
empty_seat_list = find_all_available_seats(seats)
if len(guests) > curr_empty_seats:
return False
else:
for index, item in enumerate(guests):
if len(guests) <= curr_empty_seats:
for index, _ in enumerate(guests):
seats[empty_seat_list[index]] = guests[index]
return seats
def empty_seats(seats, seat_numbers):
'''
"""Empty listed seats of their previous reservations.
:param seats: dict - seating chart dictionary.
:param seat_numbers: list - list of seat numbers to free up or empty.
:return: updated seating chart dictionary.
'''
"""
for seat in seat_numbers:
seats[seat] = None
return seats
return seats

View File

@@ -1,57 +1,61 @@
def new_seating_chart(size=22):
'''
"""Create a new seating chart.
:param size: int - number if seats in the seating chart. Default is 22.
:return: dict - with number of seats specified, and placeholder values.
'''
"""
pass
def arrange_reservations(guest_list):
'''
"""Assign guests to seats.
:param guest_list: list - list of guest names for reservations.
:return: dict - Default sized dictionary with guests assigned seats,
and placeholders for empty seats.
'''
"""
pass
def find_all_available_seats(seats):
'''
"""Find and return seat numbers that are unassigned.
:param seats: dict - seating chart.
:return: list - list of seat numbers available for reserving..
'''
"""
pass
def current_seating_capacity(seats):
'''
def current_empty_seat_capacity(seats):
"""Find the number of seats that are currently empty.
:param seats: dict - dictionary of reserved seats.
:return: int - number of seats empty.
'''
"""
pass
def accommodate_waiting_guests(seats, guests):
'''
"""Asses if guest can be accommodated. Update seating if they can be.
:param seats: dict - seating chart dictionary.
:param guests: list - walk-in guests
:return: dict - updated seating chart with available spaces filled.
'''
"""
pass
def empty_seats(seats, seat_numbers):
'''
"""Empty listed seats of their previous reservations.
:param seats: dict - seating chart dictionary.
:param seat_numbers: list - list of seat numbers to free up or empty.
:return: updated seating chart dictionary.
'''
"""
pass
pass

View File

@@ -4,7 +4,7 @@ from none import (
new_seating_chart,
arrange_reservations,
find_all_available_seats,
curr_empty_seat_capacity,
current_empty_seat_capacity,
accommodate_waiting_guests,
empty_seats
)
@@ -25,7 +25,7 @@ class TestNoneType(unittest.TestCase):
self.assertDictEqual(
new_seating_chart(),
{1: None, 2: None, 3: None, 4: None, 5: None, 6: None, 7: None, 8: None, 9: None, 10: None,
11: None,12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: None, 19: None,
11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: None, 19: None,
20: None, 21: None, 22: None},
msg="The New Seating chart does not match with the expected."
)
@@ -54,56 +54,64 @@ class TestNoneType(unittest.TestCase):
@pytest.mark.task(taskno=3)
def test_find_all_available_seats_1(self):
self.assertListEqual(
find_all_available_seats(seats = {1: None, 2: 'Frank', 3: 'Jenny', 4: None, 5: 'Alice', 6: 'George', 7: None, 8: 'Carol', 9: None, 10: None, 11: None, 12: 'Walter'}),
[1,4,7,9,10,11],
find_all_available_seats(
seats={1: None, 2: 'Frank', 3: 'Jenny', 4: None, 5: 'Alice', 6: 'George', 7: None, 8: 'Carol', 9: None,
10: None, 11: None, 12: 'Walter'}),
[1, 4, 7, 9, 10, 11],
msg="The Available Seat list is incorrect"
)
@pytest.mark.task(taskno=3)
def test_find_all_available_seats_2(self):
self.assertListEqual(
find_all_available_seats(seats = {1: None, 2: None, 3: None, 4: None, 5: 'Alice', 6: None, 7: None, 8: None, 9: None, 10: None, 11: None, 12: None}),
find_all_available_seats(
seats={1: None, 2: None, 3: None, 4: None, 5: 'Alice', 6: None, 7: None, 8: None, 9: None, 10: None,
11: None, 12: None}),
[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12],
msg="The Available Seat list is incorrect"
)
@pytest.mark.task(taskno=4)
def test_curr_empty_seat_capacity_1(self):
def test_current_empty_seat_capacityy_1(self):
self.assertIs(
curr_empty_seat_capacity({1: "Occupied", 2: None, 3: "Occupied"}),
current_empty_seat_capacity({1: "Occupied", 2: None, 3: "Occupied"}),
1,
msg="the index of the seat which is empty is invalid."
)
@pytest.mark.task(taskno=4)
def test_curr_empty_seat_capacity_2(self):
def test_current_empty_seat_capacityy_2(self):
self.assertIs(
curr_empty_seat_capacity({1: "Occupied", 2: "Occupied", 3: None, 4: "Occupied", 5: None}),
current_empty_seat_capacity({1: "Occupied", 2: "Occupied", 3: None, 4: "Occupied", 5: None}),
2,
msg="the index of the seat which is empty is invalid."
)
@pytest.mark.task(taskno=5)
def test_accommodate_waiting_guests_1(self):
starting_reservations = {1: 'Carol', 2: 'Alice', 3: 'George', 4: None, 5: None, 6: None, 7: 'Frank', 8: 'Walter'}
self.assertFalse(
accommodate_waiting_guests(starting_reservations, ["Mort", "Suze", "Phillip", "Tony"]),
msg="The Accomodation of waiting guests are incorrect"
)
starting_reservations = {1: 'Carol', 2: 'Alice', 3: 'George', 4: None, 5: None, 6: None, 7: 'Frank',
8: 'Walter'}
self.assertDictEqual(
accommodate_waiting_guests(starting_reservations, ["Mort", "Suze", "Phillip", "Tony"]), starting_reservations,
msg="The Accommodation of waiting guests are incorrect")
@pytest.mark.task(taskno=5)
def test_accommodate_waiting_guests_2(self):
starting_reservations = {1: None, 2: None, 3: None, 4: 'Carol', 5: 'Alice', 6: 'George', 7: None, 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: 'Frank', 19: 'Jenny', 20: None, 21: None, 22: 'Walter'}
starting_reservations = {1: None, 2: None, 3: None, 4: 'Carol', 5: 'Alice', 6: 'George', 7: None, 8: None,
9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None,
17: None, 18: 'Frank', 19: 'Jenny', 20: None, 21: None, 22: 'Walter'}
self.assertDictEqual(
accommodate_waiting_guests(starting_reservations, ["Mort", "Suze", "Phillip", "Tony"]),
{1: 'Mort', 2: 'Suze', 3: 'Phillip', 4: 'Carol', 5: 'Alice', 6: 'George', 7: 'Tony', 8: None, 9: None, 10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: 'Frank', 19: 'Jenny', 20: None, 21: None, 22: 'Walter'},
msg="The Accomodation of waiting guests are incorrect"
{1: 'Mort', 2: 'Suze', 3: 'Phillip', 4: 'Carol', 5: 'Alice', 6: 'George', 7: 'Tony', 8: None, 9: None,
10: None, 11: None, 12: None, 13: None, 14: None, 15: None, 16: None, 17: None, 18: 'Frank', 19: 'Jenny',
20: None, 21: None, 22: 'Walter'},
msg="The Accommodation of waiting guests are incorrect"
)
@pytest.mark.task(taskno=6)
def test_empty_seats_1(self):
self.assertDictEqual(
empty_seats(seats={1: "Alice", 2: None, 3: "Bob", 4: "George", 5: "Gloria"}, seat_numbers=[5,3,1]),
empty_seats(seats={1: "Alice", 2: None, 3: "Bob", 4: "George", 5: "Gloria"}, seat_numbers=[5, 3, 1]),
{1: None, 2: None, 3: None, 4: "George", 5: None},
msg="Seats are not emptied properly"
)
@@ -114,4 +122,4 @@ class TestNoneType(unittest.TestCase):
empty_seats(seats={1: "Alice", 2: None, 3: "Bob", 4: "George", 5: "Gloria"}, seat_numbers=[]),
{1: "Alice", 2: None, 3: "Bob", 4: "George", 5: "Gloria"},
msg="Seats are not emptied properly"
)
)