Skip to content
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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
11 changes: 9 additions & 2 deletions swap_meet/clothing.py
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):
Comment on lines +1 to +4

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 💯

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

def __init__(self, category="Clothing", condition=0):
self.category = category
self.condition = condition
def __str__(self):
return "The finest clothing you could wear."
11 changes: 9 additions & 2 deletions swap_meet/decor.py
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

Choose a reason for hiding this comment

The 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."
11 changes: 9 additions & 2 deletions swap_meet/electronics.py
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def __str__(self):
return "A gadget full of buttons and secrets."
26 changes: 25 additions & 1 deletion swap_meet/item.py
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

Choose a reason for hiding this comment

The 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.
You could refactor this to a shorthand (one-liner): self.category = category if category is not None else ""

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

Choose a reason for hiding this comment

The 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)

69 changes: 68 additions & 1 deletion swap_meet/vendor.py
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 []

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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
2 changes: 1 addition & 1 deletion tests/integration_tests/test_wave_01_02_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# @pytest.mark.skip
@pytest.mark.integration_test
def test_integration_wave_01_02_03():
# make a vendor
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_wave_04_05_06.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

@pytest.mark.skip
# @pytest.mark.skip
@pytest.mark.integration_test
def test_integration_wave_04_05_06():
camila = Vendor()
Expand Down
29 changes: 14 additions & 15 deletions tests/unit_tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check the result more pythonically but checking for the falseyness!


15 changes: 5 additions & 10 deletions tests/unit_tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
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")
item_c = Item(category="clothing")
vendor = Vendor(
inventory=[item_a, item_b, item_c]
)
vendor = Vendor(inventory=[item_a, item_b, item_c])

items = vendor.get_by_category("clothing")

Expand All @@ -23,7 +21,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")
Expand All @@ -34,7 +32,4 @@ def test_get_no_matching_items_by_category():

items = vendor.get_by_category("electronics")

raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************
assert items == []
20 changes: 8 additions & 12 deletions tests/unit_tests/test_wave_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# @pytest.mark.skip
def test_item_overrides_to_string():
item = Item()

stringified_item = str(item)

assert stringified_item == "Hello World!"

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_returns_true():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
item_c = Item(category="clothing")
fatimah = Vendor(
inventory=[item_a, item_b, item_c]
)
fatimah = Vendor(inventory=[item_a, item_b, item_c])

item_d = Item(category="electronics")
item_e = Item(category="decor")
jolie = Vendor(
inventory=[item_d, item_e]
)
jolie = Vendor(inventory=[item_d, item_e])

result = fatimah.swap_items(jolie, item_b, item_d)

Expand All @@ -38,7 +34,7 @@ def test_swap_items_returns_true():
assert item_b in jolie.inventory
assert result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_when_my_item_is_missing_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand All @@ -65,7 +61,7 @@ def test_swap_items_when_my_item_is_missing_returns_false():
assert item_e in jolie.inventory
assert not result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_when_their_item_is_missing_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand All @@ -92,7 +88,7 @@ def test_swap_items_when_their_item_is_missing_returns_false():
assert item_e in jolie.inventory
assert not result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_from_my_empty_returns_false():
fatimah = Vendor(
inventory=[]
Expand All @@ -112,7 +108,7 @@ def test_swap_items_from_my_empty_returns_false():
assert len(jolie.inventory) == 2
assert not result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_items_from_their_empty_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/test_wave_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_first_item_returns_true():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down Expand Up @@ -30,7 +30,7 @@ def test_swap_first_item_returns_true():
assert item_a in jolie.inventory
assert result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_first_item_from_my_empty_returns_false():
fatimah = Vendor(
inventory=[]
Expand All @@ -48,7 +48,7 @@ def test_swap_first_item_from_my_empty_returns_false():
assert len(jolie.inventory) == 2
assert not result

@pytest.mark.skip
# @pytest.mark.skip
def test_swap_first_item_from_their_empty_returns_false():
item_a = Item(category="clothing")
item_b = Item(category="clothing")
Expand Down
Loading