-
Notifications
You must be signed in to change notification settings - Fork 113
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
Otters - Tori Shade #101
base: master
Are you sure you want to change the base?
Otters - Tori Shade #101
Changes from all commits
a354091
0f90727
cb0c414
04ec7fa
f605720
abab276
07aed83
c8e7861
f8e44c3
5d9c84f
ac0ac9c
8ac5271
afd4d0c
3bec9bc
c0e22db
f72903f
3c02256
83d1498
cffb1e1
25064c1
869b81d
9507b63
ecd65c8
ee8ac00
2aa7efa
9d5f231
71af0e5
ba1814e
ef45658
0700961
dc870b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
'''Clothing class is instantiated and inherits from Item class''' | ||
|
||
def __init__(self, category = "Clothing", condition = 0, age = 0): | ||
super(). __init__(category, condition, age) | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
'''Decor class is instantiated and inherits from Item class''' | ||
|
||
def __init__(self, category = "Decor", condition = 0, age = 0): | ||
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. note about |
||
super(). __init__(category, condition, age) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
'''Electronics class is instantiated and inherits from Item class''' | ||
|
||
def __init__(self, category = "Electronics", condition = 0, age = 0): | ||
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. note about |
||
super(). __init__(category, condition, age) | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
class Item: | ||
pass | ||
|
||
'''Item class is instantiated''' | ||
def __init__(self, category=None, condition = 0, age = 0): | ||
if not category: | ||
category = "" | ||
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. Strings are immutable so you can set an empty string as a default value in the parameters :) |
||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
'''Function returns condition description based on quantitative value assigned to condition''' | ||
|
||
if self.condition == 0: | ||
return f"terrible" | ||
if self.condition == 1: | ||
return f"not great" | ||
if self.condition == 2: | ||
return f"kinda ok" | ||
if self.condition == 3: | ||
return f"you'll do" | ||
if self.condition == 4: | ||
return f"basic" | ||
if self.condition == 5: | ||
return f"vibe" | ||
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. Lol @ "vibe" small note - make sure to have a blank line at the end of all your Python files. It's convention. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,107 @@ | ||
class Vendor: | ||
pass | ||
|
||
def __init__(self, inventory = None): | ||
'''Vendor class is instantiated''' | ||
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. Beautiful docstrings 👏 |
||
|
||
if not inventory: | ||
inventory = [] | ||
self.inventory = inventory | ||
|
||
def add(self, item): | ||
'''Function used to add items to vendor's inventory''' | ||
|
||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
'''Function used to remove items from vendor's inventory''' | ||
|
||
if item not in self.inventory: | ||
return False | ||
else: | ||
self.inventory.remove(item) | ||
return item | ||
|
||
def get_by_category(self, category): | ||
'''Function returns items in vendor's inventory if they belong to the category passed within the parameter''' | ||
|
||
items_in_category = [] | ||
|
||
for item in self.inventory: | ||
if category == item.category: | ||
items_in_category.append(item) | ||
return items_in_category | ||
|
||
def swap_items(self, other, my_item, their_item): | ||
'''Function allows this vendor and another vendor to swap items from their respective inventories''' | ||
|
||
if my_item not in self.inventory or their_item not in other.inventory: | ||
return False | ||
else: | ||
self.remove(my_item) | ||
other.add(my_item) | ||
|
||
other.remove(their_item) | ||
self.add(their_item) | ||
return True | ||
|
||
def swap_first_item(self, other): | ||
'''Function allows this vendor and another vendor to swap the first item from their respective inventories''' | ||
|
||
if not self.inventory or not other.inventory: | ||
return False | ||
else: | ||
return self.swap_items(other, self.inventory[0], other.inventory[0]) | ||
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. Nice usage of |
||
|
||
def get_best_by_category(self, category): | ||
'''Function identifies the item in the best condition within a certain category of a vendor's inventory''' | ||
|
||
current_condition = 0 | ||
best_condition = None | ||
|
||
for item in self.inventory: | ||
if item.category == category: | ||
if item.condition > current_condition: | ||
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. small note - you could combine these conditional statements on one line using the |
||
current_condition = item.condition | ||
best_condition = item | ||
|
||
return best_condition | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
'''Function swaps the items in the best condition with that of other vendors if in a certain category''' | ||
|
||
my_best_item = self.get_best_by_category(their_priority) | ||
their_best_item = other.get_best_by_category(my_priority) | ||
|
||
if not my_best_item or not their_best_item: | ||
return False | ||
else: | ||
self.swap_items(other, my_best_item, their_best_item) | ||
return True | ||
|
||
def get_newest_by_category(self, category): | ||
'''Function identifies the newest item within a certain category of a vendor's inventory''' | ||
|
||
item_age_flag_max_30 = 30 | ||
newest_item = None | ||
|
||
for item in self.inventory: | ||
if item.category == category: | ||
if item.age <= item_age_flag_max_30: | ||
item_age_flag_max_30 = item.age | ||
newest_item = item | ||
|
||
return newest_item | ||
|
||
def swap_newest_by_category(self, category, other): | ||
'''Function swaps the newest item with that of other vendors newest item if in a certain category''' | ||
|
||
my_newest_item = self.get_newest_by_category(category) | ||
|
||
their_newest_item = other.get_newest_by_category(category) | ||
|
||
if not my_newest_item or not their_newest_item: | ||
return False | ||
else: | ||
self.swap_items(other, my_newest_item, their_newest_item) | ||
return True |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
|
||
@pytest.mark.skip | ||
@pytest.mark.integration_test | ||
#@pytest.mark.skip | ||
#@pytest.mark.integration_test | ||
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. In the future, don't worry about commenting out |
||
def test_integration_wave_01_02_03(): | ||
# make a vendor | ||
vendor = Vendor() | ||
|
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.
small note - if all items for this child class should have their category attribute set to "Clothing", do we need to have category as a parameter in the constructor? This makes it possible for users to set the category to something else which could lead to unexpected problems in our application. Think about how you could update your code to make sure the category for this class is always set to "Clothing"