-
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
Whales C17 - Julie Warren #94
base: master
Are you sure you want to change the base?
Changes from all commits
421565e
8d30b29
ca186c7
bc853a0
be13fcd
28267fe
85594ab
03578cf
5fcec7e
c8b8689
8f44f52
5b2829e
44eddf3
ddbc811
5e53635
52e1c26
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,24 @@ | ||
class Clothing: | ||
pass | ||
from .item import Item | ||
|
||
class Clothing(Item): | ||
''' | ||
A sub-class of Item, indicating a type of item a vendor might have. | ||
|
||
Attributes: | ||
condition (float): optional descr. of item condition, 0 if not defined | ||
category (str): description of item category, always set to "Clothing" | ||
''' | ||
|
||
def __init__(self, condition=0): | ||
''' | ||
Parameter: condition (float): optional description of item | ||
condition, 0 if not defined | ||
''' | ||
|
||
self.category = "Clothing" | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
'''Stringifies Clothing and returns a string describing the class.''' | ||
|
||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
class Decor: | ||
pass | ||
from .item import Item | ||
|
||
class Decor(Item): | ||
''' | ||
A sub-class of Item, indicating a type of item a vendor might have. | ||
|
||
Attributes: | ||
condition (float): optional descr. of item condition, 0 if not defined | ||
category (str): description of item category, always set to "Decor" | ||
''' | ||
|
||
def __init__(self, condition=0): | ||
''' | ||
Parameter: condition (float): optional description of item | ||
condition, 0 if not defined | ||
''' | ||
|
||
self.category = "Decor" | ||
self.condition = condition | ||
Comment on lines
+18
to
+19
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! Another option that works is calling the constructor of the parent (Item) class like |
||
|
||
def __str__(self): | ||
'''Stringifies Decor and returns a string describing the class.''' | ||
|
||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,25 @@ | ||
class Electronics: | ||
pass | ||
from .item import Item | ||
|
||
class Electronics(Item): | ||
''' | ||
A sub-class of Item, indicating a type of item a vendor might have. | ||
|
||
Attributes: | ||
condition (float): optional descr. of item condition, 0 if not defined | ||
category (str): description of item category, always set to "Electronics" | ||
''' | ||
|
||
def __init__(self, condition=0): | ||
''' | ||
Parameter: condition (float): optional description of item | ||
condition, 0 if not defined | ||
''' | ||
|
||
self.category = "Electronics" | ||
self.condition = condition | ||
|
||
|
||
def __str__(self): | ||
'''Stringifies Electronics and returns a string describing the class.''' | ||
|
||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,47 @@ | ||
class Item: | ||
pass | ||
''' | ||
A class indicating an object Item that a vendor might have. | ||
|
||
Attributes: | ||
category (str): optional descr. of item category. None if not defined, | ||
w/attribute set to an empty string. Otherwise set to input param. | ||
condition (float): optional descr. of item condition, 0 if not defined | ||
Comment on lines
+3
to
+8
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 details! |
||
''' | ||
|
||
def __init__(self, category=None, condition=0): | ||
''' | ||
Parameters: | ||
category (str): optional descr. of item category. None if not defined, | ||
w/attribute set to an empty string. Otherwise set to input param. | ||
condition (float): optional descr. of item condition, 0 if not defined | ||
''' | ||
|
||
if category is None: | ||
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. 👍🏻 |
||
self.category = "" | ||
else: | ||
self.category = category | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
'''Stringifies Item and returns a string to say hello.''' | ||
|
||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
''' | ||
Method to return string description related to item condition. | ||
Returns: a string for default condition of 0, and any float up to 5.0 | ||
''' | ||
|
||
if self.condition == 0: | ||
return "I'm not sure about the condition of this item." | ||
elif self.condition <= 1: | ||
return "Why are you even swapping this?" | ||
elif self.condition <= 2: | ||
return "You could do better." | ||
elif self.condition <= 3: | ||
return "Blisteringly mediocre." | ||
elif self.condition <= 4: | ||
return "I'll accept this. I guess." | ||
elif self.condition <= 5: | ||
return "Wow, this is amazing!" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,121 @@ | ||
class Vendor: | ||
pass | ||
''' | ||
A class for a Vendor at a swap-meet who has items. The Vendor may want to | ||
trade with other vendors based on item category, condition, or both. | ||
''' | ||
|
||
def __init__(self, inventory=None): | ||
''' | ||
Parameter: inventory (list): optional list of vendor inventory. | ||
None if not defined, w/attribute set to an empty string. | ||
Otherwise set to input parameter. | ||
''' | ||
|
||
if inventory is None: | ||
self.inventory = [] | ||
else: | ||
self.inventory = inventory | ||
|
||
def add(self, item): | ||
''' | ||
Adds an item to a vendor's inventory | ||
Parameter: item (string, or class object): represents a swappable item | ||
Returns: the added item | ||
''' | ||
|
||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
''' | ||
Removes an item from a vendor's inventory | ||
Parameter: item (string, or class object): represents a swappable item | ||
Returns: the removed item if removed, otherwise False | ||
''' | ||
|
||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
else: | ||
return False | ||
|
||
def get_by_category(self, category): | ||
''' | ||
Gets a list of every item a vendor has that is in a certain category | ||
Parameter: category (string): represents the category of a swappable item | ||
Returns: a list of items with the correct desired category | ||
''' | ||
|
||
items_in_category = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
items_in_category.append(item) | ||
return items_in_category | ||
|
||
def swap_items(self, other_vendor, self_item, their_item): | ||
''' | ||
Facilitates a swap between two vendors for two given items, and updates | ||
each vendor's inventory list accordingly. | ||
Parameters: | ||
other_vendor (another Vendor instance): vendor to swap with | ||
self_item (string): an item in the Vendor's own inventory | ||
their_item (string): an item in the other Vendor's inventory | ||
Returns: True if the swap was completed, otherwise False | ||
''' | ||
|
||
if self_item in self.inventory and their_item in other_vendor.inventory: | ||
self.remove(self_item) | ||
other_vendor.add(self_item) | ||
self.add(their_item) | ||
other_vendor.remove(their_item) | ||
return True | ||
else: | ||
return False | ||
|
||
def swap_first_item(self, other_vendor): | ||
''' | ||
Facilitates a swap of the first inventory item for two vendors | ||
and updates each vendor's inventory list accordingly. | ||
Parameter: other_vendor (another Vendor instance): vendor to swap with | ||
Returns: True if the swap was completed, otherwise False | ||
''' | ||
|
||
if len(self.inventory) >= 1 and len(other_vendor.inventory) >= 1: | ||
self.swap_items(other_vendor, self.inventory[0], other_vendor.inventory[0]) | ||
return True | ||
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. Yes! You could also take advantage of the fact that .swap_items returns True or False and |
||
else: | ||
return False | ||
|
||
def get_best_by_category(self,category): | ||
''' | ||
For a given item category, searches a vendor's inventory to find and | ||
return the item in that category with the highest rated condition. | ||
Parameter: category (string): a string attribute for an item's type | ||
Returns: The highest rate item in that category, returns none if no | ||
item in that category | ||
''' | ||
|
||
items_in_category = self.get_by_category(category) | ||
if len(items_in_category) > 0: | ||
items_in_category.sort(key=lambda item: item.condition, reverse=True) | ||
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. Very nice! |
||
return items_in_category[0] | ||
return None | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
''' | ||
Facilitates a swap between two vendors for the highest rated item | ||
of a desired category that the vendor specifies | ||
Parameters: | ||
other (another Vendor instance): vendor to swap with | ||
my_priority (string): the desired type of item to swap for | ||
their_priority (string): the other vendor's desired type | ||
of item to swap for | ||
Returns: True if the swap was completed, otherwise False | ||
''' | ||
|
||
best_their_priority = self.get_best_by_category(their_priority) | ||
best_my_priority = other.get_best_by_category(my_priority) | ||
if best_their_priority and best_my_priority: | ||
self.swap_items(other, best_their_priority, best_my_priority) | ||
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. Awesome use of helper functions! |
||
return True | ||
return False |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,12 @@ | |
import pytest | ||
from swap_meet.vendor import Vendor | ||
|
||
@pytest.mark.skip | ||
# Wave 1 / Test 1 | ||
def test_vendor_has_inventory(): | ||
vendor = Vendor() | ||
assert len(vendor.inventory) == 0 | ||
|
||
@pytest.mark.skip | ||
# Wave 1 / Test 2 | ||
def test_vendor_takes_optional_inventory(): | ||
inventory = ["a", "b", "c"] | ||
vendor = Vendor(inventory=inventory) | ||
|
@@ -16,7 +16,7 @@ def test_vendor_takes_optional_inventory(): | |
assert "b" in vendor.inventory | ||
assert "c" in vendor.inventory | ||
|
||
@pytest.mark.skip | ||
# Wave 1 / Test 3 | ||
def test_adding_to_inventory(): | ||
vendor = Vendor() | ||
item = "new item" | ||
|
@@ -27,7 +27,7 @@ def test_adding_to_inventory(): | |
assert item in vendor.inventory | ||
assert result == item | ||
|
||
@pytest.mark.skip | ||
# Wave 1 / Test 4 | ||
def test_removing_from_inventory_returns_item(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
|
@@ -40,7 +40,7 @@ def test_removing_from_inventory_returns_item(): | |
assert item not in vendor.inventory | ||
assert result == item | ||
|
||
@pytest.mark.skip | ||
# Wave 1 / Test 5 | ||
def test_removing_not_found_is_false(): | ||
item = "item to remove" | ||
vendor = Vendor( | ||
|
@@ -49,7 +49,6 @@ def test_removing_not_found_is_false(): | |
|
||
result = vendor.remove(item) | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* | ||
assert item not in vendor.inventory | ||
assert len(vendor.inventory) == 3 | ||
assert result == False | ||
Comment on lines
+52
to
+54
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. 👍🏻 |
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.
Yay docstrings! Great use of them here and throughout your code!