-
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
Panthers_A18 - Lee Reyes and Sika Sarpong #85
base: master
Are you sure you want to change the base?
Changes from all commits
ba9198f
828378e
5501aeb
8128d1a
fd22182
b2f4d24
fed9eb5
e4a428c
f3b121f
48061ad
9fe2528
a6f2e41
44c15af
dc3c66f
b187d3a
609f6ce
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, category="Clothing", condition=0, age=0): | ||
super().__init__(category, condition, 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, category="Decor", condition=0, age=0): | ||
super().__init__(category, condition, age) | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." | ||
Comment on lines
+4
to
+9
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. Same comment about |
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): | ||
def __init__(self, category="Electronics", condition=0, age=0): | ||
super().__init__(category, condition, age) | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." | ||
Comment on lines
+4
to
+9
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. Same comment about |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
class Item: | ||
pass | ||
''' | ||
All three classes and the Item class have an attribute called condition, | ||
which can be optionally provided in the initializer. The default value | ||
should be 0. | ||
''' | ||
|
||
def __init__(self, category="", condition=0, age=0): | ||
self.category = category | ||
self.condition = condition | ||
self.age = age | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
if self.condition == 0: | ||
return "Ew. You don't want that." | ||
elif self.condition == 1: | ||
return "Maybe you need gloves for that." | ||
elif self.condition == 2: | ||
return "Heavily Used" | ||
elif self.condition == 3: | ||
return "Decent" | ||
elif self.condition == 4: | ||
return "Lightly Used" | ||
elif self.condition == 5: | ||
return "Like new!" | ||
Comment on lines
+16
to
+28
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. 🤣 lol Love the condition descriptions. "maybe you need gloves for that" is my fav. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,72 @@ | ||
class Vendor: | ||
pass | ||
def __init__(self, inventory=None) -> None: | ||
self.inventory = inventory if inventory is not None else [] | ||
|
||
def __str__(self, item): | ||
f"{self.item}" | ||
# return f"my_item: {self.my_item}, their_item: {self.their_item}" | ||
|
||
def add(self, item): | ||
self.inventory.append(item) | ||
return item | ||
Comment on lines
+9
to
+11
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 remove(self, item): | ||
if item not in self.inventory: | ||
return False | ||
self.inventory.remove(item) | ||
return item | ||
Comment on lines
+13
to
+17
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 get_by_category(self, category): | ||
category_list = [item for item in self.inventory if item.category == category] | ||
return category_list | ||
Comment on lines
+19
to
+21
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 list comprehension! |
||
|
||
def swap_items(self, vendor, my_item, their_item): | ||
'''If this Vendor's inventory doesn't contain my_item or the friend's inventory doesn't contain their_item, | ||
the method returns False''' | ||
if my_item not in self.inventory or their_item not in vendor.inventory: | ||
return False | ||
self.remove(my_item) | ||
vendor.add(my_item) | ||
vendor.remove(their_item) | ||
self.add(their_item) | ||
return True | ||
Comment on lines
+23
to
+32
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 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 | ||
Comment on lines
+34
to
+38
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 functions! Currently, swapping any items has a time complexity of O(n) due to the
Here's more info on Python multiple assignment: https://www.w3schools.com/python/gloss_python_assign_value_to_multiple_variables.asp |
||
|
||
def get_best_by_category(self, category): | ||
category_list = self.get_by_category(category) | ||
if not category_list: | ||
return None | ||
return max(category_list, key=lambda x: x.condition) | ||
Comment on lines
+40
to
+44
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 |
||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
vendor_wants = other.get_best_by_category(my_priority) | ||
other_wants = self.get_best_by_category(their_priority) | ||
|
||
if not vendor_wants or not other_wants: | ||
return False | ||
|
||
self.swap_items(other, other_wants, vendor_wants) | ||
return True | ||
Comment on lines
+46
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. 👍 Great use of helper functions! This solution is very clean 😄 |
||
|
||
def swap_by_newest(self, other, my_priority,their_priority): | ||
# Our logic is the user would say what category they want, | ||
# and then swap the newest item in that category | ||
my_newest_list = self.get_by_category(my_priority) | ||
other_newest_list = other.get_by_category(their_priority) | ||
|
||
if not my_newest_list or not other_newest_list: | ||
return None | ||
|
||
my_newest_list.sort(key = lambda x:x.newest) | ||
other_newest_list.sort(key = lambda x:x.newest) | ||
|
||
self.swap(other,other_newest_list[0], my_newest_list[0]) | ||
return True | ||
Comment on lines
+56
to
+69
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. 👍 Nicely done! |
||
|
||
|
||
|
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,16 +40,18 @@ 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( | ||
inventory=["a", "b", "c"] | ||
) | ||
|
||
result = vendor.remove(item) | ||
|
||
assert result is False | ||
Comment on lines
44
to
+52
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. 👍 |
||
|
||
raise Exception("Complete this test according to comments below.") | ||
# raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* |
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,10 @@ 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 | ||
assert item_a not in items | ||
assert item_b not in items | ||
assert item_c not in items | ||
Comment on lines
+37
to
+40
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. 👍 |
||
# ********************************************************************* | ||
# ****** 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.
Setting a default value will still allow us to reassign the value. In this case, every
Clothing
instance can change its category to 'Electronics':We can move the default assignment of
category
to the parentsuper()
constructor. This will ensure that everyClothing
instance will be assigned 'Clothing' as its category.