-
Notifications
You must be signed in to change notification settings - Fork 110
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
Cheetahs 18 - Alyssa R. #80
base: master
Are you sure you want to change the base?
Changes from all commits
397d47d
80d0631
6c5e93b
6f171ef
83210e6
1d944c3
9d41d1a
79d0476
dc31761
09f2683
9167c03
7c88243
c89af05
379a7f1
988f081
800e354
c56b7ba
cdd6bba
1254610
b117b51
89a6eb8
a8bb8bb
649ac70
3fb9176
8ffb259
7022952
fa6a304
e8c4269
d15c7e1
c402578
c6713e5
6d3b365
9bf1020
480061a
67d26f1
be42eb2
60c2472
84b12f2
d2c4111
ca41d7d
767f7c6
ac17b09
9182871
edb63b3
2e32ea5
313f632
72488b3
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,12 @@ | ||
class Clothing: | ||
pass | ||
from .item import Item | ||
|
||
class Clothing(Item): | ||
|
||
def __init__(self, condition=0): | ||
super().__init__("Clothing", condition) | ||
# self.category = "Clothing" | ||
# self.condition = condition | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
class Decor: | ||
pass | ||
from .item import Item | ||
|
||
class Decor(Item): | ||
|
||
def __init__(self, condition=0): | ||
super().__init__("Decor", condition) | ||
# self.category = "Decor" | ||
# self.condition = condition | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
class Electronics: | ||
pass | ||
from .item import Item | ||
|
||
class Electronics(Item): | ||
|
||
def __init__(self, condition=0): | ||
super().__init__("Electronics", condition) | ||
# self.category = "Electronics" | ||
# self.condition = condition | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,23 @@ | ||
class Item: | ||
pass | ||
def __init__(self, category="", condition=0): | ||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
'''Returns descriptions of condition based on condition value.''' | ||
condition_dict = { | ||
0:"Yo this is trash.", | ||
1:"Definitely used. Perhaps too much.", | ||
2:"If you're okay with some dings and things.", | ||
3:"Lots of life left if you handle with care.", | ||
4:"Barely even a scratch.", | ||
5:"ULTRA RARE PIECE, NWOT CONDITION.", | ||
|
||
} | ||
if self.condition in condition_dict: | ||
return condition_dict[self.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. Great job with your |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,69 @@ | ||
from re import I | ||
from swap_meet.item import Item | ||
|
||
class Vendor: | ||
pass | ||
def __init__(self, inventory=None): | ||
'''A blueprint for different store inventories.''' | ||
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 inventory is None: | ||
inventory = [] | ||
self.inventory = inventory | ||
|
||
def add(self, item): | ||
'''Add an item to the inventory list.''' | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
'''Remove an item from inventory list.''' | ||
if item not in self.inventory: | ||
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. This approach works, but consider how a |
||
return False | ||
self.inventory.remove(item) | ||
return item | ||
|
||
def get_by_category(self, category): | ||
'''Return a list of items in the inventory with category.''' | ||
category_list = [i for i in self.inventory if i.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. Great list comprehension! 👏🏾 Be sure to use descriptive variable names here too though! |
||
return category_list | ||
|
||
def swap_items(self, other_vendor, my_item, their_item): | ||
'''Remove an item from this Vendor's inventory and swaps | ||
with other vendor.''' | ||
if my_item not in self.inventory or their_item not in other_vendor.inventory: | ||
return False | ||
self.add(their_item) | ||
self.remove(my_item) | ||
other_vendor.add(my_item) | ||
other_vendor.remove(their_item) | ||
return True | ||
|
||
|
||
def swap_first_item(self, other_vendor): | ||
'''Swap the first item in this vendor's inventory with | ||
first item of other vendor.''' | ||
if self.inventory and other_vendor.inventory: | ||
my_item = self.inventory[0] | ||
their_item = other_vendor.inventory[0] | ||
self.swap_items(other_vendor, my_item, their_item) | ||
return True | ||
else: | ||
return False | ||
|
||
def get_best_by_category(self, category): | ||
'''Returns item with the best condition in a certain category.''' | ||
items_in_category = self.get_by_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. Nice usage of an already implemented function 👍🏾 |
||
if not items_in_category: | ||
return None | ||
best_item = max(items_in_category, key=lambda item: item.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. Oooo! Great usage of the |
||
|
||
return best_item | ||
|
||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
'''Swap best item of certain categories with another vendor.''' | ||
my_item = self.get_best_by_category(their_priority) | ||
their_item = other.get_best_by_category(my_priority) | ||
|
||
if my_item is None or their_item is None: | ||
return False | ||
self.swap_items(other, my_item, their_item) | ||
return True |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,12 @@ | |
from swap_meet.vendor import Vendor | ||
from swap_meet.item import Item | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
def test_items_have_blank_default_category(): | ||
item = Item() | ||
assert item.category == "" | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
def test_get_items_by_category(): | ||
item_a = Item(category="clothing") | ||
item_b = Item(category="electronics") | ||
|
@@ -23,7 +23,7 @@ def test_get_items_by_category(): | |
assert item_c in items | ||
assert item_b not in items | ||
|
||
@pytest.mark.skip | ||
# @pytest.mark.skip | ||
def test_get_no_matching_items_by_category(): | ||
item_a = Item(category="clothing") | ||
item_b = Item(category="clothing") | ||
|
@@ -34,7 +34,11 @@ def test_get_no_matching_items_by_category(): | |
|
||
items = vendor.get_by_category("electronics") | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
assert len(items) == 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. Good asserts 👍🏾 |
||
assert item_a not in items | ||
assert item_b not in items | ||
assert item_c not in items | ||
# raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* |
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.
Great job with wave 5 and using inheritance! Nice work hardcoding the category too 🥳