-
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
Alexis Miller - Cheetahs #87
base: master
Are you sure you want to change the base?
Changes from all commits
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,8 @@ | ||
class Clothing: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Clothing", condition) | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
class Decor: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Decor", condition) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
class Electronics: | ||
pass | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, condition=0): | ||
super().__init__("Electronics", 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,18 @@ | ||
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): | ||
if self.condition == 0: | ||
return "mint condition" | ||
elif self.condition <= 2: | ||
return "lightly used" | ||
elif self.condition <= 4: | ||
return "well loved" | ||
else: | ||
return "another man's treasure" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,59 @@ | ||
from swap_meet.item import Item | ||
|
||
class Vendor: | ||
pass | ||
def __init__(self, inventory=None): | ||
if inventory is None: | ||
inventory = [] | ||
self.inventory = inventory | ||
Comment on lines
+5
to
+7
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. 💯 |
||
|
||
def add(self, item): | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
else: | ||
return False | ||
|
||
def get_by_category(self, category): | ||
items = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
items.append(item) | ||
Comment on lines
+22
to
+24
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! |
||
return items | ||
|
||
def swap_items(self, friend_vendor, my_item, their_item): | ||
if their_item not in friend_vendor.inventory or my_item not in self.inventory: | ||
return False | ||
self.remove(my_item) | ||
friend_vendor.add(my_item) | ||
friend_vendor.remove(their_item) | ||
self.add(their_item) | ||
Comment on lines
+30
to
+33
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 use of helper methods! |
||
return True | ||
|
||
def swap_first_item(self, friend_vendor): | ||
if self.inventory == [] or friend_vendor.inventory == []: | ||
return False | ||
my_first_item = self.inventory[0] | ||
their_first_item = friend_vendor.inventory[0] | ||
is_swapped = self.swap_items(friend_vendor, my_first_item, their_first_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. 🎉 |
||
return is_swapped | ||
|
||
def get_best_by_category(self, category=""): | ||
items_list = self.get_by_category(category) | ||
top_condition = 0.0 | ||
return_item = None | ||
for item in items_list: | ||
if item.condition > top_condition: | ||
top_condition = item.condition | ||
return_item = item | ||
return return_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 solution! |
||
|
||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
my_best = self.get_best_by_category(their_priority) | ||
their_best = other.get_best_by_category(my_priority) | ||
return self.swap_items(other, my_best, their_best) | ||
Comment on lines
+56
to
+58
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. 😍 |
||
|
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 | ||||||||
#@pytest.mark.skip | ||||||||
def test_vendor_has_inventory(): | ||||||||
vendor = Vendor() | ||||||||
assert len(vendor.inventory) == 0 | ||||||||
|
||||||||
@pytest.mark.skip | ||||||||
#@pytest.mark.skip | ||||||||
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 | ||||||||
#@pytest.mark.skip | ||||||||
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 | ||||||||
#@pytest.mark.skip | ||||||||
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 | ||||||||
#@pytest.mark.skip | ||||||||
def test_removing_not_found_is_false(): | ||||||||
item = "item to remove" | ||||||||
vendor = Vendor( | ||||||||
|
@@ -49,7 +49,9 @@ def test_removing_not_found_is_false(): | |||||||
|
||||||||
result = vendor.remove(item) | ||||||||
|
||||||||
raise Exception("Complete this test according to comments below.") | ||||||||
#added assert | ||||||||
assert result == False | ||||||||
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. I suggest adding a check to verify that the inventory wasn't changed by the remove action:
Suggested change
|
||||||||
#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.
👍