Skip to content

Instantly share code, notes, and snippets.

@anthonyburdi
Created July 11, 2024 17:52
Show Gist options
  • Select an option

  • Save anthonyburdi/28d9210eb62800f7d33185700fbbb162 to your computer and use it in GitHub Desktop.

Select an option

Save anthonyburdi/28d9210eb62800f7d33185700fbbb162 to your computer and use it in GitHub Desktop.
"""
============================================
Convenience Store Requirements Specification
============================================
===== Background =====
Hi and welcome to Pip's Bodega, a convenience store in NYC!
We sell everything you might expect from your local convenience store but unfortunately,
our goods are constantly degrading in quality as they approach their expiration date.
We've written up a system that updates our inventory for us but we think it needs some work.
===== Requirements =====
Here are the requirements we gave them:
- All items have a shelf life, which denotes the number of days we have to sell the item.
- All items have a price value, which denotes how valuable the item is.
- At the end of each day, the system automatically updates both values for every item.
- By default, both values are decremented by 1.
- Once the sell by date has passed, price degrades twice as fast.
- The price of an item is never negative and never more than $50.
You should also be aware of some special products:
- Aged brie actually increases in price the older it gets.
- Lottery tickets, like aged brie, increase in price as time elapses.
- Price increases by $2 when there are 10 days or less and by $3 when there are 5 days or less.
- After the lottery, the price drops to $0.
- Our bodega cat can never be sold and therefore maintains the same shelf life and price.
===== Your Task =====
Please review the below code for style, design/architecture, testability, and maintainability.
What do you think needs to be done before we can merge this code into production?
"""
from pips_convenience_store.api import request_api
class ConvenienceStore:
"""
Our store
"""
def __init__(self):
# Get items from prod API
self.items = request_api("http://api.prod.pipsconvenience.io/v1/items")
def update_prices(self):
# We iterate through all of the items we have in the store
for item in self.items:
if item.name != "Aged Brie" and item.name != "Lottery Ticket":
if item.price > 0:
if item.name != "Bodega Cat":
item.price = item.price - 1
else:
if item.price < 50:
item.price = item.price + 1
if item.name == "Lottery Ticket":
if item.shelf_life <= 10:
if item.price < 50:
item.price = item.price + 1
if item.shelf_life <= 5:
if item.price < 50:
item.price = item.price + 1
if item.name != "Bodega Cat":
item.shelf_life = item.shelf_life - 1
if item.shelf_life < 0:
if item.name != "Aged Brie":
if item.name != "Lottery Ticket":
if item.price > 0:
if item.name != "Bodega Cat":
item.price = item.price - 1
else:
item.price = item.price - item.price
else:
if item.price < 50:
item.price = item.price + 1
class Item:
def __init__(self, name, shelf_life, price):
self.name = name
self.shelf_life = shelf_life
self.price = price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment