-
Notifications
You must be signed in to change notification settings - Fork 110
Masi Nakhjiri-Cheetahs Group #81
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
base: master
Are you sure you want to change the base?
Changes from all commits
d87ef1b
e53986f
ceaadd8
548d973
b485c9b
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,9 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self,condition =0, age = 0): | ||
super().__init__(category = "Clothing", condition = condition,age =age) | ||
|
||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self,condition =0,age =0): | ||
super().__init__(category = "Decor", condition = condition,age=age) | ||
|
||
|
||
def __str__(self) -> str: | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
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 wave 5 and using inheritance! Nice work hardcoding the category too 🥳 |
||
def __init__(self,condition =0,age =0): | ||
super().__init__(category = "Electronics", condition = condition,age =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,25 @@ | ||
CONDITION_DESCRIPTION = { | ||
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 - I think it's cool that you created a constant for the condition description dictionary, but I would actually recommend keeping this data structure inside your class definition. Because it's outside the class definition, any file that imports this class module can use the constant anyway they would like. For data that should be tied to a class, it's best to have it live inside the class definition so that it can only be accessed the way it was intended to be used. |
||
0:"heavily used", | ||
1:"well loved", | ||
2:"almost new", | ||
3:"medium used", | ||
4:"open box", | ||
5:"mint" | ||
} | ||
|
||
class Item: | ||
pass | ||
def __init__(self,category="",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. Small style note - Try to make sure you are being consistent with your spacing. This line of code should have this spacing (spaces after commas, no spaces around equal signs):
You can read more about whitespace best practices in PEP 8 - Python's style guide |
||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
for key, value in CONDITION_DESCRIPTION.items(): | ||
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. The power of dictionaries is that they allow us to access values in
It's going to be really important to feel comfortable with using dictionaries and accessing items using a key. So, I would highly recommend reviewing dictionaries and maybe doing some extra practice with them if this still feels challenging. |
||
if self.condition is key: | ||
return value | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,89 @@ | ||
from swap_meet.item import Item | ||
class Vendor: | ||
pass | ||
|
||
def __init__(self,inventory = None): | ||
if inventory is None: | ||
inventory =[] | ||
|
||
self.inventory = inventory | ||
|
||
|
||
def add(self,item): | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self,item): | ||
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): | ||
list_items =[] | ||
|
||
for item in self.inventory: | ||
if item.category == category: | ||
list_items.append(item) | ||
|
||
return list_items | ||
|
||
|
||
def swap_items(self,friend,my_item,their_item): | ||
if my_item in self.inventory and their_item in friend.inventory: | ||
friend.add(my_item) | ||
self.remove(my_item) | ||
self.add(their_item) | ||
friend.remove(their_item) | ||
return True | ||
return False | ||
|
||
def swap_first_item(self, friend): | ||
if not self.inventory or not friend.inventory : | ||
return False | ||
self.swap_items(friend, self.inventory[0],friend.inventory[0]) | ||
return True | ||
|
||
|
||
|
||
def get_best_by_category(self, category): | ||
# highest_condition =0 | ||
# highest_item =None | ||
# items_list = self.get_by_category(category) | ||
# for item in items_list: | ||
# if item.condition > highest_condition: | ||
# highest_condition = item.condition | ||
# highest_item = item | ||
|
||
# return highest_item | ||
|
||
# #### refactoring the above lines from 49-57 with Lambda | ||
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. Yayyyy refactoring! 🙌🏾 |
||
items = self.get_by_category(category) | ||
if not items: | ||
return None | ||
|
||
return max( items, 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 |
||
|
||
|
||
def swap_best_by_category(self,other,my_priority,their_priority): | ||
my_best_item = other.get_best_by_category(my_priority) | ||
their_best_item = self.get_best_by_category(their_priority) | ||
return self.swap_items(other,their_best_item,my_best_item) | ||
|
||
|
||
|
||
############### Optional Enhancements ############## | ||
|
||
##### WORKING ON THIS OPTIONAL PART###### | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,9 @@ def test_get_no_matching_items_by_category(): | |
|
||
items = vendor.get_by_category("electronics") | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
# raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* | ||
assert items ==[] | ||
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. Since it's impossible for |
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.
Ooo! You're using type hinting here! Very cool! I would recommend being consistent with it. If you use it in one place, you should probably use it in the rest of your code too.