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

Otters - Tori Shade #101

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a354091
All of wave 01 unit tests are passing successfully.
ToriShade Apr 4, 2022
0f90727
Wave 01 unit tests have been updated and skip mark has been commented…
ToriShade Apr 4, 2022
cb0c414
updated for wave 03 stringify.
ToriShade Apr 6, 2022
04ec7fa
All tests successfully passing through wave 04
ToriShade Apr 6, 2022
f605720
unit tests updated to remove test skip and applicable test assertion …
ToriShade Apr 6, 2022
abab276
tests updated to remove skip
ToriShade Apr 6, 2022
07aed83
updated for wave 05 item condition
ToriShade Apr 6, 2022
c8e7861
updated for wave 05 item condition
ToriShade Apr 6, 2022
f8e44c3
updated for wave 05 item condition
ToriShade Apr 6, 2022
5d9c84f
updated for wave 05 item condition
ToriShade Apr 6, 2022
ac0ac9c
All wave 05 tests successfully passing
ToriShade Apr 6, 2022
8ac5271
All of wave 06 tests successfully passing.
ToriShade Apr 6, 2022
afd4d0c
Updated to complete applicable assert statements and to remove mark s…
ToriShade Apr 6, 2022
3bec9bc
commented out mark skip tests
ToriShade Apr 6, 2022
c0e22db
commented out mark skip tests
ToriShade Apr 6, 2022
f72903f
Updated to inherit applicable Item attributes and methods.
ToriShade Apr 7, 2022
3c02256
Updated to inherit applicable Item attributes and methods.
ToriShade Apr 7, 2022
83d1498
Updated to inherit applicable Item attributes and methods.
ToriShade Apr 7, 2022
cffb1e1
Updated so sub classes inherit applicable Item attributes and methods.
ToriShade Apr 7, 2022
25064c1
commented out pytest integration message
ToriShade Apr 7, 2022
869b81d
commented out pytest integration message
ToriShade Apr 7, 2022
9507b63
added test to get code coverage to 100%
ToriShade Apr 7, 2022
ecd65c8
updates made as part of refactoring
ToriShade Apr 7, 2022
ee8ac00
docstrings added
ToriShade Apr 8, 2022
2aa7efa
docstrings added
ToriShade Apr 8, 2022
9d5f231
docstrings added
ToriShade Apr 8, 2022
71af0e5
docstrings added
ToriShade Apr 8, 2022
ba1814e
refactoring and docstrings added
ToriShade Apr 8, 2022
ef45658
added tests for optional enhancements
ToriShade Apr 8, 2022
0700961
format updates made
ToriShade Apr 8, 2022
dc870b3
format updates made
ToriShade Apr 8, 2022
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
12 changes: 10 additions & 2 deletions swap_meet/clothing.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
class Clothing:
pass
from swap_meet.item import Item

class Clothing(Item):
'''Clothing class is instantiated and inherits from Item class'''

def __init__(self, category = "Clothing", condition = 0, age = 0):

Choose a reason for hiding this comment

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

small note - if all items for this child class should have their category attribute set to "Clothing", do we need to have category as a parameter in the constructor? This makes it possible for users to set the category to something else which could lead to unexpected problems in our application. Think about how you could update your code to make sure the category for this class is always set to "Clothing"

super(). __init__(category, condition, age)

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

class Decor(Item):
'''Decor class is instantiated and inherits from Item class'''

def __init__(self, category = "Decor", condition = 0, age = 0):

Choose a reason for hiding this comment

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

note about category parameter applies here too

super(). __init__(category, condition, age)

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

class Electronics(Item):
'''Electronics class is instantiated and inherits from Item class'''

def __init__(self, category = "Electronics", condition = 0, age = 0):

Choose a reason for hiding this comment

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

note about category parameter applies here too

super(). __init__(category, condition, age)

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

'''Item class is instantiated'''
def __init__(self, category=None, condition = 0, age = 0):
if not category:
category = ""

Choose a reason for hiding this comment

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

Strings are immutable so you can set an empty string as a default value in the parameters :)

self.category = category
self.condition = condition
self.age = age

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

def condition_description(self):
'''Function returns condition description based on quantitative value assigned to condition'''

if self.condition == 0:
return f"terrible"
if self.condition == 1:
return f"not great"
if self.condition == 2:
return f"kinda ok"
if self.condition == 3:
return f"you'll do"
if self.condition == 4:
return f"basic"
if self.condition == 5:
return f"vibe"

Choose a reason for hiding this comment

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

Lol @ "vibe"

small note - make sure to have a blank line at the end of all your Python files. It's convention.

107 changes: 106 additions & 1 deletion swap_meet/vendor.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,107 @@
class Vendor:
pass

def __init__(self, inventory = None):
'''Vendor class is instantiated'''

Choose a reason for hiding this comment

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

Beautiful docstrings 👏


if not inventory:
inventory = []
self.inventory = inventory

def add(self, item):
'''Function used to add items to vendor's inventory'''

self.inventory.append(item)
return item

def remove(self, item):
'''Function used to remove items from vendor's inventory'''

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

def get_by_category(self, category):
'''Function returns items in vendor's inventory if they belong to the category passed within the parameter'''

items_in_category = []

for item in self.inventory:
if category == item.category:
items_in_category.append(item)
return items_in_category

def swap_items(self, other, my_item, their_item):
'''Function allows this vendor and another vendor to swap items from their respective inventories'''

if my_item not in self.inventory or their_item not in other.inventory:
return False
else:
self.remove(my_item)
other.add(my_item)

other.remove(their_item)
self.add(their_item)
return True

def swap_first_item(self, other):
'''Function allows this vendor and another vendor to swap the first item from their respective inventories'''

if not self.inventory or not other.inventory:
return False
else:
return self.swap_items(other, self.inventory[0], other.inventory[0])

Choose a reason for hiding this comment

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

Nice usage of self.swap_items()


def get_best_by_category(self, category):
'''Function identifies the item in the best condition within a certain category of a vendor's inventory'''

current_condition = 0
best_condition = None

for item in self.inventory:
if item.category == category:
if item.condition > current_condition:

Choose a reason for hiding this comment

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

small note - you could combine these conditional statements on one line using the and keyword. So, if item.category == category and item.condition > condition:

current_condition = item.condition
best_condition = item

return best_condition

def swap_best_by_category(self, other, my_priority, their_priority):
'''Function swaps the items in the best condition with that of other vendors if in a certain category'''

my_best_item = self.get_best_by_category(their_priority)
their_best_item = other.get_best_by_category(my_priority)

if not my_best_item or not their_best_item:
return False
else:
self.swap_items(other, my_best_item, their_best_item)
return True

def get_newest_by_category(self, category):
'''Function identifies the newest item within a certain category of a vendor's inventory'''

item_age_flag_max_30 = 30
newest_item = None

for item in self.inventory:
if item.category == category:
if item.age <= item_age_flag_max_30:
item_age_flag_max_30 = item.age
newest_item = item

return newest_item

def swap_newest_by_category(self, category, other):
'''Function swaps the newest item with that of other vendors newest item if in a certain category'''

my_newest_item = self.get_newest_by_category(category)

their_newest_item = other.get_newest_by_category(category)

if not my_newest_item or not their_newest_item:
return False
else:
self.swap_items(other, my_newest_item, their_newest_item)
return True
4 changes: 2 additions & 2 deletions tests/integration_tests/test_wave_01_02_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from swap_meet.vendor import Vendor
from swap_meet.item import Item

@pytest.mark.skip
@pytest.mark.integration_test
#@pytest.mark.skip
#@pytest.mark.integration_test

Choose a reason for hiding this comment

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

In the future, don't worry about commenting out @pytest.mark.integration. This decorator just specifies that these tests are integration tests so they should run after all the unit tests have been executed. :)

def test_integration_wave_01_02_03():
# make a vendor
vendor = Vendor()
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/test_wave_04_05_06.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from swap_meet.decor import Decor
from swap_meet.electronics import Electronics

@pytest.mark.skip
@pytest.mark.integration_test
#@pytest.mark.skip
#@pytest.mark.integration_test
def test_integration_wave_04_05_06():
camila = Vendor()
valentina = Vendor()
Expand Down
23 changes: 14 additions & 9 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,11 @@ def test_removing_from_inventory_returns_item():
assert item not in vendor.inventory
assert result == item

@pytest.mark.skip
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************

#@pytest.mark.skip
def test_removing_not_found_is_false():
item = "item to remove"
vendor = Vendor(
Expand All @@ -49,7 +53,8 @@ def test_removing_not_found_is_false():

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 item not in vendor.inventory


18 changes: 11 additions & 7 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,11 @@ def test_get_items_by_category():
assert item_c in items
assert item_b not in items

@pytest.mark.skip
# *********************************************************************
# ****** Complete Assert Portion of this test **********
# *********************************************************************

#@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 +38,7 @@ 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 len(items) == 0
assert item_a not in items
assert item_b not in items
assert item_c not in items
12 changes: 6 additions & 6 deletions tests/unit_tests/test_wave_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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")
Expand Down Expand Up @@ -38,7 +38,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 +65,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 +92,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 +112,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