-
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
C17 Otters Vera Sazonova #93
base: master
Are you sure you want to change the base?
Changes from all commits
cfcb490
aec0ff0
6501ba2
25b5b3c
602fce8
6831a05
ef5f401
d002359
6e9f376
abedbbf
0411cc2
2f29c6c
c40666c
ba5c2bd
734a294
74179c9
1ba3be4
2745012
68d3804
f6a27e7
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 .item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, condition = 0.0): | ||
super().__init__(category = "Clothing", 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,9 @@ | ||
class Decor: | ||
pass | ||
from .item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, condition = 0.0): | ||
super().__init__(category = "Decor", condition = condition) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
class Electronics: | ||
pass | ||
from .item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, condition = 0.0): | ||
super().__init__(category = "Electronics", 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,38 @@ | ||
class Item: | ||
pass | ||
def __init__(self, category = None, condition = 0.0): | ||
if category is None: | ||
category = "" | ||
self.category = category | ||
self.condition = condition | ||
|
||
|
||
def __repr__(self): | ||
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. Love that you're using the |
||
'''Return name of category in the | ||
terminal, when instance is assign''' | ||
|
||
return self.category | ||
|
||
|
||
def __str__(self): | ||
'''Return string "Hello World!" if | ||
category is not defined''' | ||
|
||
return "Hello World!" | ||
|
||
|
||
def condition_description(self): | ||
'''Method assigning specific | ||
string-output depends of condition''' | ||
|
||
if 0 < self.condition <= 1: | ||
condition_description = "Poor" | ||
elif 1 < self.condition <= 2: | ||
condition_description = "Fair" | ||
elif 2 < self.condition <= 3: | ||
condition_description = "Good" | ||
elif 3 < self.condition <= 4: | ||
condition_description = "Like New" | ||
elif 4 < self.condition <= 5: | ||
condition_description = "New" | ||
return condition_description | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,95 @@ | ||
class Vendor: | ||
pass | ||
class Vendor(): | ||
def __init__(self,inventory = None): | ||
if inventory is None: | ||
inventory = [] | ||
self.inventory = inventory | ||
|
||
|
||
def add(self,item): | ||
'''Instance method add, which | ||
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 docstrings! 👏 |
||
add itens in the inventory list''' | ||
|
||
self.inventory.append(item) | ||
return item | ||
|
||
|
||
def remove(self,item): | ||
'''Instance method remove which | ||
remove item from inventory list''' | ||
|
||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
return False | ||
|
||
|
||
def get_by_category(self,category): | ||
'''Instance method which return | ||
a list of items in the inventory | ||
with that category''' | ||
|
||
list_of_items = [] | ||
for item in self.inventory: | ||
if category == item.category: | ||
list_of_items.append(item) | ||
return list_of_items | ||
|
||
|
||
def swap_items(self, friend, my_item, friends_item): | ||
'''Instance method implement swaping process between vendor and | ||
other person''' | ||
|
||
if my_item not in self.inventory or friends_item not in friend.inventory: | ||
return False | ||
self.remove(my_item) | ||
friend.add(my_item) | ||
friend.remove(friends_item) | ||
self.add(friends_item) | ||
return True | ||
|
||
|
||
def swap_first_item(self, friend): | ||
'''Instance method implement swaping process first item''' | ||
|
||
if len(self.inventory) == 0 or len(friend.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. small note - it's more Pythonic to check if a list is empty by doing |
||
return False | ||
self.swap_items(friend,self.inventory[0],friend.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 |
||
return True | ||
|
||
|
||
def get_best_by_category(self, consider_category): | ||
'''Instance method will get the item with the best | ||
condition in a certain category''' | ||
|
||
best_dict_category = {} | ||
best_dict_category[consider_category] = 0.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 note - you can create a dictionary and specify its values in the same line. So, line 64 could be |
||
# creating counter to check no matches categories in vendors inventory | ||
count = 0 | ||
# consider given represents string of category, add to dictionary | ||
# matching category is key and value is rate. Setup first element | ||
# of dictionary like max and matching other rate, if higher add to dict | ||
for category_from_inv 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. small note - variable names should describe the data they are holding. |
||
if consider_category == category_from_inv.category: | ||
count += 1 | ||
if category_from_inv.condition > best_dict_category[consider_category]: | ||
best_dict_category[category_from_inv.category] = category_from_inv.condition | ||
best_category = category_from_inv | ||
if count == 0: | ||
return None | ||
return best_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. Something to consider - Python doesn't create a local scope for loops which is why you can return |
||
|
||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
'''Instance method will swap the item with the best condition | ||
in a certain category''' | ||
|
||
if len(self.inventory) and len(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.
|
||
best_item_for_friend = self.get_best_by_category(their_priority) | ||
best_item_for_vendor = other.get_best_by_category(my_priority) | ||
if best_item_for_friend is None or best_item_for_vendor is None: | ||
return False | ||
else: | ||
self.swap_items(other,best_item_for_friend,best_item_for_vendor) | ||
return True | ||
return False | ||
|
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.
Strings are immutable objects so it's safe to set an empty string as a default value in your parameters :)