-
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 - Cintia/Ryan #90
base: master
Are you sure you want to change the base?
Changes from all commits
f5b8b7a
2412917
0237117
48a4704
be4ab45
522bfd2
e25bc4f
398db9a
8dff668
c318404
ca334ce
7cc812e
db45b14
7d5b7f1
a00296d
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 | ||
# creates class/category Clothing using class Item | ||
# stringifies Clothing | ||
class Clothing(Item): | ||
def __init__(self, category="Clothing", condition=0): | ||
self.category = category | ||
self.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 swap_meet.item import Item | ||
# creates class/category Decor using class Item | ||
# stringifies Decor | ||
class Decor(Item): | ||
Comment on lines
+1
to
+4
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 __init__(self, category="Decor", condition=0): | ||
self.category = category | ||
self.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 swap_meet.item import Item | ||
# creates class/category Electronics using class Item | ||
# stringifies Electronics | ||
class Electronics(Item): | ||
def __init__(self, category="Electronics", condition=0): | ||
self.category = category | ||
self.condition = condition | ||
Comment on lines
+1
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 __str__(self): | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,26 @@ | ||
class Item: | ||
pass | ||
def __init__(self, category=None, condition=0): | ||
if category is None: | ||
category = "" | ||
self.category = category | ||
Comment on lines
+3
to
+5
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. Good job using this default parameter of None. None is often used as a default argument value in Python because it allows us to call the function without providing a value for an argument that isn't required on each function invocation. Here's the article I referenced: https://bobbyhadz.com/blog/python-using-none-as-default-argument#:~:text=None%20is%20often%20used%20as,for%20list%20and%20dict%20arguments. |
||
self.condition = condition | ||
# stringifies class Item | ||
def __str__(self): | ||
return "Hello World!" | ||
# creates descriptions of conditions | ||
def condition_description(self): | ||
if self.condition == 0: | ||
return "Horrible Condition >:(" | ||
elif self.condition == 1: | ||
return "Heavily Used :(" | ||
elif self.condition == 2: | ||
return "So-So condition :/" | ||
elif self.condition == 3: | ||
return "Decent :|" | ||
elif self.condition == 4: | ||
return "Gently Used :)" | ||
elif self.condition == 5: | ||
return "Like New! >:)" | ||
Comment on lines
+11
to
+23
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 way to implement your description! It uses conditional flow pretty well |
||
|
||
# example: book = Item("book", "literature", 5) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,69 @@ | ||
from swap_meet.item import Item | ||
|
||
class Vendor: | ||
pass | ||
def __init__(self, inventory=None): | ||
self.inventory = inventory if inventory is not None else [] | ||
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. Amazing work on this guard clause ✅ |
||
|
||
# adds item to inventory | ||
def add(self, item): | ||
self.inventory.append(item) | ||
return item | ||
|
||
# removes item from inventory | ||
def remove(self, item): | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
return False | ||
Comment on lines
+8
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. So clean 🙌🏾 |
||
|
||
# returns list of items that match by category | ||
def get_by_category (self, category): | ||
if not category: | ||
return None | ||
matching_items = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
matching_items.append(item) | ||
return matching_items | ||
Comment on lines
+20
to
+27
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 job! |
||
|
||
# swaps item that you want + item that your friend wants from each inventory, if each inventory contains it. | ||
def swap_items(self, friend, my_item, their_item): | ||
if my_item in self.inventory and their_item in friend.inventory: | ||
self.add(their_item) | ||
friend.add(my_item) | ||
self.remove(my_item) | ||
friend.remove(their_item) | ||
return True | ||
return False | ||
Comment on lines
+30
to
+37
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 looks good to me! |
||
|
||
# swaps items, but specifically the first items of each inventory. | ||
def swap_first_item(self, friend): | ||
if self.inventory and friend.inventory: | ||
first_own = self.inventory[0] | ||
first_friend = friend.inventory[0] | ||
self.swap_items(friend, first_own, first_friend) | ||
return True | ||
return False | ||
|
||
# loops through a list of items matching requested category and outputs the item with the highest condition. | ||
def get_best_by_category(self, category): | ||
inventory = self.get_by_category(category) | ||
if not inventory: | ||
return None | ||
highest = 0 | ||
best_item = None | ||
for item in inventory: | ||
if item.condition > highest: | ||
highest = item.condition | ||
best_item = item | ||
return best_item | ||
Comment on lines
+49
to
+59
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 job connecting what you learned from the Problem Solving Exercise 👍🏾 |
||
|
||
# finds best condition item in a category you want and a category your friend wants. | ||
# if either doesn't have item, returns false. otherwise, swaps those two items. | ||
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) | ||
if not my_best or not their_best: | ||
return False | ||
self.swap_items(other, my_best, their_best) | ||
return True |
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,29 +27,28 @@ 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( | ||
inventory=["a", "b", "c", item] | ||
) | ||
vendor = Vendor(inventory=["a", "b", "c", item]) | ||
|
||
result = vendor.remove(item) | ||
|
||
assert len(vendor.inventory) == 3 | ||
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"] | ||
) | ||
vendor = Vendor(inventory=["a", "b", "c"]) | ||
|
||
result = vendor.remove(item) | ||
|
||
raise Exception("Complete this test according to comments below.") | ||
# ********************************************************************* | ||
# ****** Complete Assert Portion of this test ********** | ||
# ********************************************************************* | ||
assert result == False | ||
|
||
assert len(vendor.inventory) == 3 | ||
assert "a" in vendor.inventory | ||
assert "b" in vendor.inventory | ||
assert "c" in vendor.inventory | ||
Comment on lines
+48
to
+53
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. You can check the result more pythonically but checking for the falseyness! |
||
|
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.
Amazing work completing your project yall! This inheritance is sweet and the comment clearly explains what your method's objective is 💯
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.
Excellent work with these default arguments