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

C17 Whales Morgan Adkisson #91

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Clothing:
pass
from swap_meet.item import Item

class Clothing(Item):
"""A child class of Item, representing aspects of an Item specific to Clothing"""
def __init__(self, category="Clothing", condition=0.0, age=None):
self.category = category
self.condition = condition
self.age = age
Comment on lines +4 to +8

Choose a reason for hiding this comment

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

category probably shouldn't be a parameter here since we don't want it to differ for different instances:

Suggested change
"""A child class of Item, representing aspects of an Item specific to Clothing"""
def __init__(self, category="Clothing", condition=0.0, age=None):
self.category = category
self.condition = condition
self.age = age
"""A child class of Item, representing aspects of an Item specific to Clothing"""
def __init__(self, condition=0.0, age=None):
self.category= "Clothing"
self.condition = condition
self.age = age


def __str__(self):
return "The finest clothing you could wear."
13 changes: 11 additions & 2 deletions swap_meet/decor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Decor:
pass
from swap_meet.item import Item

class Decor(Item):
"""A child class of Item, representing aspects of an Item specific to Decor"""
def __init__(self, category="Decor", condition=0.0, age=None):
self.category = category
self.condition = condition
self.age = age

def __str__(self):
return "Something to decorate your space."
13 changes: 11 additions & 2 deletions swap_meet/electronics.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Electronics:
pass
from swap_meet.item import Item

class Electronics(Item):
"""A child class of Item, representing aspects of an Item specific to Electronics"""
def __init__(self, category="Electronics", condition=0.0, age=None):
self.category = category
self.condition = condition
self.age = age

def __str__(self):
return "A gadget full of buttons and secrets."
22 changes: 21 additions & 1 deletion swap_meet/item.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
class Item:
pass

def __init__(self, category="", condition=0.0, age=None):
self.category = category
self.condition = condition
self.age = age

def __str__(self):
return "Hello World!"

def condition_description(self):
condition = int(self.condition)
descriptions = {
0: 'You should probably pass on this one...',
1: 'Poor',
2: 'Meh',
3: 'Good',
4: 'Great',
5: 'Brand spankin new'
}
Comment on lines +13 to +20

Choose a reason for hiding this comment

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

Using a dictionary for this is really clean. 😃

return descriptions[condition]

88 changes: 87 additions & 1 deletion swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,88 @@
from swap_meet.item import Item

class Vendor:
pass

def __init__(self, inventory = None):
if not inventory:
inventory = []
self.inventory = inventory

def add(self, item):
self.inventory.append(item)
return item

def remove(self, item):
if item not in self.inventory:
return False
self.inventory.remove(item)
return item

def get_by_category(self, category_str):
category_items = []
for item in self.inventory:
if item.category == category_str:
category_items.append(item)
return category_items

def swap_items(self, swap_vendor, my_item, their_item):
if my_item in self.inventory and their_item in swap_vendor.inventory:
self.remove(my_item)
swap_vendor.add(my_item)
self.add(their_item)
swap_vendor.remove(their_item)
return True
return False

def swap_first_item(self, other):
if len(self.inventory) >= 1 and len(other.inventory) >= 1:
self_first_item = self.inventory[0]
other_first_item = other.inventory[0]
self.inventory[0] = other_first_item
other.inventory[0] = self_first_item
return True
return False

def get_best_by_category(self, category_str):
category_items = self.get_by_category(category_str)
if len(category_items) > 1:
best_item = category_items[0]
else:
return None

for item in category_items:
if item.condition > best_item.condition:
best_item = item
return best_item

def swap_best_by_category(self, other, my_priority, their_priority):
my_best_swap = self.get_best_by_category(their_priority)
their_best_swap = other.get_best_by_category(my_priority)

if my_best_swap and their_best_swap:
self.swap_items(other, my_best_swap, their_best_swap)
return True
return False

def get_newest_by_category(self, category_str):
"""optional enhancement: helper function to get newest item by category to pass to swap_by_newest"""
category_items = self.get_by_category(category_str)
if len(category_items) > 1:
newest_item = category_items[0]
else:
return None

for item in category_items:
if item.age < newest_item.age:
newest_item = item

return newest_item

def swap_newest_by_category(self, other, my_priority, their_priority):
"""optional enhancement: swaps newest item of certain categories with another Vendor"""
my_newest_swap = self.get_newest_by_category(their_priority)
their_newest_swap = other.get_newest_by_category(my_priority)

if my_newest_swap and their_newest_swap:
self.swap_items(other, my_newest_swap, their_newest_swap)
return True
return False
3 changes: 2 additions & 1 deletion tests/integration_tests/test_wave_01_02_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
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
vendor = Vendor()
print(vendor.inventory)
assert len(vendor.inventory) == 0

# add an item
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
116 changes: 116 additions & 0 deletions tests/unit_tests/test_optional_enhancement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import pytest
from swap_meet.vendor import Vendor
from swap_meet.clothing import Clothing
from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

def test_clothing_has_age_default_None():
clothing = Clothing()
assert clothing.age == None

def test_decor_has_age_default_None():
decor = Decor()
assert decor.age == None

def test_electronics_has_age_default_None():
electronics = Electronics()
assert electronics.age == None

def test_newest_by_category():
item_a = Clothing(age=2)
item_b = Decor(age=1)
item_c = Clothing(age=5)
ryan = Vendor(inventory=[item_a, item_b, item_c])

newest_item = ryan.get_newest_by_category("Clothing")

assert newest_item.age == 2
assert newest_item.category == "Clothing"

def test_newest_by_category_no_matches_is_none():
item_a = Electronics(age=3)
item_b = Decor(age=7)
item_c = Decor(age=5)
tara = Vendor(inventory=[item_a, item_b, item_c])

newest_item = tara.get_newest_by_category("Clothing")

assert newest_item == None

def test_newest_by_category_with_duplicates():
item_a = Clothing(age=2)
item_b = Clothing(age=2)
item_c = Clothing(age=4)
robin = Vendor(inventory=[item_a, item_b, item_c])

newest_item = robin.get_newest_by_category("Clothing")

assert newest_item.age == 2
assert newest_item.category == "Clothing"

def test_swap_newest_by_category():
item_a = Decor(age=9)
item_b = Clothing(age=2)
item_c = Decor(age=3)
thomas = Vendor(inventory=[item_a, item_b, item_c])

item_d = Electronics(age=3)
item_e = Decor(age=3)
item_f = Electronics(age=1)
stevie = Vendor(inventory=[item_d, item_e, item_f])

result = thomas.swap_newest_by_category(
other=stevie,
my_priority="Electronics",
their_priority="Decor"
)

assert result is True
assert len(thomas.inventory) == 3
assert len(stevie.inventory) == 3
assert item_c in stevie.inventory
assert item_f in thomas.inventory

def test_swap_newest_by_category_no_inventory_is_false():
item_a = Clothing(age=9)
item_b = Clothing(age=2)
item_c = Clothing(age=3)
charlotte = Vendor(inventory=[item_a, item_b, item_c])

item_d = Electronics(age=3)
item_e = Decor(age=3)
item_f = Electronics(age=1)
parker = Vendor(inventory=[item_d, item_e, item_f])

result = charlotte.swap_newest_by_category(
other=parker,
my_priority="Decor",
their_priority="Electronics"
)

assert result is False
assert len(charlotte.inventory) == 3
assert len(parker.inventory) == 3
for item in charlotte.inventory:
assert item.category != "Electronics"

def test_swap_newest_by_category_no_other_inventory_is_false():
item_a = Decor(age=3)
item_b = Electronics(age=1)
item_c = Clothing(age=5)
sage = Vendor(inventory=[item_a, item_b, item_c])

audrey = Vendor(inventory=[])

result = sage.swap_newest_by_category(
other=audrey,
my_priority="Decor",
their_priority="Clothing"
)

assert not result
assert len(sage.inventory) == 3
assert len(audrey.inventory) == 0
assert item_a in sage.inventory
assert item_b in sage.inventory
assert item_c in sage.inventory
16 changes: 10 additions & 6 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,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(
Expand All @@ -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(
Expand All @@ -49,7 +49,11 @@ def test_removing_not_found_is_false():

result = vendor.remove(item)

raise Exception("Complete this test according to comments below.")
# raise Exception("Complete this test according to comments below.")

# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************

assert len(vendor.inventory) == 3
assert result == False
13 changes: 9 additions & 4 deletions tests/unit_tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -34,7 +34,12 @@ def test_get_no_matching_items_by_category():

items = vendor.get_by_category("electronics")

raise Exception("Complete this test according to comments below.")
# raise Exception("Complete this test according to comments below.")
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************

assert len(items) == 0
assert item_a not in items
assert item_b not in items
assert item_c not in items
Loading